Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions ir/normalize.go
Original file line number Diff line number Diff line change
Expand Up @@ -780,6 +780,12 @@ func normalizePostgreSQLType(input string) string {
return after
Copy link

Copilot AI Nov 14, 2025

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_enum would be returned as _my_enum instead of being further normalized to my_enum[].

The logic should continue to check for the underscore prefix after removing pg_catalog:

// Remove pg_catalog prefix for unmapped types
if after, found := strings.CutPrefix(typeName, "pg_catalog."); found {
    typeName = after
}

// Handle custom array types (internal PostgreSQL array notation)
// e.g., _my_enum_type -> my_enum_type[]
if strings.HasPrefix(typeName, "_") {
    return typeName[1:] + "[]"
}

return typeName
Suggested change
return after
typeName = after

Copilot uses AI. Check for mistakes.
}

// 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
Copy link

Copilot AI Nov 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The custom array type normalization only handles direct type names but doesn't handle type casts. When custom array types appear in expressions with type casts (e.g., value::_my_enum), they won't be normalized to value::my_enum[].

Consider adding normalization for custom array types in the type cast handling section (lines 756-759). For example:

// Replace PostgreSQL internal type names with standard SQL types in type casts
for pgType, sqlType := range typeMap {
    expr = strings.ReplaceAll(expr, "::"+pgType, "::"+sqlType)
}

// Handle custom array types in type casts
// e.g., ::_my_enum -> ::my_enum[]
expr = regexp.MustCompile(`::(pg_catalog\.)?_(\w+)`).ReplaceAllString(expr, "::$2[]")

Copilot uses AI. Check for mistakes.

// Return as-is if no mapping found
return typeName
}
Expand Down
1 change: 1 addition & 0 deletions testdata/diff/create_table/enum_array_column/diff.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE items ADD COLUMN statuses status[];
12 changes: 12 additions & 0 deletions testdata/diff/create_table/enum_array_column/new.sql
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[]
);
11 changes: 11 additions & 0 deletions testdata/diff/create_table/enum_array_column/old.sql
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
);
20 changes: 20 additions & 0 deletions testdata/diff/create_table/enum_array_column/plan.json
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"
}
]
}
]
}
1 change: 1 addition & 0 deletions testdata/diff/create_table/enum_array_column/plan.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE items ADD COLUMN statuses status[];
13 changes: 13 additions & 0 deletions testdata/diff/create_table/enum_array_column/plan.txt
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[];
Loading