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
9 changes: 8 additions & 1 deletion internal/diff/function.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,15 @@ func formatFunctionParameter(param *ir.Parameter, includeDefault bool, targetSch
}

// Add DEFAULT value if present and requested
// Strip schema prefix from default value type casts
// We strip both the target schema prefix and any temporary schema prefix (pgschema_tmp_*)
if includeDefault && param.DefaultValue != nil {
part += " DEFAULT " + *param.DefaultValue
defaultVal := *param.DefaultValue
// Strip target schema prefix
defaultVal = stripSchemaPrefix(defaultVal, targetSchema)
// Also strip temporary embedded postgres schema prefixes (pgschema_tmp_*)
defaultVal = stripTempSchemaPrefix(defaultVal)
part += " DEFAULT " + defaultVal
}

return part
Expand Down
38 changes: 36 additions & 2 deletions internal/diff/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,55 @@ import (
"github.com/pgschema/pgschema/ir"
)

// stripSchemaPrefix removes the schema prefix from a type name if it matches the target schema
// stripSchemaPrefix removes the schema prefix from a type name if it matches the target schema.
// It handles both simple type names (e.g., "schema.typename") and type casts within expressions
// (e.g., "'value'::schema.typename" -> "'value'::typename").
func stripSchemaPrefix(typeName, targetSchema string) string {
if typeName == "" || targetSchema == "" {
return typeName
}

// Check if the type has the target schema prefix
// Check if the type has the target schema prefix at the beginning
prefix := targetSchema + "."
if after, found := strings.CutPrefix(typeName, prefix); found {
return after
}

// Also handle type casts within expressions: ::schema.typename -> ::typename
// This is needed for function parameter default values like 'value'::schema.enum_type
castPrefix := "::" + targetSchema + "."
if strings.Contains(typeName, castPrefix) {
return strings.ReplaceAll(typeName, castPrefix, "::")
Comment on lines +28 to +29
Copy link

Copilot AI Dec 29, 2025

Choose a reason for hiding this comment

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

Using strings.ReplaceAll will replace all occurrences of the schema prefix in the type name, which could cause issues if the schema name appears in other parts of the expression. For example, if targetSchema is "public" and typeName is "CASE WHEN public.status = 'active'::public.status_enum THEN 'yes'::public.yes_no END", this would replace all instances of "::public." with "::", resulting in malformed SQL.

Consider using a more targeted approach that only replaces the specific occurrence related to the type cast, or add additional validation to ensure you're only replacing type cast contexts.

Copilot uses AI. Check for mistakes.
}

return typeName
}

// stripTempSchemaPrefix removes temporary embedded postgres schema prefixes (pgschema_tmp_*).
// These are used internally during plan generation and should not appear in output DDL.
func stripTempSchemaPrefix(value string) string {
if value == "" {
return value
}

// Pattern: ::pgschema_tmp_YYYYMMDD_HHMMSS_XXXXXXXX.typename -> ::typename
// We look for ::pgschema_tmp_ followed by anything until the next dot
idx := strings.Index(value, "::pgschema_tmp_")
if idx == -1 {
return value
}

// Find the dot after pgschema_tmp_*
dotIdx := strings.Index(value[idx+15:], ".")
if dotIdx == -1 {
return value
}

// Replace ::pgschema_tmp_XXX.typename with ::typename
prefix := value[idx : idx+15+dotIdx+1] // includes the trailing dot
Comment on lines +44 to +56
Copy link

Copilot AI Dec 29, 2025

Choose a reason for hiding this comment

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

The hardcoded offset of 15 in value[idx+15:] assumes the literal string "::pgschema_tmp_" is exactly 15 characters. However, "::pgschema_tmp_" is actually 16 characters (2 colons + "pgschema_tmp_" which is 14 characters). This off-by-one error means the function is starting its search for the dot one character too early, which could cause it to miss or incorrectly handle the schema prefix.

The correct offset should be 16, not 15. Also consider using len("::pgschema_tmp_") instead of a magic number for better maintainability.

Suggested change
idx := strings.Index(value, "::pgschema_tmp_")
if idx == -1 {
return value
}
// Find the dot after pgschema_tmp_*
dotIdx := strings.Index(value[idx+15:], ".")
if dotIdx == -1 {
return value
}
// Replace ::pgschema_tmp_XXX.typename with ::typename
prefix := value[idx : idx+15+dotIdx+1] // includes the trailing dot
tempPrefix := "::pgschema_tmp_"
idx := strings.Index(value, tempPrefix)
if idx == -1 {
return value
}
// Find the dot after pgschema_tmp_*
dotIdx := strings.Index(value[idx+len(tempPrefix):], ".")
if dotIdx == -1 {
return value
}
// Replace ::pgschema_tmp_XXX.typename with ::typename
prefix := value[idx : idx+len(tempPrefix)+dotIdx+1] // includes the trailing dot

Copilot uses AI. Check for mistakes.
Comment on lines +50 to +56
Copy link

Copilot AI Dec 29, 2025

Choose a reason for hiding this comment

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

The same off-by-one error exists here. The calculation idx+15+dotIdx+1 uses 15 instead of the correct length of "::pgschema_tmp_" which is 16. This will cause the prefix extraction to include one extra character before the "::" or exclude one character that should be included.

The correct calculation should be idx + len("::pgschema_tmp_") + dotIdx + 1 or idx + 16 + dotIdx + 1.

Suggested change
dotIdx := strings.Index(value[idx+15:], ".")
if dotIdx == -1 {
return value
}
// Replace ::pgschema_tmp_XXX.typename with ::typename
prefix := value[idx : idx+15+dotIdx+1] // includes the trailing dot
dotIdx := strings.Index(value[idx+len("::pgschema_tmp_"):], ".")
if dotIdx == -1 {
return value
}
// Replace ::pgschema_tmp_XXX.typename with ::typename
prefix := value[idx : idx+len("::pgschema_tmp_")+dotIdx+1] // includes the trailing dot

Copilot uses AI. Check for mistakes.
return strings.ReplaceAll(value, prefix, "::")
Comment on lines +43 to +57
Copy link

Copilot AI Dec 29, 2025

Choose a reason for hiding this comment

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

Similar to the issue in stripSchemaPrefix, using strings.ReplaceAll here could cause problems if there are multiple temporary schema prefixes in the value, or if the extracted prefix accidentally matches other parts of the expression.

Additionally, this function only handles the first occurrence it finds (since it searches from the beginning), but then uses ReplaceAll which will replace all occurrences. This creates an inconsistency: if there are multiple different temporary schema prefixes (e.g., ::pgschema_tmp_20231201_120000_ABC.type1 and ::pgschema_tmp_20231201_130000_XYZ.type2), the function will only extract the prefix for the first one but attempt to replace all occurrences of that prefix, potentially leaving other temporary prefixes in place.

Consider either using strings.Replace(value, prefix, "::", 1) to only replace the first occurrence, or looping to handle all temporary schema prefixes in the value.

Suggested change
// We look for ::pgschema_tmp_ followed by anything until the next dot
idx := strings.Index(value, "::pgschema_tmp_")
if idx == -1 {
return value
}
// Find the dot after pgschema_tmp_*
dotIdx := strings.Index(value[idx+15:], ".")
if dotIdx == -1 {
return value
}
// Replace ::pgschema_tmp_XXX.typename with ::typename
prefix := value[idx : idx+15+dotIdx+1] // includes the trailing dot
return strings.ReplaceAll(value, prefix, "::")
// We look for ::pgschema_tmp_ followed by anything until the next dot.
const tmpPrefix = "::pgschema_tmp_"
for {
idx := strings.Index(value, tmpPrefix)
if idx == -1 {
break
}
// Find the dot after pgschema_tmp_*
dotIdx := strings.Index(value[idx+len(tmpPrefix):], ".")
if dotIdx == -1 {
// No terminating dot; nothing more to strip safely.
break
}
// Replace this specific ::pgschema_tmp_XXX.typename with ::typename
prefixEnd := idx + len(tmpPrefix) + dotIdx + 1 // includes the trailing dot
prefix := value[idx:prefixEnd]
value = strings.Replace(value, prefix, "::", 1)
}
return value

Copilot uses AI. Check for mistakes.
}
Comment on lines 12 to +58
Copy link

Copilot AI Dec 29, 2025

Choose a reason for hiding this comment

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

The new stripSchemaPrefix and stripTempSchemaPrefix helper functions lack unit tests. Given the complexity of these functions and the edge cases they need to handle (multiple occurrences, off-by-one errors, nested expressions), comprehensive unit tests would help ensure correctness and prevent regressions.

Consider adding unit tests that cover:

  • Simple type name prefix stripping
  • Type casts within expressions
  • Multiple occurrences of schema prefixes
  • Edge cases like empty strings, missing dots, etc.
  • Temporary schema prefix patterns with various timestamp formats

Copilot uses AI. Check for mistakes.

// sortConstraintColumnsByPosition sorts constraint columns by their position
func sortConstraintColumnsByPosition(columns []*ir.ConstraintColumn) []*ir.ConstraintColumn {
sorted := make([]*ir.ConstraintColumn, len(columns))
Expand Down
38 changes: 24 additions & 14 deletions ir/normalize.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,14 @@ func normalizeDefaultValue(value string, tableSchema string) string {

// Handle type casting - remove explicit type casts that are semantically equivalent
if strings.Contains(value, "::") {
// Strip temporary embedded postgres schema prefixes (pgschema_tmp_*)
// These are used internally during plan generation and should be normalized away
// Pattern: ::pgschema_tmp_YYYYMMDD_HHMMSS_XXXXXXXX.typename -> ::typename
if strings.Contains(value, "::pgschema_tmp_") {
re := regexp.MustCompile(`::pgschema_tmp_[^.]+\.`)
value = re.ReplaceAllString(value, "::")
}

// Handle NULL::type -> NULL
// Example: NULL::text -> NULL
re := regexp.MustCompile(`\bNULL::(?:[a-zA-Z_][\w\s.]*)(?:\[\])?`)
Expand All @@ -146,22 +154,24 @@ func normalizeDefaultValue(value string, tableSchema string) string {
re = regexp.MustCompile(`'(-?\d+(?:\.\d+)?)'::(?:integer|bigint|smallint|numeric|decimal|real|double precision|int2|int4|int8|float4|float8)`)
value = re.ReplaceAllString(value, "$1")

// Handle string literals with type casts (including escaped quotes)
// Example: 'text'::text -> 'text'
// Example: 'O''Brien'::text -> 'O''Brien'
// Example: '{}'::jsonb -> '{}'
// Example: '{1,2,3}'::integer[] -> '{1,2,3}'
// Pattern explanation:
// '(?:[^']|'')*' - matches a quoted string literal, handling escaped quotes ''
// ::[a-zA-Z_][\w\s.]* - matches ::typename
// (?:\[\])? - optionally followed by [] for array types
re = regexp.MustCompile(`('(?:[^']|'')*')::(?:[a-zA-Z_][\w\s.]*)(?:\[\])?`)
// Handle string literals with ONLY truly redundant type casts
// Only remove casts where the literal is inherently the target type:
// Example: 'text'::text -> 'text' (string literal IS text)
// Example: 'O''Brien'::character varying -> 'O''Brien'
// Example: '{}'::text[] -> '{}' (empty array literal with text array cast)
// Example: '{}'::jsonb -> '{}' (JSON object literal - column type provides context)
//
// IMPORTANT: Do NOT remove semantically significant casts like:
// - '1 year'::interval (interval literals REQUIRE the cast)
// - 'value'::my_enum (custom type casts)
// - '2024-01-01'::date (date literals need the cast in expressions)
//
// Pattern matches redundant text/varchar/char/json casts (including arrays)
// Note: jsonb must come before json to avoid partial match
// Note: (?:\[\])* handles multi-dimensional arrays like text[][]
re = regexp.MustCompile(`('(?:[^']|'')*')::(text|character varying|character|bpchar|varchar|jsonb|json)(?:\[\])*`)
value = re.ReplaceAllString(value, "$1")

// Handle date/timestamp literals with type casts
// Example: '2024-01-01'::date -> '2024-01-01'
// Already handled by the string literal pattern above

// Handle parenthesized expressions with type casts - remove outer parentheses
// Example: (100)::bigint -> 100::bigint
// Pattern captures the number and the type cast separately
Expand Down
3 changes: 2 additions & 1 deletion testdata/diff/create_function/add_function/diff.sql
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ CREATE OR REPLACE FUNCTION process_order(
note varchar DEFAULT '',
status text DEFAULT 'pending',
apply_tax boolean DEFAULT true,
is_priority boolean DEFAULT false
is_priority boolean DEFAULT false,
expiry_date date DEFAULT (CURRENT_DATE + '1 year'::interval)
)
RETURNS numeric
LANGUAGE plpgsql
Expand Down
4 changes: 3 additions & 1 deletion testdata/diff/create_function/add_function/new.sql
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ CREATE FUNCTION process_order(
status text DEFAULT 'pending',
-- Boolean defaults
apply_tax boolean DEFAULT true,
is_priority boolean DEFAULT false
is_priority boolean DEFAULT false,
-- Interval default (reproduces issue #216)
expiry_date date DEFAULT (CURRENT_DATE + INTERVAL '1 year')
)
RETURNS numeric
LANGUAGE plpgsql
Expand Down
2 changes: 1 addition & 1 deletion testdata/diff/create_function/add_function/plan.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"path": "public.mask_sensitive_data"
},
{
"sql": "CREATE OR REPLACE FUNCTION process_order(\n order_id integer,\n discount_percent numeric DEFAULT 0,\n priority_level integer DEFAULT 1,\n note varchar DEFAULT '',\n status text DEFAULT 'pending',\n apply_tax boolean DEFAULT true,\n is_priority boolean DEFAULT false\n)\nRETURNS numeric\nLANGUAGE plpgsql\nVOLATILE\nSTRICT\nSECURITY DEFINER\nLEAKPROOF\nPARALLEL RESTRICTED\nAS $$\nDECLARE\n total numeric;\nBEGIN\n SELECT amount INTO total FROM orders WHERE id = order_id;\n RETURN total - (total * discount_percent / 100);\nEND;\n$$;",
"sql": "CREATE OR REPLACE FUNCTION process_order(\n order_id integer,\n discount_percent numeric DEFAULT 0,\n priority_level integer DEFAULT 1,\n note varchar DEFAULT '',\n status text DEFAULT 'pending',\n apply_tax boolean DEFAULT true,\n is_priority boolean DEFAULT false,\n expiry_date date DEFAULT (CURRENT_DATE + '1 year'::interval)\n)\nRETURNS numeric\nLANGUAGE plpgsql\nVOLATILE\nSTRICT\nSECURITY DEFINER\nLEAKPROOF\nPARALLEL RESTRICTED\nAS $$\nDECLARE\n total numeric;\nBEGIN\n SELECT amount INTO total FROM orders WHERE id = order_id;\n RETURN total - (total * discount_percent / 100);\nEND;\n$$;",
"type": "function",
"operation": "create",
"path": "public.process_order"
Expand Down
3 changes: 2 additions & 1 deletion testdata/diff/create_function/add_function/plan.sql
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ CREATE OR REPLACE FUNCTION process_order(
note varchar DEFAULT '',
status text DEFAULT 'pending',
apply_tax boolean DEFAULT true,
is_priority boolean DEFAULT false
is_priority boolean DEFAULT false,
expiry_date date DEFAULT (CURRENT_DATE + '1 year'::interval)
)
RETURNS numeric
LANGUAGE plpgsql
Expand Down
3 changes: 2 additions & 1 deletion testdata/diff/create_function/add_function/plan.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ CREATE OR REPLACE FUNCTION process_order(
note varchar DEFAULT '',
status text DEFAULT 'pending',
apply_tax boolean DEFAULT true,
is_priority boolean DEFAULT false
is_priority boolean DEFAULT false,
expiry_date date DEFAULT (CURRENT_DATE + '1 year'::interval)
)
RETURNS numeric
LANGUAGE plpgsql
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
CREATE OR REPLACE FUNCTION process_order(
order_id integer,
discount_percent numeric DEFAULT 0,
status order_status DEFAULT 'pending',
priority utils.priority_level DEFAULT 'medium'
status order_status DEFAULT 'pending'::order_status,
priority utils.priority_level DEFAULT 'medium'::utils.priority_level
)
RETURNS numeric
LANGUAGE plpgsql
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ CREATE TYPE order_status AS ENUM ('pending', 'processing', 'completed', 'cancell
CREATE FUNCTION process_order(
order_id integer,
discount_percent numeric DEFAULT 0,
status order_status DEFAULT 'pending',
priority utils.priority_level DEFAULT 'medium'
status order_status DEFAULT 'pending'::order_status,
priority utils.priority_level DEFAULT 'medium'::utils.priority_level
)
RETURNS numeric
LANGUAGE plpgsql
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
"pgschema_version": "1.5.1",
"created_at": "1970-01-01T00:00:00Z",
"source_fingerprint": {
"hash": "07aea23ff65a63da587c7fddf4fe417ec7e0cbddbff86a8775bb4bfc5d1b011f"
"hash": "fc335bb328a0b47f89b922eadc006adbeadd205c59890bb5523a57bb00e854b9"
},
"groups": [
{
"steps": [
{
"sql": "CREATE OR REPLACE FUNCTION process_order(\n order_id integer,\n discount_percent numeric DEFAULT 0,\n status order_status DEFAULT 'pending',\n priority utils.priority_level DEFAULT 'medium'\n)\nRETURNS numeric\nLANGUAGE plpgsql\nSTABLE\nAS $$\nDECLARE\n base_price numeric;\n tax_rate numeric := 0.08;\nBEGIN\n -- Different logic: calculate with tax instead of just discount\n -- Status and priority parameters are available but not used in this simplified version\n SELECT price INTO base_price FROM products WHERE id = order_id;\n RETURN base_price * (1 - discount_percent / 100) * (1 + tax_rate);\nEND;\n$$;",
"sql": "CREATE OR REPLACE FUNCTION process_order(\n order_id integer,\n discount_percent numeric DEFAULT 0,\n status order_status DEFAULT 'pending'::order_status,\n priority utils.priority_level DEFAULT 'medium'::utils.priority_level\n)\nRETURNS numeric\nLANGUAGE plpgsql\nSTABLE\nAS $$\nDECLARE\n base_price numeric;\n tax_rate numeric := 0.08;\nBEGIN\n -- Different logic: calculate with tax instead of just discount\n -- Status and priority parameters are available but not used in this simplified version\n SELECT price INTO base_price FROM products WHERE id = order_id;\n RETURN base_price * (1 - discount_percent / 100) * (1 + tax_rate);\nEND;\n$$;",
"type": "function",
"operation": "alter",
"path": "public.process_order"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
CREATE OR REPLACE FUNCTION process_order(
order_id integer,
discount_percent numeric DEFAULT 0,
status order_status DEFAULT 'pending',
priority utils.priority_level DEFAULT 'medium'
status order_status DEFAULT 'pending'::order_status,
priority utils.priority_level DEFAULT 'medium'::utils.priority_level
)
RETURNS numeric
LANGUAGE plpgsql
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ DDL to be executed:
CREATE OR REPLACE FUNCTION process_order(
order_id integer,
discount_percent numeric DEFAULT 0,
status order_status DEFAULT 'pending',
priority utils.priority_level DEFAULT 'medium'
status order_status DEFAULT 'pending'::order_status,
priority utils.priority_level DEFAULT 'medium'::utils.priority_level
)
RETURNS numeric
LANGUAGE plpgsql
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ALTER TABLE users ADD COLUMN fqdn citext NOT NULL;
ALTER TABLE users ADD COLUMN metadata utils.hstore;
ALTER TABLE users ADD COLUMN description utils.custom_text;
ALTER TABLE users ADD COLUMN status utils.custom_enum DEFAULT 'active';
ALTER TABLE users ADD COLUMN status utils.custom_enum DEFAULT 'active'::utils.custom_enum;
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"path": "public.users.description"
},
{
"sql": "ALTER TABLE users ADD COLUMN status utils.custom_enum DEFAULT 'active';",
"sql": "ALTER TABLE users ADD COLUMN status utils.custom_enum DEFAULT 'active'::utils.custom_enum;",
"type": "table.column",
"operation": "create",
"path": "public.users.status"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ ALTER TABLE users ADD COLUMN metadata utils.hstore;

ALTER TABLE users ADD COLUMN description utils.custom_text;

ALTER TABLE users ADD COLUMN status utils.custom_enum DEFAULT 'active';
ALTER TABLE users ADD COLUMN status utils.custom_enum DEFAULT 'active'::utils.custom_enum;
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ ALTER TABLE users ADD COLUMN metadata utils.hstore;

ALTER TABLE users ADD COLUMN description utils.custom_text;

ALTER TABLE users ADD COLUMN status utils.custom_enum DEFAULT 'active';
ALTER TABLE users ADD COLUMN status utils.custom_enum DEFAULT 'active'::utils.custom_enum;
2 changes: 1 addition & 1 deletion testdata/diff/create_table/alter_column_types/diff.sql
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ ALTER TABLE user_pending_permissions ALTER COLUMN status DROP DEFAULT;

ALTER TABLE user_pending_permissions ALTER COLUMN status TYPE action_type USING status::action_type;

ALTER TABLE user_pending_permissions ALTER COLUMN status SET DEFAULT 'pending';
ALTER TABLE user_pending_permissions ALTER COLUMN status SET DEFAULT 'pending'::action_type;

ALTER TABLE user_pending_permissions ALTER COLUMN tags TYPE action_type[] USING tags::action_type[];
2 changes: 1 addition & 1 deletion testdata/diff/create_table/alter_column_types/plan.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"path": "public.user_pending_permissions.status"
},
{
"sql": "ALTER TABLE user_pending_permissions ALTER COLUMN status SET DEFAULT 'pending';",
"sql": "ALTER TABLE user_pending_permissions ALTER COLUMN status SET DEFAULT 'pending'::action_type;",
"type": "table.column",
"operation": "alter",
"path": "public.user_pending_permissions.status"
Expand Down
2 changes: 1 addition & 1 deletion testdata/diff/create_table/alter_column_types/plan.sql
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ ALTER TABLE user_pending_permissions ALTER COLUMN status DROP DEFAULT;

ALTER TABLE user_pending_permissions ALTER COLUMN status TYPE action_type USING status::action_type;

ALTER TABLE user_pending_permissions ALTER COLUMN status SET DEFAULT 'pending';
ALTER TABLE user_pending_permissions ALTER COLUMN status SET DEFAULT 'pending'::action_type;

ALTER TABLE user_pending_permissions ALTER COLUMN tags TYPE action_type[] USING tags::action_type[];
2 changes: 1 addition & 1 deletion testdata/diff/create_table/alter_column_types/plan.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@ ALTER TABLE user_pending_permissions ALTER COLUMN status DROP DEFAULT;

ALTER TABLE user_pending_permissions ALTER COLUMN status TYPE action_type USING status::action_type;

ALTER TABLE user_pending_permissions ALTER COLUMN status SET DEFAULT 'pending';
ALTER TABLE user_pending_permissions ALTER COLUMN status SET DEFAULT 'pending'::action_type;

ALTER TABLE user_pending_permissions ALTER COLUMN tags TYPE action_type[] USING tags::action_type[];
2 changes: 1 addition & 1 deletion testdata/diff/migrate/v5/diff.sql
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ CREATE POLICY audit_insert_system ON audit FOR INSERT TO PUBLIC WITH CHECK (true

CREATE POLICY audit_user_isolation ON audit TO PUBLIC USING (user_name = CURRENT_USER);

ALTER TABLE employee ADD COLUMN status employee_status DEFAULT 'active' NOT NULL;
ALTER TABLE employee ADD COLUMN status employee_status DEFAULT 'active'::employee_status NOT NULL;
2 changes: 1 addition & 1 deletion testdata/diff/migrate/v5/plan.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
"path": "public.audit.audit_user_isolation"
},
{
"sql": "ALTER TABLE employee ADD COLUMN status employee_status DEFAULT 'active' NOT NULL;",
"sql": "ALTER TABLE employee ADD COLUMN status employee_status DEFAULT 'active'::employee_status NOT NULL;",
"type": "table.column",
"operation": "create",
"path": "public.employee.status"
Expand Down
2 changes: 1 addition & 1 deletion testdata/diff/migrate/v5/plan.sql
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ CREATE POLICY audit_insert_system ON audit FOR INSERT TO PUBLIC WITH CHECK (true

CREATE POLICY audit_user_isolation ON audit TO PUBLIC USING (user_name = CURRENT_USER);

ALTER TABLE employee ADD COLUMN status employee_status DEFAULT 'active' NOT NULL;
ALTER TABLE employee ADD COLUMN status employee_status DEFAULT 'active'::employee_status NOT NULL;
2 changes: 1 addition & 1 deletion testdata/diff/migrate/v5/plan.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,4 @@ CREATE POLICY audit_insert_system ON audit FOR INSERT TO PUBLIC WITH CHECK (true

CREATE POLICY audit_user_isolation ON audit TO PUBLIC USING (user_name = CURRENT_USER);

ALTER TABLE employee ADD COLUMN status employee_status DEFAULT 'active' NOT NULL;
ALTER TABLE employee ADD COLUMN status employee_status DEFAULT 'active'::employee_status NOT NULL;
2 changes: 1 addition & 1 deletion testdata/dump/bytebase/pgschema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
--

-- Dumped from database version PostgreSQL 17.5
-- Dumped by pgschema version 1.4.0
-- Dumped by pgschema version 1.5.1


--
Expand Down
2 changes: 1 addition & 1 deletion testdata/dump/employee/pgschema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
--

-- Dumped from database version PostgreSQL 18.0
-- Dumped by pgschema version 1.5.0
-- Dumped by pgschema version 1.5.1


--
Expand Down
4 changes: 2 additions & 2 deletions testdata/dump/issue_125_function_default/pgschema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
--

-- Dumped from database version PostgreSQL 18.0
-- Dumped by pgschema version 1.5.0
-- Dumped by pgschema version 1.5.1


--
Expand All @@ -13,7 +13,7 @@
CREATE OR REPLACE FUNCTION test_complex_defaults(
arr integer[] DEFAULT ARRAY[1, 2, 3],
json_data jsonb DEFAULT '{"key": "value"}',
range_val int4range DEFAULT '[1,10)',
range_val int4range DEFAULT '[1,10)'::int4range,
expr_default integer DEFAULT 40
)
RETURNS jsonb
Expand Down
4 changes: 2 additions & 2 deletions testdata/dump/sakila/pgschema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
--

-- Dumped from database version PostgreSQL 17.5
-- Dumped by pgschema version 1.5.0
-- Dumped by pgschema version 1.5.1


--
Expand Down Expand Up @@ -139,7 +139,7 @@ CREATE TABLE IF NOT EXISTS film (
rental_rate numeric(4,2) DEFAULT 4.99 NOT NULL,
length smallint,
replacement_cost numeric(5,2) DEFAULT 19.99 NOT NULL,
rating mpaa_rating DEFAULT 'G',
rating mpaa_rating DEFAULT 'G'::mpaa_rating,
last_update timestamptz DEFAULT now() NOT NULL,
special_features text[],
fulltext tsvector NOT NULL,
Expand Down
Loading