From 748a0d9d156e3ab1d424097f73e1a747ec813b84 Mon Sep 17 00:00:00 2001 From: Dmitriy Lunev Date: Mon, 16 Sep 2024 15:51:47 +0300 Subject: [PATCH] v1.1.0: add new alembic migration name generator. --- pyproject.toml | 2 +- .../alembic/migration_numbering.py | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 1849d08..fc2dfdb 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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" diff --git a/sqlalchemy_dev_utils/alembic/migration_numbering.py b/sqlalchemy_dev_utils/alembic/migration_numbering.py index 41808c1..77bac5a 100644 --- a/sqlalchemy_dev_utils/alembic/migration_numbering.py +++ b/sqlalchemy_dev_utils/alembic/migration_numbering.py @@ -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}"