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]: Invalid schema generation on postgres instrospect #2337

Closed
duckboy81 opened this issue May 16, 2024 · 1 comment
Closed

[BUG]: Invalid schema generation on postgres instrospect #2337

duckboy81 opened this issue May 16, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@duckboy81
Copy link

What version of drizzle-orm are you using?

v0.20.18

What version of drizzle-kit are you using?

v0.30.10

Describe the Bug

Smallest of issues: During introspection, the resultant schema.ts is missing a comma in the extraConfig section for a PgTable.

Given the following database table:

create table public.organization_code_configuration
(
    code_config_id         integer                  not null
        constraint organization_code_configuration_code_configuration_code_config_
            references public.code_configuration
            on update cascade on delete restrict,
    org_id                 uuid                     not null
        constraint organization_code_configuration_organization_org_id_fk
            references public.organization
            on update cascade on delete cascade,
    effective              date                     not null,
    last_updated           timestamp with time zone not null,
    last_updated_by        uuid,
    can_edit_configuration boolean default false    not null,
    constraint organization_code_configuration_pk
        primary key (org_id, code_config_id),
    constraint organization_code_configuration_pk_2
        unique (org_id, effective)
);

comment on constraint organization_code_configuration_code_configuration_code_config_ on public.organization_code_configuration is 'prevents deletion of a code configuration while an organization still has a link to it';

alter table public.organization_code_configuration
    owner to postgres;

Run drizzle-kit introspect:pg

Expected behavior

Current behavior. Notice the missing comma after name: "organization_code_configuration_pk"}) (4th line from the bottom)

export const organizationCodeConfiguration = pgTable("organization_code_configuration", {
	codeConfigId: integer("code_config_id").notNull().references(() => codeConfiguration.codeConfigId, { onDelete: "restrict", onUpdate: "cascade" } ),
	orgId: uuid("org_id").notNull().references(() => organization.orgId, { onDelete: "cascade", onUpdate: "cascade" } ),
	effective: date("effective").notNull(),
	lastUpdated: timestamp("last_updated", { withTimezone: true, mode: 'string' }).notNull(),
	lastUpdatedBy: uuid("last_updated_by"),
	canEditConfiguration: boolean("can_edit_configuration").default(false).notNull(),
},
(table) => {
	return {
		organizationCodeConfigurationPk: primaryKey({ columns: [table.codeConfigId, table.orgId], name: "organization_code_configuration_pk"})
		organizationCodeConfigurationSingleConfigPerDay: unique("organization_code_configuration_single_config_per_day").on(table.orgId, table.effective),
	}
});

Environment & setup

Windows 11, node v20.13.1, cli

@duckboy81 duckboy81 added the bug Something isn't working label May 16, 2024
@AlexBlokh
Copy link
Contributor

can you please check on version drizzle-kit@0.21.3, should be fixed, we didn't manage to reproduce with your schema

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

2 participants