Skip to content

feat(constraints): add prefix_tablename option to Unique and Check constraints (#1437) - #1441

Open
shadialhasan wants to merge 1 commit into
piccolo-orm:masterfrom
shadialhasan:feat-prefix-unique-constraint-tablename
Open

shadialhasan wants to merge 1 commit into
piccolo-orm:masterfrom
shadialhasan:feat-prefix-unique-constraint-tablename

Conversation

@shadialhasan

Copy link
Copy Markdown

Description

Fixes #1437

When multiple Table classes inherit a Unique constraint from a common mixin, PostgreSQL requires index names across tables in the same schema to be unique; attempting to apply identical index names results in
elation already exists.

This PR implements the solution suggested in #1437:

  1. Adds prefix_tablename: bool = False to Constraint, Unique, and Check constraints.
  2. Ensures Constraint instances (and their column references) are safely cloned in TableMetaclass so inheriting tables do not mutate each other's constraint metadata.
  3. Automatically prefixes index and constraint names with {tablename}_{base_name} when prefix_tablename=True is enabled.
  4. Preserves 100% backward compatibility: prefix_tablename defaults to False, leaving existing constraint naming and migration serialized params byte-identical unless explicitly enabled.
  5. Adds comprehensive unit test coverage in ests/table/test_constraints.py and ests/apps/migrations/auto/test_schema_differ.py.

Checks

  • Tested with SQLite & schema differ test suites
  • Passed lake8 lint checks
  • Fully backward-compatible

…nstraints (piccolo-orm#1437)

- Support prefix_tablename=True in Unique and Check constraints
- Ensure Constraint instances and columns are safely copied in TableMetaclass for mixin inheritance
- Automatically prefix index and constraint names with table name to prevent PostgreSQL collisions across mixin consumers
- Add full test coverage in test_constraints.py and test_schema_differ.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Prefix Unqiue constraint's index name with the table name

1 participant