Messed up my migrations - Need help

Hello, I am new to Drizzle (in general new to SQL world). Using drizzle with turso db. I had few tables and recently added one new table (say T10) and updated existing table (say T9). For some reason, I have deleted the migrations folder and now I am reading that we are not supposed to do that. When I run
drizzle-kit push:sqlite --config=./src/db/drizzle.config.ts
drizzle-kit push:sqlite --config=./src/db/drizzle.config.ts
It is trying to create all the existing tables and giving me below error:
SQL input error: table `T1 already exists (at offset 13)
SQL input error: table `T1 already exists (at offset 13)
How to: - migrate the only changed schema to turso db (that is: create table T10 and alter table T9) - Do I need to re-populate the migrations folder upto date as per db ? if yes how? Help is much appreciated! Thank you #help
3 Replies
Mykhailo
Mykhailo10mo ago
Hello, @rsrahul! drizzle-kit generate and drizzle-kit push are different approaches for migration process. You can find more info in this chat https://discord.com/channels/1043890932593987624/1220264364666519572 Feel free to ask any questions about it
rsrahul
rsrahulOP10mo ago
@Mykhailo sorry but this does not help, I have tried both. But, meanwhile I had deleted the migrations folder. Now drizzle is trying to create tables which already exists and it is failing.
Mykhailo
Mykhailo10mo ago
try to use drizzle-kit introspect command. It should generate migration files with snapshots. And then you can make changes, generate migrations and apply them using migrate() function https://orm.drizzle.team/kit-docs/commands#introspect--pull
Drizzle ORM - List of commands
Drizzle ORM is a lightweight and performant TypeScript ORM with developer experience in mind.

Did you find this page helpful?