From 99e227633c36967c10df2ac0738452d1dce08b33 Mon Sep 17 00:00:00 2001 From: Pavel Kirilin Date: Mon, 27 Jan 2025 12:14:19 +0100 Subject: [PATCH] Fixed ruff integration with alembic. --- .../template/{{cookiecutter.project_name}}/alembic.ini | 10 ++++------ .../db_ormar/migrations/script.py.mako | 8 +++++--- .../versions/2021-08-16-16-53_819cbf6e030b.py | 5 ++--- .../versions/2021-08-16-16-55_2b7380507a71.py | 4 ++-- .../db_sa/migrations/script.py.mako | 8 +++++--- .../versions/2021-08-16-16-53_819cbf6e030b.py | 2 ++ .../versions/2021-08-16-16-55_2b7380507a71.py | 4 ++-- 7 files changed, 22 insertions(+), 19 deletions(-) diff --git a/fastapi_template/template/{{cookiecutter.project_name}}/alembic.ini b/fastapi_template/template/{{cookiecutter.project_name}}/alembic.ini index 588ed017..dc44727e 100644 --- a/fastapi_template/template/{{cookiecutter.project_name}}/alembic.ini +++ b/fastapi_template/template/{{cookiecutter.project_name}}/alembic.ini @@ -7,16 +7,14 @@ output_encoding = utf-8 [post_write_hooks] -hooks = black,autoflake,isort +hooks = black,ruff black.type = console_scripts black.entrypoint = black -autoflake.type = console_scripts -autoflake.entrypoint = autoflake - -isort.type = console_scripts -isort.entrypoint = isort +ruff.type = exec +ruff.executable = ruff +ruff.options = check --fix REVISION_SCRIPT_FILENAME --ignore N999 # Logging configuration [loggers] diff --git a/fastapi_template/template/{{cookiecutter.project_name}}/{{cookiecutter.project_name}}/db_ormar/migrations/script.py.mako b/fastapi_template/template/{{cookiecutter.project_name}}/{{cookiecutter.project_name}}/db_ormar/migrations/script.py.mako index 55df2863..395e017f 100644 --- a/fastapi_template/template/{{cookiecutter.project_name}}/{{cookiecutter.project_name}}/db_ormar/migrations/script.py.mako +++ b/fastapi_template/template/{{cookiecutter.project_name}}/{{cookiecutter.project_name}}/db_ormar/migrations/script.py.mako @@ -1,4 +1,4 @@ -"""${message} +"""${message}${"." if not message.endswith(".") else ""} Revision ID: ${up_revision} Revises: ${down_revision | comma,n} @@ -17,8 +17,10 @@ depends_on = ${repr(depends_on)} def upgrade() -> None: - ${upgrades if upgrades else "pass"} + """Run the migration.""" + ${upgrades if upgrades else ""} def downgrade() -> None: - ${downgrades if downgrades else "pass"} + """Undo the migration.""" + ${downgrades if downgrades else ""} diff --git a/fastapi_template/template/{{cookiecutter.project_name}}/{{cookiecutter.project_name}}/db_ormar/migrations/versions/2021-08-16-16-53_819cbf6e030b.py b/fastapi_template/template/{{cookiecutter.project_name}}/{{cookiecutter.project_name}}/db_ormar/migrations/versions/2021-08-16-16-53_819cbf6e030b.py index 3b22742e..6a09969e 100644 --- a/fastapi_template/template/{{cookiecutter.project_name}}/{{cookiecutter.project_name}}/db_ormar/migrations/versions/2021-08-16-16-53_819cbf6e030b.py +++ b/fastapi_template/template/{{cookiecutter.project_name}}/{{cookiecutter.project_name}}/db_ormar/migrations/versions/2021-08-16-16-53_819cbf6e030b.py @@ -6,7 +6,6 @@ """ - # revision identifiers, used by Alembic. revision = "819cbf6e030b" down_revision = None @@ -15,8 +14,8 @@ def upgrade() -> None: - pass + """Run the upgrade migrations.""" def downgrade() -> None: - pass + """Run the downgrade migrations.""" diff --git a/fastapi_template/template/{{cookiecutter.project_name}}/{{cookiecutter.project_name}}/db_ormar/migrations/versions/2021-08-16-16-55_2b7380507a71.py b/fastapi_template/template/{{cookiecutter.project_name}}/{{cookiecutter.project_name}}/db_ormar/migrations/versions/2021-08-16-16-55_2b7380507a71.py index f06778fe..a0dc51c5 100644 --- a/fastapi_template/template/{{cookiecutter.project_name}}/{{cookiecutter.project_name}}/db_ormar/migrations/versions/2021-08-16-16-55_2b7380507a71.py +++ b/fastapi_template/template/{{cookiecutter.project_name}}/{{cookiecutter.project_name}}/db_ormar/migrations/versions/2021-08-16-16-55_2b7380507a71.py @@ -16,7 +16,7 @@ def upgrade() -> None: - # ### commands auto generated by Alembic - please adjust! ### + """Run the upgrade migrations.""" op.create_table( "dummy_model", sa.Column("id", sa.Integer(), nullable=False), @@ -27,6 +27,6 @@ def upgrade() -> None: def downgrade() -> None: - # ### commands auto generated by Alembic - please adjust! ### + """Run the downgrade migrations.""" op.drop_table("dummy_model") # ### end Alembic commands ### diff --git a/fastapi_template/template/{{cookiecutter.project_name}}/{{cookiecutter.project_name}}/db_sa/migrations/script.py.mako b/fastapi_template/template/{{cookiecutter.project_name}}/{{cookiecutter.project_name}}/db_sa/migrations/script.py.mako index 55df2863..395e017f 100644 --- a/fastapi_template/template/{{cookiecutter.project_name}}/{{cookiecutter.project_name}}/db_sa/migrations/script.py.mako +++ b/fastapi_template/template/{{cookiecutter.project_name}}/{{cookiecutter.project_name}}/db_sa/migrations/script.py.mako @@ -1,4 +1,4 @@ -"""${message} +"""${message}${"." if not message.endswith(".") else ""} Revision ID: ${up_revision} Revises: ${down_revision | comma,n} @@ -17,8 +17,10 @@ depends_on = ${repr(depends_on)} def upgrade() -> None: - ${upgrades if upgrades else "pass"} + """Run the migration.""" + ${upgrades if upgrades else ""} def downgrade() -> None: - ${downgrades if downgrades else "pass"} + """Undo the migration.""" + ${downgrades if downgrades else ""} diff --git a/fastapi_template/template/{{cookiecutter.project_name}}/{{cookiecutter.project_name}}/db_sa/migrations/versions/2021-08-16-16-53_819cbf6e030b.py b/fastapi_template/template/{{cookiecutter.project_name}}/{{cookiecutter.project_name}}/db_sa/migrations/versions/2021-08-16-16-53_819cbf6e030b.py index 3b22742e..8b05bbe8 100644 --- a/fastapi_template/template/{{cookiecutter.project_name}}/{{cookiecutter.project_name}}/db_sa/migrations/versions/2021-08-16-16-53_819cbf6e030b.py +++ b/fastapi_template/template/{{cookiecutter.project_name}}/{{cookiecutter.project_name}}/db_sa/migrations/versions/2021-08-16-16-53_819cbf6e030b.py @@ -15,8 +15,10 @@ def upgrade() -> None: + """Run the upgrade migrations.""" pass def downgrade() -> None: + """Run the downgrade migrations.""" pass diff --git a/fastapi_template/template/{{cookiecutter.project_name}}/{{cookiecutter.project_name}}/db_sa/migrations/versions/2021-08-16-16-55_2b7380507a71.py b/fastapi_template/template/{{cookiecutter.project_name}}/{{cookiecutter.project_name}}/db_sa/migrations/versions/2021-08-16-16-55_2b7380507a71.py index 53cfe129..f531a432 100644 --- a/fastapi_template/template/{{cookiecutter.project_name}}/{{cookiecutter.project_name}}/db_sa/migrations/versions/2021-08-16-16-55_2b7380507a71.py +++ b/fastapi_template/template/{{cookiecutter.project_name}}/{{cookiecutter.project_name}}/db_sa/migrations/versions/2021-08-16-16-55_2b7380507a71.py @@ -16,7 +16,7 @@ def upgrade() -> None: - # ### commands auto generated by Alembic - please adjust! ### + """Run the upgrade migrations.""" op.create_table( "dummy_model", sa.Column("id", sa.Integer(), autoincrement=True, nullable=False), @@ -27,6 +27,6 @@ def upgrade() -> None: def downgrade() -> None: - # ### commands auto generated by Alembic - please adjust! ### + """Run the downgrade migrations.""" op.drop_table("dummy_model") # ### end Alembic commands ###