drizzle-team / drizzle-team/drizzle-orm
[BUG]: [durable-sqlite] DrizzleError: Rollback when working with @cloudflare/vite-plugin
- Dominant language
- TypeScript
- Stars
- 35.8k
- Forks
- 1.6k
- Avg merge
- 2d 7h
- Merged PRs (30d)
- 4
Description
### Report hasn't been filed before.
- [x] 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](https://developers.cloudflare.com/workers/vite-plugin/) as is recommended by Cloudflare.
With [some finagling](https://github.com/drizzle-team/drizzle-orm/issues/4543#issuecomment-2904547438), 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 (/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 /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 /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 (/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 (/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 (/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 //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`:
```ts
// ...
export class Website extends DurableObject {
db: ReturnType;
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[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 (/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 (/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 /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 /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 (/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 (/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 (/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 //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](https://orm.drizzle.team/docs/get-started/do-new#step-8---migrate-and-query-the-database), 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](https://github.com/drizzle-team/drizzle-orm/issues/4543#issuecomment-2904547438). Without that I get a parsing error thrown by Rollup.
Happy to help debug the issue in any way. Thanks!
Contributor guide
Assessment
This issue has not been assessed yet.