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

[Pg] Fix many introspection issues #2804

Closed

Conversation

L-Mario564
Copy link
Collaborator

@L-Mario564 L-Mario564 commented Aug 16, 2024

Addresses #1210, #1928, #1625, #2315, #2714, #1633, #1648.

This PR aims to fix many introspection issues for the PG dialect in Drizzle Kit.

Summary of fixes

  • Handle sql values:
id: integer("id").default(nextval('deal_id_seq'::regclass)).primaryKey().notNull(); // Current
id: integer("id").default(sql`nextval('deal_id_seq'::regclass)`).primaryKey().notNull(); // Fix
  • Wrap string in quotes if the column name is an invalid object key:
top:detected: tinyint("Top:detected"); // Current
'top:detected': tinyint("Top:detected"); // Fix
  • Handle default null:
create table "users" ( "phone" text default null::text );
phone: text("phone").default(NULL::text); // Current
phone: text("phone"); // Fix
  • Correctly reference enums in different schemas:
const auth = pgSchema("auth");
const aalLevelInAuth = auth.enum("aal_level", ['aal1', 'aal2', 'aal3']);
aal: aalLevel("aal"); // Current
aal: aalLevelInAuth("aal"); // Fix
  • Fix enums "overlapping" with native types:
const timeLeft = pgEnum("TimeLeft", ['VERY_LONG', 'SHORT', 'MEDIUM', 'LONG']);
timeLeft: time("timeLeft").notNull(); // Current. This happens because the enum began with "time" and the native "time" got picked up instead
timeLeft: timeLeft("timeLeft").notNull(); // Fix

@L-Mario564 L-Mario564 marked this pull request as draft August 16, 2024 03:34
@L-Mario564 L-Mario564 marked this pull request as ready for review August 16, 2024 05:07
@AndriiSherman
Copy link
Member

Thanks! I fixed most of the same issues yesterday, so I'll merge your PR and find the places where we have common fixes and what you additionally fixed

@AndriiSherman
Copy link
Member

I'll close this one as long as it had a lot of conflicts with another implementation that was fixed. I took some ideas from this PR, like removing "::" mappings in introspect and some array type default handlers

I didn't merge it, because it would have caused more problems and taken more time to resolve

Thanks a lot for you work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants