drop tables

Is there a way to do a migration to drop tables? Other ORMs like Sequelize and Prisma have a concept of up & down migrations, but Drizzle doesn't. Is there a Drizzle way to do a "down" migration?
M
mr_pablo356d ago
So looks like drizzle kit does indeed create migrations to drop tables when you remove them from the schema file. but i'd still like to know if you can do incremental up/down migrations?
AS
Andrii Sherman356d ago
we don't have support for down migrations so far any down migration is a new migration with dropping something
M
mr_pablo356d ago
no incremental migrations? like doing 1 or 2 in a step?
P
Piotr332d ago
are there are plans to support down migration? I'd say it is a must for everyday dev cycle. thanks
AS
Andrii Sherman332d ago
Why do you need it when developing new feature? We will have down migrations, but thinking about a situation of a rollback while production deploy Not sure about a use case for development
P
Piotr332d ago
bug in migration - rollback, fix migration, up again; without the possibility to rollback it's manual labour
AS
Andrii Sherman332d ago
If you are using Postgres and there is a bug in migration - it will be rollbacked automatically because all migration scripts are covered in transactions So no need to down migration If you are using databases without DDL transaction support, then this flow will still not be useful. For example, the up migration will break on the 3rd statement out of 5. How would you write a down script so that it can be executed successfully? Alternatively, what if there is a bug in both the down and up migrations?
P
Piotr332d ago
ok I meant a different case - prototyping, made wrong assumptions about tables, I would like to correct and push only the final version - like a squashed commit - I would not like to push 7 migrations showing my messy development process.
AS
Andrii Sherman332d ago
Okay, I see. In this case, it may seem like a more appropriate approach: 1. You write an up+down migration. 2. If you don't like something, you run the down migration. 3. Modify the up and down migrations. 4. Repeat all steps until you are satisfied with your migration. The problem here is that you need to manage two scripts just for the development flow. For such cases, we have a command called push. We support it in MySQL and SQLite, and soon we will have support for Postgres as well. The great thing about it is that it's really useful for prototyping your schema. You can apply any changes to your local database right away without needing to rewrite the up and down migration scripts. Once you finish prototyping, you can generate the up script just once. In this case, you don't need separate up and down scripts. As I mentioned before, I still see the down script as great only for rollbacks during production deployments. We have spent a lot of time using it in various production projects and found that we hardly ever used the down scripts, except for a few deployments where we wanted to ensure smoothness. But those were only 1% of all the deployments we had. Here's another good workflow that has worked well for us before having push command Each time you work on a new feature: 1. Get the development database to your local db, with or without data (your choice). 2. Generate as many migration files as you need until you are ready with your feature. 3. Remove all those migrations using 'drizzle-kit drop' from the project files. 4. Generate a single migration. 5. Dump the development database one more time. 6. Run the final migration and test your feature. After that, you are ready to deploy. However, all of these steps can be omitted with drizzle-kit push For references you can check 1. https://orm.drizzle.team/kit-docs/overview#prototyping-with-db-push 2. https://orm.drizzle.team/kit-docs/commands#prototype--push 3. https://orm.drizzle.team/kit-docs/config-reference And an article example for SQLite: https://driz.li/sqlite-push
P
Piotr331d ago
ok thanks for the explanation @Andrew Sherman @Andrew Sherman what is the timeline to support push for postgresql?
AS
Andrii Sherman330d ago
I think I will be ready with v1 this week
MU
Marek Urbanowicz243d ago
do you have current status of this? Sorry for pinging but we are going full speed on Drizzle and "down" on migrations, exactly for production rollback is something we are also exploring with drizzle
A
Amur243d ago
i'd be curious about this too
AS
Andrii Sherman241d ago
I can't say when down migrations will be in drizzle. I'll try to go through backlog and make it in a higher priority
B
blago_stas231d ago
And what about tests? In the case when I want to roll back all migrations before each test and migrate again
Want results from more Discord servers?
Add your server
More Posts
db.query error with relationI have created a schema.ts, with two tables, with a one-to-one relationship. I have also create the How to transform to camelCase with json_agg()?As topic. I can't find any example on how to go about this. The closest I can find is https://orm.drHow to use select?I have a SQL query ``` SELECT row_to_json(departments.*) as department, row_to_jsonCount in relational queriesHow do I count in relational queries? For example if i'm querying db.query.posts.findMany() and wantCreate a type of VARCHAR[]I want to create a type for my column of `VARCHAR[]` but when I used Drizzle-Kit to generate it, I gSelect with relationIs there a way to get relations when using `db.select().from(table)`I can't get the `db.query.table.Any plan to support ClickHouse db?Any plan to support ClickHouse db? https://clickhouse.com/`where` inside relational queries `with` does not workHi there! I'm new to drizzle and tried out the relational queries. I want to do a nested `where` rIssue with 'insert on conflict do update where'I am using db.insert(lastHeaterMetricsTable) .values(heaterEntityWithMaxTime) Duplicate relations when using `with`I'm running into a problem where some duplicate values are being returned through a relation with `wUsing BIN_TO_UUID / UUID_TO_BINI’m trying to understand the best way to use `BIN_TO_UUID` and `UUID_TO_BIN` (MySQL). The below is drizzle-kit drop config file does not existI have a `/foo/drizzle.config.ts` file as suggested in the docs (https://orm.drizzle.team/kit-docs/Related object is not typed correctlyI have the following schema ``` export const menus = pgTable('menus', { id: uuid('id').primaryKey(Custom vector type with pgvectorI'm trying to use the `pgvector` extension with a custom type but am running into an issue with the Missing 'with' clause additional operators (where, limit, offset, etc)Have been digging into the docs and the latest update. ❣️ In the docs (https://orm.drizzle.team/ddrizzle-zod type errors with latest versionsI updated all drizzle deps to latest and having type errors when using drizzle-zodI am confused on how the new relational queries worksIn the docs I see the following ``` import { pgTable, serial, text, integer, boolean } from 'drizzleis not assignable to type 'DrizzleD1Database'Hello This last release was amazing. Making joins simple was the missing piece for me. However, IDrizzle kit generate gives error after upgradeI have updated drizzle-orm to 0.26.0 and drizzle-kit to 018.0. I have defined relations according toIntrospection error with pgHello, I am trying to introspect my already created DB but when I run the cli command I get: ``` > d