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]: Postgres push fails due to lack of quotes #2396

Open
jasongerbes opened this issue May 30, 2024 · 0 comments
Open

[BUG]: Postgres push fails due to lack of quotes #2396

jasongerbes opened this issue May 30, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@jasongerbes
Copy link

What version of drizzle-orm are you using?

0.30.10

What version of drizzle-kit are you using?

0.21.4

Describe the Bug

The drizzle-kit push command fails when using a Postgres database if a table has a composite primary key and it's name includes a "-".

This issue appears to be due to the CONSTRAINT name not being wrapped with quotes:

> drizzle-kit push

drizzle-kit: v0.21.4
drizzle-orm: v0.30.10

No config path provided, using default path
Reading config file '/Users/jasongerbes/Documents/GitHub/test-app/drizzle.config.ts'
Using '@vercel/postgres' driver for database querying
[Warning] '@vercel/postgres' can only connect to remote Neon/Vercel Postgres/Supabase instances through a websocket
[✓] Pulling schema from database...
 Warning  You are about to execute current statements:

ALTER TABLE "example-table" DROP CONSTRAINT example-table_userId_credentialID_pk;
--> statement-breakpoint
ALTER TABLE "example-table" ADD CONSTRAINT example-table_userId_credentialID_pk PRIMARY KEY(userId,credentialID);

error: syntax error at or near "-"

Expected behavior

The drizzle-kit push command should wrap CONSTRAINT names in quotes to prevent issues due to the inclusion of "-" in a table's name.

Environment & setup

Example table schema:

import { pgTable, primaryKey, text } from 'drizzle-orm/pg-core'

export const examples = pgTable(
  'example-table',
  {
    credentialID: text('credentialID').notNull().unique(),
    userId: text('userId').notNull(),
  },
  (example) => ({
    compositePK: primaryKey({
      columns: [example.userId, example.credentialID],
    }),
  }),
)

Reproduction steps:

  1. Set up a Postgres database (e.g. Vercel Postgres)
  2. Run drizzle-kit push
  3. Run drizzle-kit push again
@jasongerbes jasongerbes added the bug Something isn't working label May 30, 2024
@jasongerbes jasongerbes changed the title [BUG]: Postgres push failing due to lack of quotes [BUG]: Postgres push fails due to lack of quotes May 30, 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