[GH-ISSUE #2194] 0.28->0.29 db migration failure #1342

Closed
opened 2026-03-02 11:56:39 +03:00 by kerem · 6 comments
Owner

Originally created by @shaman007 on GitHub (Nov 30, 2025).
Original GitHub issue: https://github.com/karakeep-app/karakeep/issues/2194

Describe the Bug

0.28->0.29 db migration failure

Steps to Reproduce

1 - have Karareep 0.28 up and runing (pod, k8s)
2 - change image version to 0.29
3 -

s6-rc: info: service s6rc-oneshot-runner: starting
s6-rc: info: service s6rc-oneshot-runner successfully started
s6-rc: info: service fix-attrs: starting
s6-rc: info: service init-db-migration: starting
Running db migration script
s6-rc: info: service fix-attrs successfully started
s6-rc: info: service legacy-cont-init: starting
s6-rc: info: service legacy-cont-init successfully started
file:///db_migrations/index.js:7864
      throw new DrizzleError({ cause: err, message: `Failed to run the query '${staticQuery.sql}'` });
            ^

DrizzleError: Failed to run the query 'CREATE TABLE `listCollaborators` (
	`id` text PRIMARY KEY NOT NULL,
	`listId` text NOT NULL,
	`userId` text NOT NULL,
	`role` text NOT NULL,
	`createdAt` integer NOT NULL,
	`addedBy` text,
	FOREIGN KEY (`listId`) REFERENCES `bookmarkLists`(`id`) ON UPDATE no action ON DELETE cascade,
	FOREIGN KEY (`userId`) REFERENCES `user`(`id`) ON UPDATE no action ON DELETE cascade,
	FOREIGN KEY (`addedBy`) REFERENCES `user`(`id`) ON UPDATE no action ON DELETE set null
);
'
    at BetterSQLiteSession.run (file:///db_migrations/index.js:7864:13)
    at SQLiteSyncDialect.migrate (file:///db_migrations/index.js:5722:21)
    ... 4 lines matching cause stack trace ...
    at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:117:5) {
  cause: SqliteError: table `listCollaborators` already exists
      at PreparedQuery.run (file:///db_migrations/index.js:7979:22)
      at BetterSQLiteSession.run (file:///db_migrations/index.js:7862:74)
      at SQLiteSyncDialect.migrate (file:///db_migrations/index.js:5722:21)
      at migrator_migrate (file:///db_migrations/index.js:2207:14)
      at file:///db_migrations/index.js:14194:1
      at ModuleJob.run (node:internal/modules/esm/module_job:343:25)
      at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:665:26)
      at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:117:5) {
    code: 'SQLITE_ERROR'
  }
}

Node.js v22.21.1

Expected Behaviour

New version up and running

Screenshots or Additional Context

No response

Device Details

No response

Exact Karakeep Version

0.29.0

Have you checked the troubleshooting guide?

  • I have checked the troubleshooting guide and I haven't found a solution to my problem
Originally created by @shaman007 on GitHub (Nov 30, 2025). Original GitHub issue: https://github.com/karakeep-app/karakeep/issues/2194 ### Describe the Bug 0.28->0.29 db migration failure ### Steps to Reproduce 1 - have Karareep 0.28 up and runing (pod, k8s) 2 - change image version to 0.29 3 - ``` s6-rc: info: service s6rc-oneshot-runner: starting s6-rc: info: service s6rc-oneshot-runner successfully started s6-rc: info: service fix-attrs: starting s6-rc: info: service init-db-migration: starting Running db migration script s6-rc: info: service fix-attrs successfully started s6-rc: info: service legacy-cont-init: starting s6-rc: info: service legacy-cont-init successfully started file:///db_migrations/index.js:7864 throw new DrizzleError({ cause: err, message: `Failed to run the query '${staticQuery.sql}'` }); ^ DrizzleError: Failed to run the query 'CREATE TABLE `listCollaborators` ( `id` text PRIMARY KEY NOT NULL, `listId` text NOT NULL, `userId` text NOT NULL, `role` text NOT NULL, `createdAt` integer NOT NULL, `addedBy` text, FOREIGN KEY (`listId`) REFERENCES `bookmarkLists`(`id`) ON UPDATE no action ON DELETE cascade, FOREIGN KEY (`userId`) REFERENCES `user`(`id`) ON UPDATE no action ON DELETE cascade, FOREIGN KEY (`addedBy`) REFERENCES `user`(`id`) ON UPDATE no action ON DELETE set null ); ' at BetterSQLiteSession.run (file:///db_migrations/index.js:7864:13) at SQLiteSyncDialect.migrate (file:///db_migrations/index.js:5722:21) ... 4 lines matching cause stack trace ... at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:117:5) { cause: SqliteError: table `listCollaborators` already exists at PreparedQuery.run (file:///db_migrations/index.js:7979:22) at BetterSQLiteSession.run (file:///db_migrations/index.js:7862:74) at SQLiteSyncDialect.migrate (file:///db_migrations/index.js:5722:21) at migrator_migrate (file:///db_migrations/index.js:2207:14) at file:///db_migrations/index.js:14194:1 at ModuleJob.run (node:internal/modules/esm/module_job:343:25) at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:665:26) at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:117:5) { code: 'SQLITE_ERROR' } } Node.js v22.21.1 ``` ### Expected Behaviour New version up and running ### Screenshots or Additional Context _No response_ ### Device Details _No response_ ### Exact Karakeep Version 0.29.0 ### Have you checked the troubleshooting guide? - [x] I have checked the troubleshooting guide and I haven't found a solution to my problem
kerem 2026-03-02 11:56:39 +03:00
Author
Owner

@MohamedBassem commented on GitHub (Nov 30, 2025):

hmmm, that's surprising. Do you have multiple replicas for the web container running by any chance?

<!-- gh-comment-id:3592457061 --> @MohamedBassem commented on GitHub (Nov 30, 2025): hmmm, that's surprising. Do you have multiple replicas for the web container running by any chance?
Author
Owner

@shaman007 commented on GitHub (Nov 30, 2025):

I accidentally started 2, but then scaled it correctly.

But thinking more, it may come from the 'nightly' I'd tried some time ago for a period of time. Is it a way I manually drop the listCollaborators, then will switch to 0.29? I don't see sqlite3 binary in the image.

<!-- gh-comment-id:3592465310 --> @shaman007 commented on GitHub (Nov 30, 2025): I accidentally started 2, but then scaled it correctly. But thinking more, it may come from the 'nightly' I'd tried some time ago for a period of time. Is it a way I manually drop the listCollaborators, then will switch to 0.29? I don't see sqlite3 binary in the image.
Author
Owner

@MohamedBassem commented on GitHub (Nov 30, 2025):

technically, going to nightly and then back to a 'newer" release is fine. Somehow you ended up in a state where the migrations are applied but are not recorded and on startup we're trying to re-apply them. You'll have to do some surgery to get it back to some consistent state (luckily there are only three migrations in this release beyond the one that you're stuck on). The image doesn't come up with a sqlite3 CLI but you can install it.

<!-- gh-comment-id:3592470114 --> @MohamedBassem commented on GitHub (Nov 30, 2025): technically, going to nightly and then back to a 'newer" release is fine. Somehow you ended up in a state where the migrations are applied but are not recorded and on startup we're trying to re-apply them. You'll have to do some surgery to get it back to some consistent state (luckily there are only three migrations in this release beyond the one that you're stuck on). The image doesn't come up with a sqlite3 CLI but you can install it.
Author
Owner

@shaman007 commented on GitHub (Nov 30, 2025):

Fixed it with

DROP TABLE IF EXISTS listCollaborators;
CREATE TABLE IF NOT EXISTS listCollaborators (
    id TEXT PRIMARY KEY NOT NULL,
    listId TEXT NOT NULL,
    userId TEXT NOT NULL,
    role TEXT NOT NULL,
    createdAt INTEGER NOT NULL,
    addedBy TEXT,
    FOREIGN KEY (listId) REFERENCES bookmarkLists(id) ON DELETE CASCADE,
    FOREIGN KEY (userId) REFERENCES user(id) ON DELETE CASCADE,
    FOREIGN KEY (addedBy) REFERENCES user(id) ON DELETE SET NULL
);

on /data/db.db.

Bthw, you can have sqlite3 console with python /usr/lib/python3.12/sqlite3/main.py /data/db.db

Please consider some sanity checks in future migration.

<!-- gh-comment-id:3592475684 --> @shaman007 commented on GitHub (Nov 30, 2025): Fixed it with ``` DROP TABLE IF EXISTS listCollaborators; CREATE TABLE IF NOT EXISTS listCollaborators ( id TEXT PRIMARY KEY NOT NULL, listId TEXT NOT NULL, userId TEXT NOT NULL, role TEXT NOT NULL, createdAt INTEGER NOT NULL, addedBy TEXT, FOREIGN KEY (listId) REFERENCES bookmarkLists(id) ON DELETE CASCADE, FOREIGN KEY (userId) REFERENCES user(id) ON DELETE CASCADE, FOREIGN KEY (addedBy) REFERENCES user(id) ON DELETE SET NULL ); ``` on /data/db.db. Bthw, you can have sqlite3 console with python /usr/lib/python3.12/sqlite3/__main__.py /data/db.db Please consider some sanity checks in future migration.
Author
Owner

@MohamedBassem commented on GitHub (Nov 30, 2025):

@shaman007 I'm not sure I understand how you recreating the table fixed the issue? The migration was complaining that the table already exists?

<!-- gh-comment-id:3592477834 --> @MohamedBassem commented on GitHub (Nov 30, 2025): @shaman007 I'm not sure I understand how you recreating the table fixed the issue? The migration was complaining that the table already exists?
Author
Owner

@shaman007 commented on GitHub (Nov 30, 2025):

Sorry, I missed few steps.

1 - Migration was complaining that the table exists and failing, app not working.
2 - I moved back to .28, manually dropped the table
3 - Moved to .29 back; the app is running, but with internal errors that this table does not exist.

  [cause]: SqliteError: no such table: listCollaborators

4 - made the table back
5 - it works again

<!-- gh-comment-id:3592481160 --> @shaman007 commented on GitHub (Nov 30, 2025): Sorry, I missed few steps. 1 - Migration was complaining that the table exists and failing, app not working. 2 - I moved back to .28, manually dropped the table 3 - Moved to .29 back; the app is running, but with internal errors that this table does not exist. ``` [cause]: SqliteError: no such table: listCollaborators ``` 4 - made the table back 5 - it works again
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/karakeep#1342
No description provided.