Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG]: Incorrect migration generation for constraints with schemas/databases in PostgreSQL #2319

Open
buyna-gtn opened this issue May 15, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@buyna-gtn
Copy link

buyna-gtn commented May 15, 2024

What version of drizzle-orm are you using?

0.30.10

What version of drizzle-kit are you using?

0.21.1

Describe the Bug

Drizzle kit is generating incorrect migrations, when adding composite unique constraint on new columns in existing PostgreSQL table. Columns were created inside the table without the unique constraint.

const user = pgTable(
  "user",
  {
    id: uuid("id").primaryKey().defaultRandom(),
    email: text("email").unique().notNull(),

    // Newly added columns
    firstName: text("first_name").notNull(),
    lastName: text("last_name").notNull(),
    //-------------------------------------
    role: userRole("role").notNull().default("member"),
    status: userStatus("status").notNull().default("active"),

    createdAt: timestamp("created_at").notNull().defaultNow(),
    updatedAt: timestamp("updated_at").notNull().defaultNow(),
  },
  (table) => ({
    nameUnq: unique().on(table.firstName, table.lastName),
  }),
);

GENERATED MIGRATION:

ALTER TABLE "user" ADD COLUMN "first_name" text NOT NULL;--> statement-breakpoint
ALTER TABLE "user" ADD COLUMN "last_name" text NOT NULL;

Expected behavior

Drizzle kit should generate composite unique constraint on first_name and last_name columns.

Environment & setup

No response

@buyna-gtn buyna-gtn added the bug Something isn't working label May 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant