From 9529784fa288924817775f6db7ce6feff536a1c5 Mon Sep 17 00:00:00 2001 From: Michael Plunkett <5885605+michplunkett@users.noreply.github.com> Date: Fri, 28 Feb 2025 11:46:39 -0600 Subject: [PATCH] Format and lint `migrations` directory (#59) --- .pre-commit-config.yaml | 6 +-- app/migrations/env.py | 7 ++- ...7ed0_create_archives_store_until_column.py | 18 ++++--- ...24ec4b1_rename_sheets_last_archived_col.py | 21 +++++--- ...dd_new_service_account_email_column_to_.py | 13 +++-- ...21d2c96d8_add_sheet_id_to_archive_table.py | 34 +++++++------ ...45b_modify_archive_url_to_have_uuid_id_.py | 8 +-- ...vacuum_database_if_there_s_enough_space.py | 9 ++-- .../a23aaf3ae930_drop_active_column.py | 25 +++++++--- ...a012ec405b8_add_columns_to_groups_table.py | 49 ++++++++++++------- 10 files changed, 120 insertions(+), 70 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 5e1d2a8..edb6bcf 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,6 @@ repos: - repo: https://github.com/nbQA-dev/nbQA - rev: 1.8.5 + rev: 1.9.1 hooks: - id: nbqa-ruff args: @@ -17,7 +17,7 @@ repos: - --profile=black - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.4.0 + rev: v5.0.0 hooks: - id: trailing-whitespace - id: check-docstring-first @@ -49,7 +49,7 @@ repos: - id: python-no-log-warn - repo: https://github.com/PyCQA/isort - rev: 5.12.0 + rev: 6.0.1 hooks: - id: isort name: Run isort to sort imports diff --git a/app/migrations/env.py b/app/migrations/env.py index 1f579ab..54c1f48 100644 --- a/app/migrations/env.py +++ b/app/migrations/env.py @@ -9,11 +9,14 @@ from app.shared.settings import get_settings # this is the Alembic Config object, which provides # access to the values within the .ini file in use. config = context.config -config.set_main_option('sqlalchemy.url', get_settings().DATABASE_PATH) +config.set_main_option("sqlalchemy.url", get_settings().DATABASE_PATH) # Interpret the config file for Python logging. # This line sets up loggers basically. if config.config_file_name is not None: - fileConfig(config.config_file_name, disable_existing_loggers=False) # disable_existing_loggers prevents loguru disabling + # disable_existing_loggers prevents loguru disabling + fileConfig( + config.config_file_name, disable_existing_loggers=False + ) # add your model's MetaData object here # for 'autogenerate' support diff --git a/app/migrations/versions/02b2f6d17ed0_create_archives_store_until_column.py b/app/migrations/versions/02b2f6d17ed0_create_archives_store_until_column.py index 8642f2b..1bb5695 100644 --- a/app/migrations/versions/02b2f6d17ed0_create_archives_store_until_column.py +++ b/app/migrations/versions/02b2f6d17ed0_create_archives_store_until_column.py @@ -5,13 +5,14 @@ Revises: 1636724ec4b1 Create Date: 2025-02-08 15:22:20.392522 """ + import sqlalchemy as sa from alembic import op # revision identifiers, used by Alembic. -revision = '02b2f6d17ed0' -down_revision = '1636724ec4b1' +revision = "02b2f6d17ed0" +down_revision = "1636724ec4b1" branch_labels = None depends_on = None STORE_UNTIL_COL = "store_until" @@ -20,15 +21,20 @@ STORE_UNTIL_COL = "store_until" def upgrade() -> None: conn = op.get_bind() inspector = sa.inspect(conn) - columns = [col['name'] for col in inspector.get_columns('archives')] + columns = [col["name"] for col in inspector.get_columns("archives")] if STORE_UNTIL_COL not in columns: - op.add_column('archives', sa.Column(STORE_UNTIL_COL, sa.DateTime(), nullable=True, default=None)) + op.add_column( + "archives", + sa.Column( + STORE_UNTIL_COL, sa.DateTime(), nullable=True, default=None + ), + ) def downgrade() -> None: conn = op.get_bind() inspector = sa.inspect(conn) - columns = [col['name'] for col in inspector.get_columns('archives')] + columns = [col["name"] for col in inspector.get_columns("archives")] if STORE_UNTIL_COL in columns: - op.drop_column('archives', STORE_UNTIL_COL) + op.drop_column("archives", STORE_UNTIL_COL) diff --git a/app/migrations/versions/1636724ec4b1_rename_sheets_last_archived_col.py b/app/migrations/versions/1636724ec4b1_rename_sheets_last_archived_col.py index 324f75a..ad972fc 100644 --- a/app/migrations/versions/1636724ec4b1_rename_sheets_last_archived_col.py +++ b/app/migrations/versions/1636724ec4b1_rename_sheets_last_archived_col.py @@ -5,13 +5,14 @@ Revises: a23aaf3ae930 Create Date: 2025-02-05 19:19:01.984396 """ + import sqlalchemy as sa from alembic import op # revision identifiers, used by Alembic. -revision = '1636724ec4b1' -down_revision = 'a23aaf3ae930' +revision = "1636724ec4b1" +down_revision = "a23aaf3ae930" branch_labels = None depends_on = None @@ -19,14 +20,18 @@ depends_on = None def upgrade() -> None: conn = op.get_bind() inspector = sa.inspect(conn) - columns = [col['name'] for col in inspector.get_columns('sheets')] - if 'last_archived_at' in columns: - op.alter_column('sheets', 'last_archived_at', new_column_name='last_url_archived_at') + columns = [col["name"] for col in inspector.get_columns("sheets")] + if "last_archived_at" in columns: + op.alter_column( + "sheets", "last_archived_at", new_column_name="last_url_archived_at" + ) def downgrade() -> None: conn = op.get_bind() inspector = sa.inspect(conn) - columns = [col['name'] for col in inspector.get_columns('sheets')] - if 'last_url_archived_at' in columns: - op.alter_column('sheets', 'last_url_archived_at', new_column_name='last_archived_at') + columns = [col["name"] for col in inspector.get_columns("sheets")] + if "last_url_archived_at" in columns: + op.alter_column( + "sheets", "last_url_archived_at", new_column_name="last_archived_at" + ) diff --git a/app/migrations/versions/63ac79df4ad0_add_new_service_account_email_column_to_.py b/app/migrations/versions/63ac79df4ad0_add_new_service_account_email_column_to_.py index 572905d..0ea0b11 100644 --- a/app/migrations/versions/63ac79df4ad0_add_new_service_account_email_column_to_.py +++ b/app/migrations/versions/63ac79df4ad0_add_new_service_account_email_column_to_.py @@ -5,13 +5,14 @@ Revises: 02b2f6d17ed0 Create Date: 2025-02-11 21:53:23.293274 """ + import sqlalchemy as sa from alembic import op # revision identifiers, used by Alembic. -revision = '63ac79df4ad0' -down_revision = '02b2f6d17ed0' +revision = "63ac79df4ad0" +down_revision = "02b2f6d17ed0" branch_labels = None depends_on = None @@ -22,15 +23,17 @@ TABLE = "groups" def upgrade() -> None: conn = op.get_bind() inspector = sa.inspect(conn) - columns = [col['name'] for col in inspector.get_columns(TABLE)] + columns = [col["name"] for col in inspector.get_columns(TABLE)] if NEW_COL not in columns: - op.add_column(TABLE, sa.Column(NEW_COL, sa.String, nullable=True, default=None)) + op.add_column( + TABLE, sa.Column(NEW_COL, sa.String, nullable=True, default=None) + ) def downgrade() -> None: conn = op.get_bind() inspector = sa.inspect(conn) - columns = [col['name'] for col in inspector.get_columns(TABLE)] + columns = [col["name"] for col in inspector.get_columns(TABLE)] if NEW_COL in columns: op.drop_column(TABLE, NEW_COL) diff --git a/app/migrations/versions/89121d2c96d8_add_sheet_id_to_archive_table.py b/app/migrations/versions/89121d2c96d8_add_sheet_id_to_archive_table.py index 892e853..e34e06d 100644 --- a/app/migrations/versions/89121d2c96d8_add_sheet_id_to_archive_table.py +++ b/app/migrations/versions/89121d2c96d8_add_sheet_id_to_archive_table.py @@ -5,14 +5,14 @@ Revises: fa012ec405b8 Create Date: 2024-11-04 11:12:30.237299 """ + import sqlalchemy as sa from alembic import op -from sqlalchemy.engine.reflection import Inspector # revision identifiers, used by Alembic. -revision = '89121d2c96d8' -down_revision = 'fa012ec405b8' +revision = "89121d2c96d8" +down_revision = "fa012ec405b8" branch_labels = None depends_on = None @@ -20,23 +20,27 @@ depends_on = None def upgrade() -> None: conn = op.get_bind() inspector = sa.inspect(conn) - columns = [col['name'] for col in inspector.get_columns('archives')] + columns = [col["name"] for col in inspector.get_columns("archives")] - if 'sheet_id' not in columns: - with op.batch_alter_table('archives') as batch_op: - batch_op.add_column(sa.Column('sheet_id', sa.String(), nullable=True, default=None)) - batch_op.create_foreign_key('fk_sheet_id', 'sheets', ['sheet_id'], ['id']) + if "sheet_id" not in columns: + with op.batch_alter_table("archives") as batch_op: + batch_op.add_column( + sa.Column("sheet_id", sa.String(), nullable=True, default=None) + ) + batch_op.create_foreign_key( + "fk_sheet_id", "sheets", ["sheet_id"], ["id"] + ) def downgrade() -> None: conn = op.get_bind() inspector = sa.inspect(conn) - foreign_keys = [fk['name'] for fk in inspector.get_foreign_keys('archives')] - columns = [col['name'] for col in inspector.get_columns('archives')] + foreign_keys = [fk["name"] for fk in inspector.get_foreign_keys("archives")] + columns = [col["name"] for col in inspector.get_columns("archives")] - with op.batch_alter_table('archives') as batch_op: - if 'fk_sheet_id' in foreign_keys: - batch_op.drop_constraint('fk_sheet_id', type_='foreignkey') + with op.batch_alter_table("archives") as batch_op: + if "fk_sheet_id" in foreign_keys: + batch_op.drop_constraint("fk_sheet_id", type_="foreignkey") - if 'sheet_id' in columns: - batch_op.drop_column('sheet_id') + if "sheet_id" in columns: + batch_op.drop_column("sheet_id") diff --git a/app/migrations/versions/9369a264945b_modify_archive_url_to_have_uuid_id_.py b/app/migrations/versions/9369a264945b_modify_archive_url_to_have_uuid_id_.py index bdfe474..1f7f348 100644 --- a/app/migrations/versions/9369a264945b_modify_archive_url_to_have_uuid_id_.py +++ b/app/migrations/versions/9369a264945b_modify_archive_url_to_have_uuid_id_.py @@ -5,11 +5,12 @@ Revises: Create Date: 2023-12-20 17:24:59.320691 """ + from alembic import op # revision identifiers, used by Alembic. -revision = '9369a264945b' +revision = "9369a264945b" down_revision = None branch_labels = None depends_on = None @@ -19,10 +20,11 @@ def upgrade() -> None: # since the primary key constraint is not named, we have to recreate it first with op.batch_alter_table("archive_urls") as batch_op: batch_op.create_primary_key("pk_url", ["url"]) - batch_op.drop_constraint("pk_url", type_='primary') + batch_op.drop_constraint("pk_url", type_="primary") batch_op.create_primary_key("pk_url_archive_id", ["url", "archive_id"]) + def downgrade() -> None: with op.batch_alter_table("archive_urls") as batch_op: - batch_op.drop_constraint("pk_url_archive_id", type_='primary') + batch_op.drop_constraint("pk_url_archive_id", type_="primary") batch_op.create_primary_key("url", ["url"]) diff --git a/app/migrations/versions/93a611e4c066_vacuum_database_if_there_s_enough_space.py b/app/migrations/versions/93a611e4c066_vacuum_database_if_there_s_enough_space.py index 6b8d8d2..b099f59 100644 --- a/app/migrations/versions/93a611e4c066_vacuum_database_if_there_s_enough_space.py +++ b/app/migrations/versions/93a611e4c066_vacuum_database_if_there_s_enough_space.py @@ -5,12 +5,13 @@ Revises: 9369a264945b Create Date: 2023-12-20 18:33:27.132566 """ + from alembic import op # revision identifiers, used by Alembic. -revision = '93a611e4c066' -down_revision = '9369a264945b' +revision = "93a611e4c066" +down_revision = "9369a264945b" branch_labels = None depends_on = None @@ -20,7 +21,9 @@ def upgrade() -> None: with op.get_context().autocommit_block(): op.execute("VACUUM") except Exception as e: - print("Unable to run vacuum, maybe there's not enough disk space. it should be 2x the size of the database") + print( + "Unable to run vacuum, maybe there's not enough disk space. it should be 2x the size of the database" + ) print(e) diff --git a/app/migrations/versions/a23aaf3ae930_drop_active_column.py b/app/migrations/versions/a23aaf3ae930_drop_active_column.py index ebc85e7..aa8f97b 100644 --- a/app/migrations/versions/a23aaf3ae930_drop_active_column.py +++ b/app/migrations/versions/a23aaf3ae930_drop_active_column.py @@ -5,13 +5,14 @@ Revises: 89121d2c96d8 Create Date: 2025-02-04 12:19:20.753570 """ + import sqlalchemy as sa from alembic import op # revision identifiers, used by Alembic. -revision = 'a23aaf3ae930' -down_revision = '89121d2c96d8' +revision = "a23aaf3ae930" +down_revision = "89121d2c96d8" branch_labels = None depends_on = None @@ -19,16 +20,24 @@ depends_on = None def upgrade() -> None: conn = op.get_bind() inspector = sa.inspect(conn) - columns = [col['name'] for col in inspector.get_columns('users')] + columns = [col["name"] for col in inspector.get_columns("users")] - if 'is_active' in columns: - op.drop_column('users', 'is_active') + if "is_active" in columns: + op.drop_column("users", "is_active") def downgrade() -> None: conn = op.get_bind() inspector = sa.inspect(conn) - columns = [col['name'] for col in inspector.get_columns('users')] + columns = [col["name"] for col in inspector.get_columns("users")] - if 'is_active' not in columns: - op.add_column('users', sa.Column('is_active', sa.Boolean(), nullable=False, server_default=sa.false())) + if "is_active" not in columns: + op.add_column( + "users", + sa.Column( + "is_active", + sa.Boolean(), + nullable=False, + server_default=sa.false(), + ), + ) diff --git a/app/migrations/versions/fa012ec405b8_add_columns_to_groups_table.py b/app/migrations/versions/fa012ec405b8_add_columns_to_groups_table.py index c3169c3..f5cbcaa 100644 --- a/app/migrations/versions/fa012ec405b8_add_columns_to_groups_table.py +++ b/app/migrations/versions/fa012ec405b8_add_columns_to_groups_table.py @@ -5,14 +5,14 @@ Revises: 93a611e4c066 Create Date: 2024-10-31 09:36:50.360710 """ + import sqlalchemy as sa from alembic import op -from sqlalchemy.engine.reflection import Inspector # revision identifiers, used by Alembic. -revision = 'fa012ec405b8' -down_revision = '93a611e4c066' +revision = "fa012ec405b8" +down_revision = "93a611e4c066" branch_labels = None depends_on = None @@ -20,26 +20,41 @@ depends_on = None def upgrade() -> None: conn = op.get_bind() inspector = sa.inspect(conn) - columns = [col['name'] for col in inspector.get_columns('groups')] + columns = [col["name"] for col in inspector.get_columns("groups")] - if 'description' not in columns: - op.add_column('groups', sa.Column('description', sa.String(), nullable=True)) - if 'orchestrator' not in columns: - op.add_column('groups', sa.Column('orchestrator', sa.String(), nullable=True)) - if 'orchestrator_sheet' not in columns: - op.add_column('groups', sa.Column('orchestrator_sheet', sa.String(), nullable=True)) - if 'permissions' not in columns: - op.add_column('groups', sa.Column('permissions', sa.JSON(), nullable=True)) - if 'domains' not in columns: - op.add_column('groups', sa.Column('domains', sa.JSON(), nullable=True)) + if "description" not in columns: + op.add_column( + "groups", sa.Column("description", sa.String(), nullable=True) + ) + if "orchestrator" not in columns: + op.add_column( + "groups", sa.Column("orchestrator", sa.String(), nullable=True) + ) + if "orchestrator_sheet" not in columns: + op.add_column( + "groups", + sa.Column("orchestrator_sheet", sa.String(), nullable=True), + ) + if "permissions" not in columns: + op.add_column( + "groups", sa.Column("permissions", sa.JSON(), nullable=True) + ) + if "domains" not in columns: + op.add_column("groups", sa.Column("domains", sa.JSON(), nullable=True)) def downgrade() -> None: conn = op.get_bind() inspector = sa.inspect(conn) - columns = [col['name'] for col in inspector.get_columns('groups')] + columns = [col["name"] for col in inspector.get_columns("groups")] - column_names = ['description', 'orchestrator', 'orchestrator_sheet', 'permissions', 'domains'] + column_names = [ + "description", + "orchestrator", + "orchestrator_sheet", + "permissions", + "domains", + ] for column_name in column_names: if column_name in columns: - op.drop_column('groups', column_name) + op.drop_column("groups", column_name)