-
Notifications
You must be signed in to change notification settings - Fork 29
Fix normalization of custom array type #163
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -780,6 +780,12 @@ func normalizePostgreSQLType(input string) string { | |
| return after | ||
| } | ||
|
|
||
| // Handle custom array types (internal PostgreSQL array notation) | ||
| // e.g., _my_enum_type -> my_enum_type[] | ||
| if strings.HasPrefix(typeName, "_") { | ||
| return typeName[1:] + "[]" | ||
| } | ||
|
Comment on lines
+783
to
+787
|
||
|
|
||
| // Return as-is if no mapping found | ||
| return typeName | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ALTER TABLE items ADD COLUMN statuses status[]; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| CREATE TYPE status AS ENUM ( | ||
| 'pending', | ||
| 'active', | ||
| 'inactive', | ||
| 'archived' | ||
| ); | ||
|
|
||
| CREATE TABLE items ( | ||
| id uuid DEFAULT gen_random_uuid() NOT NULL, | ||
| name varchar(255) NOT NULL, | ||
| statuses status[] | ||
| ); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| CREATE TYPE status AS ENUM ( | ||
| 'pending', | ||
| 'active', | ||
| 'inactive', | ||
| 'archived' | ||
| ); | ||
|
|
||
| CREATE TABLE items ( | ||
| id uuid DEFAULT gen_random_uuid() NOT NULL, | ||
| name varchar(255) NOT NULL | ||
| ); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| { | ||
| "version": "1.0.0", | ||
| "pgschema_version": "1.4.0", | ||
| "created_at": "1970-01-01T00:00:00Z", | ||
| "source_fingerprint": { | ||
| "hash": "68e81c1d995e4acafbcc1d7cb0f4d8e866e177daf6d08e6f00c69e1338c6a14c" | ||
| }, | ||
| "groups": [ | ||
| { | ||
| "steps": [ | ||
| { | ||
| "sql": "ALTER TABLE items ADD COLUMN statuses status[];", | ||
| "type": "table.column", | ||
| "operation": "create", | ||
| "path": "public.items.statuses" | ||
| } | ||
| ] | ||
| } | ||
| ] | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ALTER TABLE items ADD COLUMN statuses status[]; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| Plan: 1 to modify. | ||
|
|
||
| Summary by type: | ||
| tables: 1 to modify | ||
|
|
||
| Tables: | ||
| ~ items | ||
| + statuses (column) | ||
|
|
||
| DDL to be executed: | ||
| -------------------------------------------------- | ||
|
|
||
| ALTER TABLE items ADD COLUMN statuses status[]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The pg_catalog prefix removal returns immediately without checking if the result is a custom array type. For example,
pg_catalog._my_enumwould be returned as_my_enuminstead of being further normalized tomy_enum[].The logic should continue to check for the underscore prefix after removing pg_catalog: