Skip to content

[BUG]: [durable-sqlite] DrizzleError: Rollback when working with @cloudflare/vite-plugin #4558

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
1 task done
rakeshpai opened this issue May 23, 2025 · 0 comments
Open
1 task done
Labels
bug Something isn't working

Comments

@rakeshpai
Copy link

Report hasn't been filed before.

  • I have verified that the bug I'm about to report hasn't been filed before.

What version of drizzle-orm are you using?

0.43.1

What version of drizzle-kit are you using?

0.31.1

Other packages

No response

Describe the Bug

I'm trying to get drizzle to work with the storage in Cloudflare Durable Objects, while using the @cloudflare/vite-plugin as is recommended by Cloudflare.

With some finagling, I was able to get past most errors, but am now stuck with an error that looks as follows:

workerd/io/worker.c++:2103: info: uncaught exception; source = Uncaught (in promise); stack = DrizzleError: Rollback
    at SQLiteDOTransaction.rollback (<snip project dir>/node_modules/.pnpm/drizzle-orm@0.43.1_@cloudflare+workers-types@4.20250522.0/node_modules/drizzle-orm/sqlite-core/session.js:113:11)
    at <snip project dir>/node_modules/.pnpm/drizzle-orm@0.43.1_@cloudflare+workers-types@4.20250522.0/node_modules/drizzle-orm/durable-sqlite/migrator.js:54:10
    at <snip project dir>/node_modules/.pnpm/drizzle-orm@0.43.1_@cloudflare+workers-types@4.20250522.0/node_modules/drizzle-orm/durable-sqlite/session.js:33:7
    at SQLiteDOSession.transaction (<snip project dir>/node_modules/.pnpm/drizzle-orm@0.43.1_@cloudflare+workers-types@4.20250522.0/node_modules/drizzle-orm/durable-sqlite/session.js:32:17)
    at DrizzleSqliteDODatabase.transaction (<snip project dir>/node_modules/.pnpm/drizzle-orm@0.43.1_@cloudflare+workers-types@4.20250522.0/node_modules/drizzle-orm/sqlite-core/db.js:298:25)
    at migrate (<snip project dir>/node_modules/.pnpm/drizzle-orm@0.43.1_@cloudflare+workers-types@4.20250522.0/node_modules/drizzle-orm/durable-sqlite/migrator.js:27:6)
    at /<snip project dir>/worker/app/website/index.ts:18:13
workerd/jsg/exception.c++:140: info: Annotating with brokenness; internalMessage = jsg.Error: DrizzleError: Rollback; brokennessReason = broken.inputGateBroken
workerd/io/io-context.c++:368: info: uncaught exception; exception = workerd/jsg/_virtual_includes/iterator/workerd/jsg/value.h:1479: failed: broken.inputGateBroken; jsg.Error: DrizzleError: Rollback
stack: 100d8dbb0 100d8fba7 100d8f66f 1029a7423

That last stackframe points to my code, where I'm calling migrate:

// ...
export class Website extends DurableObject {
  db: ReturnType<typeof drizzle>;

  constructor(ctx: DurableObjectState, env: Cloudflare.Env) {
    super(ctx, env);
    this.db = drizzle(ctx.storage);
    void ctx.blockConcurrencyWhile(async () => {
      await migrate( // <-- The last stack frame points here
        this.db,
        migrations as unknown as Parameters<typeof migrate>[1]
      );
    });
  }

I used a tip from #3865 and removed the try/catch in the migrate function in my node_modules to see the actual cause of the error, and got the following:

workerd/io/worker.c++:2103: info: uncaught exception; source = Uncaught (in promise); stack = DrizzleError: Failed to run the query '
				CREATE TABLE IF NOT EXISTS "__drizzle_migrations" (
					id SERIAL PRIMARY KEY,
					hash text NOT NULL,
					created_at numeric
				)
			'
    at SQLiteDOSession.run (<snip project dir>/node_modules/.pnpm/drizzle-orm@0.43.1_@cloudflare+workers-types@4.20250522.0/node_modules/drizzle-orm/sqlite-core/session.js:72:13)
    at DrizzleSqliteDODatabase.run (<snip project dir>/node_modules/.pnpm/drizzle-orm@0.43.1_@cloudflare+workers-types@4.20250522.0/node_modules/drizzle-orm/sqlite-core/db.js:256:25)
    at <snip project dir>/node_modules/.pnpm/drizzle-orm@0.43.1_@cloudflare+workers-types@4.20250522.0/node_modules/drizzle-orm/durable-sqlite/migrator.js:37:8
    at <snip project dir>/node_modules/.pnpm/drizzle-orm@0.43.1_@cloudflare+workers-types@4.20250522.0/node_modules/drizzle-orm/durable-sqlite/session.js:33:7
    at SQLiteDOSession.transaction (<snip project dir>/node_modules/.pnpm/drizzle-orm@0.43.1_@cloudflare+workers-types@4.20250522.0/node_modules/drizzle-orm/durable-sqlite/session.js:32:17)
    at DrizzleSqliteDODatabase.transaction (<snip project dir>/node_modules/.pnpm/drizzle-orm@0.43.1_@cloudflare+workers-types@4.20250522.0/node_modules/drizzle-orm/sqlite-core/db.js:298:25)
    at migrate (<snip project dir>/node_modules/.pnpm/drizzle-orm@0.43.1_@cloudflare+workers-types@4.20250522.0/node_modules/drizzle-orm/durable-sqlite/migrator.js:27:6)
    at /<snip project dir>/worker/app/website/index.ts:18:13
workerd/jsg/exception.c++:140: info: Annotating with brokenness; internalMessage = jsg.Error: DrizzleError: Failed to run the query '
				CREATE TABLE IF NOT EXISTS "__drizzle_migrations" (
					id SERIAL PRIMARY KEY,
					hash text NOT NULL,
					created_at numeric
				)
			'; brokennessReason = broken.inputGateBroken
workerd/io/io-context.c++:368: info: uncaught exception; exception = workerd/jsg/_virtual_includes/iterator/workerd/jsg/value.h:1479: failed: broken.inputGateBroken; jsg.Error: DrizzleError: Failed to run the query '
				CREATE TABLE IF NOT EXISTS "__drizzle_migrations" (
					id SERIAL PRIMARY KEY,
					hash text NOT NULL,
					created_at numeric
				)
			'
stack: 1031f1bb0 1031f3ba7 1031f366f 104e0b423

I'm now at a loss about how to proceed. I'm passing in ctx.storage to drizzle(...) as shown above, which is what the docs say, so it should have a valid DB to work against. I'm not sure why it would fail to run the query.

Worth noting: I've modified the migration.js file to import ... from '....sql?raw'; ie, I've added the ?raw to make it get imported as a string, as described here. Without that I get a parsing error thrown by Rollup.

Happy to help debug the issue in any way. Thanks!

@rakeshpai rakeshpai added the bug Something isn't working label May 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant