DT
Join ServerDrizzle Team
help
I think I don't really understand migrations local sqlite.
It's a local sqlite db (
The problem is how do I push these migrations to my
I was planning to later use Turso & switch to it but even in the case of turso, I think I would have to manually write each migration in the db shell. Drizzle Kit does not have a push command for sqlite. I'm using
DB_URL=file:dev.db
) in a nextjs & trpc setup. I'm trying drizzle for the first time & I did follow the steps mentioned https://github.com/drizzle-team/drizzle-orm/blob/main/drizzle-orm/src/sqlite-core/README.md#-quick-start. I ran npx drizzle-kit generate:sqlite
& it succesfully generated a migration. Good Job Drizzle!The problem is how do I push these migrations to my
dev.db
file? Do I need to push them manually? Am I missing something?I was planning to later use Turso & switch to it but even in the case of turso, I think I would have to manually write each migration in the db shell. Drizzle Kit does not have a push command for sqlite. I'm using
drizzle-kit: v0.17.6 drizzle-orm: v0.25.4
. Any help is appreciated as I'm tired reading docs & searching for similar issues here.Currently, the migrations can only be run from the code. The documentation is a bit confusing right now, but you can read about it here: https://github.com/drizzle-team/drizzle-orm/blob/main/drizzle-orm/src/sqlite-core/README.md#-migrations
Oh, Okay. I guess until this is taken care of by
drizzle-kit push:...
command (something similar to what prisma does). It would be impossible to make this work with serverless frameworks (like nextjs) without manually pushing your migrations to db each time you make a change ie. generate new migrations. For now it's a deal breaker & I think I would have to fallback to using prisma but I really wish it's solved soon as would instantly take it over prisma any day. Thank you for the help though Dan!It's not hard to just write a small script to execute the code... takes about 2 minutes.
yeah, you can just write a
It's the same as using wrangler with d1
script.ts
that is going to run migration from examples above. It would be mostly the same as using db push. You will just get 1 more table in database It's the same as using wrangler with d1
@isitayush but good news are
I'm working this month on having db push/db pull available for SQLite, so your experience with Turso + Drizzle will be even better
If db push is important and the only thing to go for you - you can follow #kit-releases to get updates about db push/db pull for SQLite available. It a priority for me right now
I'm working this month on having db push/db pull available for SQLite, so your experience with Turso + Drizzle will be even better
If db push is important and the only thing to go for you - you can follow #kit-releases to get updates about db push/db pull for SQLite available. It a priority for me right now
It totally slipped from my head that I could include a script such as
ensure_migrations.ts
with tsc
that runs before dev
or start
alongisde my next app. A native solution in drizzle-kit
would still be awesome but this workaround seems to work too. Welp! Thank you Dan & Andrew. I hope you will bump up 'covers ~95% of the common cases' line to '99%' when db:push
ships later this month. Goodluck!Yeah, drizzle-kit will have db push as well as running migrations files from cli command
How do you run the
I even wrote a [stack overflow question](https://stackoverflow.com/questions/76183638/typescript-script-err-module-not-found-running-a-script-with-ts-node-that-impo) about this exact usecase
script.ts
? I know its a weird question but I have no nice way of running .ts
scripts because of esm
, importing other files, and so on. I even wrote a [stack overflow question](https://stackoverflow.com/questions/76183638/typescript-script-err-module-not-found-running-a-script-with-ts-node-that-impo) about this exact usecase
Hey @bloberenober, Just a small question. How do I set a 'gen_random_uuid()' function as a default value on a custom type? I have the following:
const serial_uuid = customType<
{
data: string;
driverData: string;
notNull: true;
default: true;
}
>({
dataType(config) {
return 'UUID';
},
});
& it generates a following migration, "id" UUID PRIMARY KEY NOT NULL,
.I'm looking for it to be something like this.
"id" UUID PRIMARY KEY NOT NULL DEFAULT gen_random_uuid()
Okay, Figured It out! It's
.default(sql``)
. : )