Skip to content

[BUG]: Drizzle Kit push to Postgres 18 produces unecessary DROP SQL when the schema was NOT changed #4944

@JohnCido

Description

@JohnCido

Report hasn't been filed before.

  • 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.44.5

What version of drizzle-kit are you using?

0.31.5

Other packages

No response

Describe the Bug

Considering this given table:

import { sql } from "drizzle-orm";
import { pgTable, uuid } from "drizzle-orm/pg-core";

export const tests = pgTable("tests", {
	id: uuid("id").primaryKey().default(sql`uuidv7()`),
});

And this config:

import { defineConfig } from "drizzle-kit";

export default defineConfig({
	dialect: "postgresql",
	schema: "./index.ts",
	dbCredentials: {
		url: "postgresql://postgres:password@localhost:63104/postgres",
		ssl: false,
	},
	strict: true,
	verbose: true,
});

If you run the push command, it prints this log, which is OK:

[✓] Pulling schema from database...

 Warning  You are about to execute current statements:

CREATE TABLE "tests" (
        "id" uuid PRIMARY KEY DEFAULT uuidv7() NOT NULL
);


[✓] Changes applied

But, if you run push again without making any changes to the schema, instead of telling you there're no changes to be pushed, it prints the following SQL:

ALTER TABLE "tests" DROP CONSTRAINT "tests_id_not_null";

And of course it fails:

789 |     query.execute()
790 |   }
791 | 
792 |   function ErrorResponse(x) {
793 |     query && (query.cursorFn || query.describeFirst) && write(Sync)
794 |     const error = Errors.postgres(parseError(x))
                               ^
PostgresError: column "id" is in a primary key
 severity_local: "ERROR",
   severity: "ERROR",
       file: "tablecmds.c",
    routine: "dropconstraint_internal",
       code: "42P16"

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions