Skip to content

[Feature]: Add naming validation for CHECK, UNIQUE, and PRIMARY KEY constraints #4

Description

@AlexeyShalaev

Problem statement

MigrationNamingMixin currently validates only indexes and foreign keys. PostgreSQL also creates named constraints that follow naming conventions but are not checked:

  • CHECK constraints — e.g. chk_orders_amount_positive
  • UNIQUE constraints — exist as standalone constraints (separate from unique indexes)
  • PRIMARY KEY constraints — e.g. pk_users (distinct from the _pkey index name)
  • EXCLUDE constraints — less common, but present in some schemas

Without validation, these can silently drift from the team's naming convention.

Proposed solution

Extend fetch_table_naming_results and validate_naming_results to collect and validate named constraints via Inspector.get_check_constraints(), Inspector.get_unique_constraints(), and Inspector.get_pk_constraint().

Add corresponding class variables to MigrationNamingMixin (and expose on MigrationTestBase):

allowed_check_prefixes: ClassVar[list[str]] = ["chk_"]
allowed_check_suffixes: ClassVar[list[str]] = []

allowed_uq_prefixes: ClassVar[list[str]] = ["uq_"]
allowed_uq_suffixes: ClassVar[list[str]] = []

allowed_pk_prefixes: ClassVar[list[str]] = ["pk_"]
allowed_pk_suffixes: ClassVar[list[str]] = ["_pkey"]

Scope

New feature — additive, fully backward-compatible (empty or sensible defaults for all new attributes).

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions