Skip to content

Commit

Permalink
v1.1.0: add new alembic migration name generator.
Browse files Browse the repository at this point in the history
  • Loading branch information
ALittleMoron committed Sep 16, 2024
1 parent f90c11f commit 748a0d9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ dev = [

[project]
name = "sqlalchemy_dev_utils"
version = "1.0.1"
version = "1.1.0"
description = "My sqlalchemy utils package, that I use in my projects."
authors = [{ name = "Dmitriy Lunev", email = "dima.lunev14@gmail.com" }]
requires-python = ">=3.11"
Expand Down
17 changes: 17 additions & 0 deletions sqlalchemy_dev_utils/alembic/migration_numbering.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,20 @@ def process_revision_directives_datetime_order(
rev_id = get_utc_now().strftime("%Y%m%d%H%M%S")
for directive in directives:
directive.rev_id = rev_id


def process_revision_directives_small_int_order(
context: "MigrationContext", # noqa: F401
revision: "RevisionType", # noqa: F401
directives: list["MigrationScript"],
) -> None:
"""``process_revision_directives`` function for alembic migration file naming.
Use in content.configure method:
https://alembic.sqlalchemy.org/en/latest/api/runtime.html#alembic.runtime.environment.EnvironmentContext.configure
"""
migration_script = directives[0]
head_revision = context.get_current_revision()
new_rev_id = int(head_revision) + 1 if head_revision else 1
migration_script.rev_id = f"{new_rev_id:04}"

0 comments on commit 748a0d9

Please sign in to comment.