close
Skip to content

[BUG]: Array default in migrations are wrong #2621

@cybercoder-naj

Description

@cybercoder-naj

What version of drizzle-orm are you using?

0.31.2

What version of drizzle-kit are you using?

0.22.8

Describe the Bug

For the given schema in typescript:

export const users = schema.table('users', {
  id: text('id').primaryKey(),
  /* removed for brevity */
  dietaryRestrictions: text('dietary_restrictions')
    .array()
    .notNull()
    .default([]),
  allergies: text('allergies').array().notNull().default([]),
  meals: boolean('meals').array().notNull().default([false, false, false])
});

the migration schema provided was:

CREATE TABLE IF NOT EXISTS "auth"."users" (
    "id" text PRIMARY KEY NOT NULL, 
    --> removed for brevity
    "dietary_restrictions" text[] DEFAULT  NOT NULL,
    "allergies" text[] DEFAULT  NOT 
    "meals" boolean[] DEFAULT false,false,false NOT NULL,
);

The default values given for arrays are not correct.

Expected behavior

The migration sql must output:

CREATE TABLE IF NOT EXISTS "auth"."users" (
    "id" text PRIMARY KEY NOT NULL,
    --> removed for brevity
    "dietary_restrictions" text[] DEFAULT '{}' NOT NULL,
    "allergies" text[] DEFAULT '{}' NOT NULL,
    "pronouns" text NOT NULL,
    "meals" boolean[] DEFAULT '{false,false,false}' NOT NULL
);

Environment & setup

bun v1.1.18, linux x86

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions