drizzle-team / drizzle-orm

Headless TypeScript ORM with a head. Runs on Node, Bun and Deno. Lives on the Edge and yes, it's a JavaScript ORM too 😅
https://orm.drizzle.team
Apache License 2.0
23.01k stars 550 forks source link

[BUG]: unexpected DROP SEQUENCE statements on `drizzle-kit push` #2643

Closed Entsllor closed 1 month ago

Entsllor commented 1 month ago

What version of drizzle-orm are you using?

0.32

What version of drizzle-kit are you using?

0.23

Describe the Bug

I want to create migrations only for "currentSchema", but when I am trying to push a new migration, drizzle kit is trying to delete sequences from other postgresql schemas

  1. Define config

    export default defineConfig({
    dialect: "postgresql",
    schema: "./src/models",
    out: "./migrations",
    schemaFilter: settings.DB_SCHEMA_NAME, // currentSchema
    migrations: {
        table: "migrations",
        schema: settings.DB_SCHEMA_NAME,
    },
    dbCredentials: {
        url: settings.DB_URL,
    },
    verbose: true,
    strict: true,
    });
  2. Define any model

    export const BaseSchema = pgSchema(settings.DB_SCHEMA_NAME);
    export const groups = BaseSchema.table("groups", {
    id: uuid('id').primaryKey().notNull().$default(uuid4)
    });
  3. Generate migration via drizzle-kit generate You will see something an expected migration file without DROP statements

    CREATE SCHEMA "currentSchema"; -- unrelated but also a bug https://github.com/drizzle-team/drizzle-orm/issues/2335
    --> statement-breakpoint
    CREATE TABLE IF NOT EXISTS "currentSchema"."groups" (
    "id" uuid PRIMARY KEY NOT NULL
    );
  4. drizzle-kit push

    
    -- drizzle-kit: v0.23.0
    -- drizzle-orm: v0.32.0
    -- Warning  You are about to execute current statements:

CREATE SCHEMA "currentSchema";

CREATE TABLE IF NOT EXISTS "currentSchema"."groups" ( "id" uuid PRIMARY KEY NOT NULL );

DROP SEQUENCE "ANOTHER_SCHEMA"."cities_id_seq"; DROP SEQUENCE "THIRD_SCHEMA"."users_id_seq";


These drop statements cause errors
`cannot drop sequence ANOTHER_SCHEMA.cities_id_seq because other objects depend on it`

### Expected behavior

This bug appers only while using drizzle-kit 0.23. 
When I am using drizzle-kit 0.22.8 and drizzle-orm 0.32 everything is ok.
drizzle-kit (0.22.8) push will print something this:
```sql
-- drizzle-kit: v0.22.8
-- drizzle-orm: v0.32.0
-- Warning  You are about to execute current statements:

CREATE SCHEMA "currentSchema";

CREATE TABLE IF NOT EXISTS "currentSchema"."groups" (
        "id" uuid PRIMARY KEY NOT NULL
);

Environment & setup

postgresql with at least 2 schemas ("currentSchema" and "ANOTHER_SCHEMA") drizzle-kit: v0.23.0 drizzle-orm: v0.32.0 using postgres.js v3.4.4

AndriiSherman commented 1 month ago

thanks, will fix that!

AndriiSherman commented 1 month ago

should be fixed in drizzle-kit@0.23.1