pgschema icon indicating copy to clipboard operation
pgschema copied to clipboard

`plan`/`apply` truncates enum type names longer than 25 chars in generated column definitions (regression in 1.12.1)

Open saosebastiao opened this issue 4 months ago • 1 comments

Summary

In pgschema 1.12.1, the generated CREATE TABLE statement truncates a column's enum type name to 25 characters whenever the type name is longer than 25 chars. The CREATE TYPE is emitted correctly with the full name, but the column that references it uses the truncated name, so applying the plan fails with type "<truncated>" does not exist (SQLSTATE 42704).

This is a regression: the same schema plans and applies cleanly in 1.12.0.

Version

Version: 1.12.1@2d864f32 darwin/arm64 2026-07-29 02:58:41

(also reproducible on the linux/amd64 1.12.1 build). Last-good version: 1.12.0@62d09975.

Minimal reproduction

Desired-state file main.sql for a schema repro:

CREATE TYPE enum_deal_area_market_info_type AS ENUM ('inbound', 'outbound');

CREATE TABLE deal_area_market_info (
    id bigint GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
    type enum_deal_area_market_info_type NOT NULL
);

enum_deal_area_market_info_type is 31 characters — well under PostgreSQL's 63-byte NAMEDATALEN limit.

Apply against an empty schema:

pgschema apply --host ... --db ... --user ... --schema repro --file main.sql --auto-approve \
  --plan-host ... --plan-db ... --plan-user ...

1.12.1 — FAILS

Generated SQL (abridged):

CREATE TYPE enum_deal_area_market_info_type AS ENUM (
    'inbound',
    'outbound'
);

CREATE TABLE IF NOT EXISTS deal_area_market_info (
    ...
    type enum_deal_area_market_inf NOT NULL,   -- <-- truncated to 25 chars
    ...
);
Error: failed to execute concatenated statements in group 1:
ERROR: type "enum_deal_area_market_inf" does not exist (SQLSTATE 42704)

1.12.0 — SUCCEEDS

    type enum_deal_area_market_info_type NOT NULL,   -- full name, correct
Applying changes...
Changes applied successfully!

Characterization

The truncation is a fixed cut at 25 characters applied to the bare type reference in a column definition. Every enum type name > 25 chars is affected; names ≤ 25 chars are fine. Observed across several unrelated types:

Real type name (len) Rendered in column def
enum_deal_area_market_info_type (31) enum_deal_area_market_inf (25)
enum_ssr_legal_rf_certifier_emails_certifier_type (49) enum_ssr_legal_rf_certifi (25)
enum_tmus_license_county_details_action (39) enum_tmus_license_county_ (25)
enum_ssr_renewal_permanent_discontinuation (43) enum_ssr_renewal_permanen (25)
utopia_email_category_enum (26) utopia_email_category_enu (25)
enum_deals_status (17) enum_deals_status (not truncated)
utopia_email_type_enum (22) utopia_email_type_enum (not truncated)

Notably, the same type name used in a cast (e.g. a column DEFAULT like ... DEFAULT 'x'::utopia_email_category_enum) is rendered in full — only the bare column type reference is truncated. This suggests the defect is isolated to the code path that formats a column's type name in CREATE TABLE, not the general type-name formatter.

Impact

Any schema with an enum type name longer than 25 characters cannot be applied by 1.12.1 (the plan is generated with a dangling type reference). This blocks plan review workflows too, since the emitted DDL is invalid.

Expected

The column's type reference should render the full type name (enum_deal_area_market_info_type), matching the emitted CREATE TYPE and 1.12.0 behavior.

saosebastiao avatar Aug 04 '26 21:08 saosebastiao

Already fixed in 325d20ac

tianzhou avatar Aug 05 '26 05:08 tianzhou