sqlalchemy / sqlalchemy/alembic

new hook: compare_identity_default

Open
#821 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

autogenerate - detection use case
Dominant language
Python
Stars
4.4k
Forks
375
PR merge metrics
No merged PRs in 30d

Description

Question:

short of monkey-patching

# alembic.autogenerate.compare
def _compare_identity_default(...):

what is "the proper way" to override the logic of compare_identity_default?

https://github.com/sqlalchemy/alembic/blob/master/alembic/autogenerate/compare.py#L1022

The use case:

  • database is multi-master postgres cluster
  • ddl from alembic is replicated to all nodes via pglogical https://www.2ndquadrant.com/en/resources/pglogical/
  • replication process on each cluster node intercepts ddl to inject its own per-node values for minvalue, maxvalue to ensure unique non-overlapping sequence range for identity for every node, like so:
-- this is substituted by ddl intercept on every node by values provided by postgres.conf file
... GENERATED ... AS IDENTITY ( ... MINVALUE %s  MAXVALUE %s  ... )

The requirement:

  • have alembic ignore minvalue, maxvalue mismatch for identity columns
  • during subsequent invocations of alembic revision --autogenerate
  • depending on: database name, table name, column name

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with alembic/autogenerate/compare.py around compare_identity_default and review how alembic revision --autogenerate invokes it. Determine an extension point that can use the database, table, and column names to ignore identity minvalue and maxvalue differences; done means the behavior is configurable without monkey-patching and works for subsequent autogeneration runs.

Written by the indexing model from the issue text.

Assessment

Tech stack
postgresql, python
Domain
databases
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.