Black formater

This commit is contained in:
Sebastiaan
2025-05-24 11:03:54 +02:00
parent ad27420688
commit c1442f430e
7 changed files with 144 additions and 88 deletions

View File

@@ -19,7 +19,7 @@ fileConfig(config.config_file_name)
# target_metadata = None # target_metadata = None
from app.models.base import BaseSQLModel # noqa from app.models.base import BaseSQLModel # noqa
from app.core.config import settings # noqa from app.core.config import settings # noqa
target_metadata = BaseSQLModel.metadata target_metadata = BaseSQLModel.metadata

View File

@@ -5,33 +5,32 @@ Revises: d98dd8ec85a3
Create Date: 2024-07-31 22:24:34.447891 Create Date: 2024-07-31 22:24:34.447891
""" """
from alembic import op from alembic import op
import sqlalchemy as sa import sqlalchemy as sa
import sqlmodel.sql.sqltypes import sqlmodel.sql.sqltypes
# revision identifiers, used by Alembic. # revision identifiers, used by Alembic.
revision = '1a31ce608336' revision = "1a31ce608336"
down_revision = 'd98dd8ec85a3' down_revision = "d98dd8ec85a3"
branch_labels = None branch_labels = None
depends_on = None depends_on = None
def upgrade(): def upgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
op.alter_column('item', 'owner_id', op.alter_column("item", "owner_id", existing_type=sa.UUID(), nullable=False)
existing_type=sa.UUID(), op.drop_constraint("item_owner_id_fkey", "item", type_="foreignkey")
nullable=False) op.create_foreign_key(
op.drop_constraint('item_owner_id_fkey', 'item', type_='foreignkey') None, "item", "user", ["owner_id"], ["id"], ondelete="CASCADE"
op.create_foreign_key(None, 'item', 'user', ['owner_id'], ['id'], ondelete='CASCADE') )
# ### end Alembic commands ### # ### end Alembic commands ###
def downgrade(): def downgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
op.drop_constraint(None, 'item', type_='foreignkey') op.drop_constraint(None, "item", type_="foreignkey")
op.create_foreign_key('item_owner_id_fkey', 'item', 'user', ['owner_id'], ['id']) op.create_foreign_key("item_owner_id_fkey", "item", "user", ["owner_id"], ["id"])
op.alter_column('item', 'owner_id', op.alter_column("item", "owner_id", existing_type=sa.UUID(), nullable=True)
existing_type=sa.UUID(),
nullable=True)
# ### end Alembic commands ### # ### end Alembic commands ###

View File

@@ -5,65 +5,90 @@ Revises: e2412789c190
Create Date: 2024-06-17 14:42:44.639457 Create Date: 2024-06-17 14:42:44.639457
""" """
from alembic import op from alembic import op
import sqlalchemy as sa import sqlalchemy as sa
import sqlmodel.sql.sqltypes import sqlmodel.sql.sqltypes
# revision identifiers, used by Alembic. # revision identifiers, used by Alembic.
revision = '9c0a54914c78' revision = "9c0a54914c78"
down_revision = 'e2412789c190' down_revision = "e2412789c190"
branch_labels = None branch_labels = None
depends_on = None depends_on = None
def upgrade(): def upgrade():
# Adjust the length of the email field in the User table # Adjust the length of the email field in the User table
op.alter_column('user', 'email', op.alter_column(
existing_type=sa.String(), "user",
type_=sa.String(length=255), "email",
existing_nullable=False) existing_type=sa.String(),
type_=sa.String(length=255),
existing_nullable=False,
)
# Adjust the length of the full_name field in the User table # Adjust the length of the full_name field in the User table
op.alter_column('user', 'full_name', op.alter_column(
existing_type=sa.String(), "user",
type_=sa.String(length=255), "full_name",
existing_nullable=True) existing_type=sa.String(),
type_=sa.String(length=255),
existing_nullable=True,
)
# Adjust the length of the title field in the Item table # Adjust the length of the title field in the Item table
op.alter_column('item', 'title', op.alter_column(
existing_type=sa.String(), "item",
type_=sa.String(length=255), "title",
existing_nullable=False) existing_type=sa.String(),
type_=sa.String(length=255),
existing_nullable=False,
)
# Adjust the length of the description field in the Item table # Adjust the length of the description field in the Item table
op.alter_column('item', 'description', op.alter_column(
existing_type=sa.String(), "item",
type_=sa.String(length=255), "description",
existing_nullable=True) existing_type=sa.String(),
type_=sa.String(length=255),
existing_nullable=True,
)
def downgrade(): def downgrade():
# Revert the length of the email field in the User table # Revert the length of the email field in the User table
op.alter_column('user', 'email', op.alter_column(
existing_type=sa.String(length=255), "user",
type_=sa.String(), "email",
existing_nullable=False) existing_type=sa.String(length=255),
type_=sa.String(),
existing_nullable=False,
)
# Revert the length of the full_name field in the User table # Revert the length of the full_name field in the User table
op.alter_column('user', 'full_name', op.alter_column(
existing_type=sa.String(length=255), "user",
type_=sa.String(), "full_name",
existing_nullable=True) existing_type=sa.String(length=255),
type_=sa.String(),
existing_nullable=True,
)
# Revert the length of the title field in the Item table # Revert the length of the title field in the Item table
op.alter_column('item', 'title', op.alter_column(
existing_type=sa.String(length=255), "item",
type_=sa.String(), "title",
existing_nullable=False) existing_type=sa.String(length=255),
type_=sa.String(),
existing_nullable=False,
)
# Revert the length of the description field in the Item table # Revert the length of the description field in the Item table
op.alter_column('item', 'description', op.alter_column(
existing_type=sa.String(length=255), "item",
type_=sa.String(), "description",
existing_nullable=True) existing_type=sa.String(length=255),
type_=sa.String(),
existing_nullable=True,
)

View File

@@ -5,6 +5,7 @@ Revises: 9c0a54914c78
Create Date: 2024-07-19 04:08:04.000976 Create Date: 2024-07-19 04:08:04.000976
""" """
from alembic import op from alembic import op
import sqlalchemy as sa import sqlalchemy as sa
import sqlmodel.sql.sqltypes import sqlmodel.sql.sqltypes
@@ -12,8 +13,8 @@ from sqlalchemy.dialects import postgresql
# revision identifiers, used by Alembic. # revision identifiers, used by Alembic.
revision = 'd98dd8ec85a3' revision = "d98dd8ec85a3"
down_revision = '9c0a54914c78' down_revision = "9c0a54914c78"
branch_labels = None branch_labels = None
depends_on = None depends_on = None
@@ -23,68 +24,97 @@ def upgrade():
op.execute('CREATE EXTENSION IF NOT EXISTS "uuid-ossp"') op.execute('CREATE EXTENSION IF NOT EXISTS "uuid-ossp"')
# Create a new UUID column with a default UUID value # Create a new UUID column with a default UUID value
op.add_column('user', sa.Column('new_id', postgresql.UUID(as_uuid=True), default=sa.text('uuid_generate_v4()'))) op.add_column(
op.add_column('item', sa.Column('new_id', postgresql.UUID(as_uuid=True), default=sa.text('uuid_generate_v4()'))) "user",
op.add_column('item', sa.Column('new_owner_id', postgresql.UUID(as_uuid=True), nullable=True)) sa.Column(
"new_id",
postgresql.UUID(as_uuid=True),
default=sa.text("uuid_generate_v4()"),
),
)
op.add_column(
"item",
sa.Column(
"new_id",
postgresql.UUID(as_uuid=True),
default=sa.text("uuid_generate_v4()"),
),
)
op.add_column(
"item", sa.Column("new_owner_id", postgresql.UUID(as_uuid=True), nullable=True)
)
# Populate the new columns with UUIDs # Populate the new columns with UUIDs
op.execute('UPDATE "user" SET new_id = uuid_generate_v4()') op.execute('UPDATE "user" SET new_id = uuid_generate_v4()')
op.execute('UPDATE item SET new_id = uuid_generate_v4()') op.execute("UPDATE item SET new_id = uuid_generate_v4()")
op.execute('UPDATE item SET new_owner_id = (SELECT new_id FROM "user" WHERE "user".id = item.owner_id)') op.execute(
'UPDATE item SET new_owner_id = (SELECT new_id FROM "user" WHERE "user".id = item.owner_id)'
)
# Set the new_id as not nullable # Set the new_id as not nullable
op.alter_column('user', 'new_id', nullable=False) op.alter_column("user", "new_id", nullable=False)
op.alter_column('item', 'new_id', nullable=False) op.alter_column("item", "new_id", nullable=False)
# Drop old columns and rename new columns # Drop old columns and rename new columns
op.drop_constraint('item_owner_id_fkey', 'item', type_='foreignkey') op.drop_constraint("item_owner_id_fkey", "item", type_="foreignkey")
op.drop_column('item', 'owner_id') op.drop_column("item", "owner_id")
op.alter_column('item', 'new_owner_id', new_column_name='owner_id') op.alter_column("item", "new_owner_id", new_column_name="owner_id")
op.drop_column('user', 'id') op.drop_column("user", "id")
op.alter_column('user', 'new_id', new_column_name='id') op.alter_column("user", "new_id", new_column_name="id")
op.drop_column('item', 'id') op.drop_column("item", "id")
op.alter_column('item', 'new_id', new_column_name='id') op.alter_column("item", "new_id", new_column_name="id")
# Create primary key constraint # Create primary key constraint
op.create_primary_key('user_pkey', 'user', ['id']) op.create_primary_key("user_pkey", "user", ["id"])
op.create_primary_key('item_pkey', 'item', ['id']) op.create_primary_key("item_pkey", "item", ["id"])
# Recreate foreign key constraint # Recreate foreign key constraint
op.create_foreign_key('item_owner_id_fkey', 'item', 'user', ['owner_id'], ['id']) op.create_foreign_key("item_owner_id_fkey", "item", "user", ["owner_id"], ["id"])
def downgrade(): def downgrade():
# Reverse the upgrade process # Reverse the upgrade process
op.add_column('user', sa.Column('old_id', sa.Integer, autoincrement=True)) op.add_column("user", sa.Column("old_id", sa.Integer, autoincrement=True))
op.add_column('item', sa.Column('old_id', sa.Integer, autoincrement=True)) op.add_column("item", sa.Column("old_id", sa.Integer, autoincrement=True))
op.add_column('item', sa.Column('old_owner_id', sa.Integer, nullable=True)) op.add_column("item", sa.Column("old_owner_id", sa.Integer, nullable=True))
# Populate the old columns with default values # Populate the old columns with default values
# Generate sequences for the integer IDs if not exist # Generate sequences for the integer IDs if not exist
op.execute('CREATE SEQUENCE IF NOT EXISTS user_id_seq AS INTEGER OWNED BY "user".old_id') op.execute(
op.execute('CREATE SEQUENCE IF NOT EXISTS item_id_seq AS INTEGER OWNED BY item.old_id') 'CREATE SEQUENCE IF NOT EXISTS user_id_seq AS INTEGER OWNED BY "user".old_id'
)
op.execute(
"CREATE SEQUENCE IF NOT EXISTS item_id_seq AS INTEGER OWNED BY item.old_id"
)
op.execute('SELECT setval(\'user_id_seq\', COALESCE((SELECT MAX(old_id) + 1 FROM "user"), 1), false)') op.execute(
op.execute('SELECT setval(\'item_id_seq\', COALESCE((SELECT MAX(old_id) + 1 FROM item), 1), false)') "SELECT setval('user_id_seq', COALESCE((SELECT MAX(old_id) + 1 FROM \"user\"), 1), false)"
)
op.execute(
"SELECT setval('item_id_seq', COALESCE((SELECT MAX(old_id) + 1 FROM item), 1), false)"
)
op.execute('UPDATE "user" SET old_id = nextval(\'user_id_seq\')') op.execute("UPDATE \"user\" SET old_id = nextval('user_id_seq')")
op.execute('UPDATE item SET old_id = nextval(\'item_id_seq\'), old_owner_id = (SELECT old_id FROM "user" WHERE "user".id = item.owner_id)') op.execute(
'UPDATE item SET old_id = nextval(\'item_id_seq\'), old_owner_id = (SELECT old_id FROM "user" WHERE "user".id = item.owner_id)'
)
# Drop new columns and rename old columns back # Drop new columns and rename old columns back
op.drop_constraint('item_owner_id_fkey', 'item', type_='foreignkey') op.drop_constraint("item_owner_id_fkey", "item", type_="foreignkey")
op.drop_column('item', 'owner_id') op.drop_column("item", "owner_id")
op.alter_column('item', 'old_owner_id', new_column_name='owner_id') op.alter_column("item", "old_owner_id", new_column_name="owner_id")
op.drop_column('user', 'id') op.drop_column("user", "id")
op.alter_column('user', 'old_id', new_column_name='id') op.alter_column("user", "old_id", new_column_name="id")
op.drop_column('item', 'id') op.drop_column("item", "id")
op.alter_column('item', 'old_id', new_column_name='id') op.alter_column("item", "old_id", new_column_name="id")
# Create primary key constraint # Create primary key constraint
op.create_primary_key('user_pkey', 'user', ['id']) op.create_primary_key("user_pkey", "user", ["id"])
op.create_primary_key('item_pkey', 'item', ['id']) op.create_primary_key("item_pkey", "item", ["id"])
# Recreate foreign key constraint # Recreate foreign key constraint
op.create_foreign_key('item_owner_id_fkey', 'item', 'user', ['owner_id'], ['id']) op.create_foreign_key("item_owner_id_fkey", "item", "user", ["owner_id"], ["id"])

View File

@@ -5,6 +5,7 @@ Revises:
Create Date: 2023-11-24 22:55:43.195942 Create Date: 2023-11-24 22:55:43.195942
""" """
import sqlalchemy as sa import sqlalchemy as sa
import sqlmodel.sql.sqltypes import sqlmodel.sql.sqltypes
from alembic import op from alembic import op

View File

@@ -38,9 +38,9 @@ class Settings(BaseSettings):
FRONTEND_HOST: str = "http://localhost:5173" FRONTEND_HOST: str = "http://localhost:5173"
ENVIRONMENT: Literal["local", "staging", "production"] = "local" ENVIRONMENT: Literal["local", "staging", "production"] = "local"
BACKEND_CORS_ORIGINS: Annotated[ BACKEND_CORS_ORIGINS: Annotated[list[AnyUrl] | str, BeforeValidator(parse_cors)] = (
list[AnyUrl] | str, BeforeValidator(parse_cors) []
] = [] )
@computed_field # type: ignore[prop-decorator] @computed_field # type: ignore[prop-decorator]
@property @property

View File

@@ -9,6 +9,7 @@ from uuid import UUID as RowId
class BaseSQLModel(SQLModel): class BaseSQLModel(SQLModel):
pass pass
# endregion # endregion
# region Generic message ####################################################### # region Generic message #######################################################