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]: drizzle-kit pull generate adds extra comma to the column config function #3563

Open
1 task done
vince-winkintel opened this issue Nov 15, 2024 · 0 comments
Open
1 task done
Labels
bug Something isn't working

Comments

@vince-winkintel
Copy link

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.36.3

What version of drizzle-kit are you using?

0.28.1

Other packages

drizzle-zod@0.5.1, @planetscale/database@1.19.0

Describe the Bug

Table DDL:

CREATE TABLE `fiscal_quarter` (
  `id` int unsigned NOT NULL AUTO_INCREMENT,
  `public_id` char(12) NOT NULL,
  `created_at` datetime(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
  `created_by` varchar(128) NOT NULL DEFAULT 'UNKNOWN',
  `updated_at` datetime(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3),
  `updated_by` varchar(128) NOT NULL DEFAULT 'UNKNOWN',
  `legacy_table` varchar(128) NULL,
  `legacy_id` int unsigned NULL,
  `quarter_number` tinyint unsigned NOT NULL CHECK (quarter_number IN (1, 2, 3, 4)),
  `year_number` smallint unsigned NOT NULL CHECK (LENGTH(year_number) = 4),
  `long_description` char(13) GENERATED ALWAYS AS (CONCAT(CASE quarter_number WHEN 1 THEN '1st' WHEN 2 THEN '2nd' WHEN 3 THEN '3rd' WHEN 4 THEN '4th' END, ' Qtr. ', year_number)) VIRTUAL NOT NULL,
  `short_description` char(6) GENERATED ALWAYS AS (CONCAT(quarter_number, 'Q', year_number)) VIRTUAL NOT NULL,
  `is_disabled` boolean NOT NULL DEFAULT true,
  PRIMARY KEY (`id`),
  UNIQUE INDEX `fiscal_quarter_public_id_ui` (`public_id`),
  UNIQUE INDEX `fiscal_quarter_qrt_yr_ui` (`quarter_number`,`year_number`),
  INDEX `fiscal_quarter_updated_at_idx` (`updated_at`),
  INDEX `fiscal_quarter_legacy_table_id_idx` (`legacy_table`, `legacy_id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

Result of drizzle-kit introspect:

export const fiscalQuarter = mysqlTable("fiscal_quarter", {
    id: int({ unsigned: true }).autoincrement().notNull(),
    publicId: char("public_id", { length: 12 }).notNull(),
    createdAt: datetime("created_at", { mode: 'string', fsp: 3 }).default(sql`(CURRENT_TIMESTAMP(3))`).notNull(),
    createdBy: varchar("created_by", { length: 128 }).default('UNKNOWN').notNull(),
    updatedAt: datetime("updated_at", { mode: 'string', fsp: 3 }).default(sql`(CURRENT_TIMESTAMP(3))`).notNull(),
    updatedBy: varchar("updated_by", { length: 128 }).default('UNKNOWN').notNull(),
    legacyTable: varchar("legacy_table", { length: 128 }),
    legacyId: int("legacy_id", , { unsigned: true }),
    quarterNumber: tinyint("quarter_number", , { unsigned: true }).notNull(),
    yearNumber: smallint("year_number", , { unsigned: true }).notNull(),
    longDescription: char("long_description", { length: 13 }).notNull().generatedAlwaysAs(sql`concat((case \`quarter_number\` when 1 then _utf8mb4\'1st\' when 2 then _utf8mb4\'2nd\' when 3 then _utf8mb4\'3rd\' when 4 then _utf8mb4\'4th\' end),_utf8mb4\' Qtr. \',\`year_number\`)`, { mode: "virtual" }),
    shortDescription: char("short_description", { length: 6 }).notNull().generatedAlwaysAs(sql`concat(\`quarter_number\`,_utf8mb4\'Q\',\`year_number\`)`, { mode: "virtual" }),
    isDisabled: tinyint("is_disabled").default(1).notNull(),
},
    (table) => {
        return {
            updatedAtIdx: index("fiscal_quarter_updated_at_idx").on(table.updatedAt),
            legacyTableIdIdx: index("fiscal_quarter_legacy_table_id_idx").on(table.legacyTable, table.legacyId),
            fiscalQuarterId: primaryKey({ columns: [table.id], name: "fiscal_quarter_id" }),
            fiscalQuarterPublicIdUi: unique("fiscal_quarter_public_id_ui").on(table.publicId),
            fiscalQuarterQrtYrUi: unique("fiscal_quarter_qrt_yr_ui").on(table.quarterNumber, table.yearNumber),
            fiscalQuarterChk1: check("fiscal_quarter_chk_1", sql`(\`quarter_number\` in (1,2,3,4))`),
            fiscalQuarterChk2: check("fiscal_quarter_chk_2", sql`(length(\`year_number\`) = 4)`),
        }
    });

The legacyId, quarterNumber, and yearNumber columns all have an extra comma in the int, tinyint, smallint functions:

...
legacyId: int("legacy_id", , { unsigned: true }),
...
@vince-winkintel vince-winkintel added the bug Something isn't working label Nov 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