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]: Default value in array generating wrong migration file #1003

Closed
Aaditya-23 opened this issue Aug 8, 2023 · 3 comments
Closed

[BUG]: Default value in array generating wrong migration file #1003

Aaditya-23 opened this issue Aug 8, 2023 · 3 comments
Assignees
Labels
bug Something isn't working db/postgres drizzle/kit

Comments

@Aaditya-23
Copy link

What version of drizzle-orm are you using?

0.28.0

What version of drizzle-kit are you using?

0.19.12

Describe the Bug

This is my drizzle schema.

export const responses = pgTable('responses', {
  id: uuid('id').defaultRandom().primaryKey(),
  response: uuid('user_response').array().default([]).notNull(),
  isCorrect: boolean('is_correct'),
  userTestId: uuid('user_test_id')
    .references(() => userTests.id)
    .notNull(),
  questionId: uuid('question_id')
    .references(() => questions.id)
    .notNull(),
  createdAt: timestamp('created_at').defaultNow().notNull(),
})

Migrations look like this

CREATE TABLE IF NOT EXISTS "responses" (
	"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"user_response" uuid[] DEFAULT  NOT NULL,
	"is_correct" boolean,
	"user_test_id" uuid NOT NULL,
	"question_id" uuid NOT NULL,
	"created_at" timestamp DEFAULT now() NOT NULL
);

Expected behavior

Whereas user_response column should be like

`"user_response" uuid[] DEFAULT '{}' NOT NULL,`

Environment & setup

I am using Next13, vercel postgres and turborepo.

@Aaditya-23 Aaditya-23 added the bug Something isn't working label Aug 8, 2023
@Aaditya-23
Copy link
Author

Hey team @AndriiSherman any updates on this issue? I am unable to use db push because of this issue and I don't want migration files in my codebase.

@DevTobias
Copy link

I think you could use the magic sql operator to avoid this issue:

{
  response: uuid('user_response').array().default(sql`'{}'`).notNull(),
}

@AndriiSherman
Copy link
Member

Should be fixed in drizzle-kit0.24.0
Please check release notes before updating

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working db/postgres drizzle/kit
Projects
None yet
Development

No branches or pull requests

5 participants