constr_name_unif
constr_name_unif · Uniforms the names of constraints on base tables.
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 100529 | constr_name_unif | constr_name_unif | 1.0.1 | ADMIN | MIT | SQL |
PostgreSQL · 10, 11, 12, 13, 14, 15, 16, 17, 18
Usage
Sources:
constr_name_unif inventories and renames PostgreSQL constraints according to a configurable convention. Use it to standardize names on existing base tables, but treat every rename operation as schema-changing DDL that can affect migrations and tools which refer to constraint names.
Core Workflow
Install the pure-SQL extension, inspect the constraints and available patterns, and only then run the desired rename function:
The bundled postgresql_default pattern uses suffixes such as pkey and fkey. The bundled snake_case_with_short_prefix pattern uses prefixes such as pk and fk. Custom patterns can choose a delimiter, prefix or suffix placement, and abbreviations for each supported constraint type.
Important Objects
get_all_constraints()andget_all_constraints_in_schema(text)return the current constraint inventory; overloads can restrict results by constraint type.get_all_patterns()lists configured naming patterns.add_pattern(...)anddelete_pattern(...)manage naming patterns.add_to_abbreviated_tables(...),empty_abbreviated_tables(), andget_abbreviated_tables()manage table-name abbreviations.rename_all_constraints(text)and its schema/type-specific variants issueALTER TABLE ... RENAME CONSTRAINTstatements for primary-key, foreign-key, check, unique, and exclusion constraints.
Operational Notes
Generated identifiers are kept within PostgreSQL’s 63-byte identifier limit and collisions are disambiguated. Foreign-key names also incorporate the referenced table. The extension has no dry-run API that reports every proposed target name, so first capture the inventory, test the selected pattern on a copy, and run the rename in a controlled transaction with suitable DDL privileges. Review application migrations, monitoring, and administrative scripts for hard-coded constraint names before committing.