Format and lint migrations directory (#59)

This commit is contained in:
Michael Plunkett
2025-02-28 11:46:39 -06:00
committed by GitHub
parent d575b6f9af
commit 9529784fa2
10 changed files with 120 additions and 70 deletions

View File

@@ -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

View File

@@ -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)

View File

@@ -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"
)

View File

@@ -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)

View File

@@ -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")

View File

@@ -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"])

View File

@@ -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)

View File

@@ -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(),
),
)

View File

@@ -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)