Restructure into full project layout

This commit is contained in:
2026-06-16 23:06:16 -06:00
parent de4862b2d1
commit 57765496a6
74 changed files with 4441 additions and 3 deletions
View File
+52
View File
@@ -0,0 +1,52 @@
import asyncio
from logging.config import fileConfig
from sqlalchemy import pool
from sqlalchemy.engine import Connection
from sqlalchemy.ext.asyncio import async_engine_from_config
from alembic import context
from app.core.config import settings
from app.core.database import Base
import app.models # noqa: F401 — ensure all models are imported
config = context.config
config.set_main_option("sqlalchemy.url", settings.DATABASE_URL)
if config.config_file_name is not None:
fileConfig(config.config_file_name)
target_metadata = Base.metadata
def run_migrations_offline() -> None:
url = config.get_main_option("sqlalchemy.url")
context.configure(url=url, target_metadata=target_metadata, literal_binds=True)
with context.begin_transaction():
context.run_migrations()
def do_run_migrations(connection: Connection) -> None:
context.configure(connection=connection, target_metadata=target_metadata)
with context.begin_transaction():
context.run_migrations()
async def run_async_migrations() -> None:
connectable = async_engine_from_config(
config.get_section(config.config_ini_section, {}),
prefix="sqlalchemy.",
poolclass=pool.NullPool,
)
async with connectable.connect() as connection:
await connection.run_sync(do_run_migrations)
await connectable.dispose()
def run_migrations_online() -> None:
asyncio.run(run_async_migrations())
if context.is_offline_mode():
run_migrations_offline()
else:
run_migrations_online()
@@ -0,0 +1,95 @@
"""initial schema
Revision ID: 0001
Revises:
Create Date: 2024-01-01 00:00:00.000000
"""
from alembic import op
import sqlalchemy as sa
revision = '0001'
down_revision = None
branch_labels = None
depends_on = None
def upgrade() -> None:
op.create_table(
'users',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('email', sa.String(255), nullable=False),
sa.Column('hashed_password', sa.String(255), nullable=False),
sa.Column('display_name', sa.String(100), nullable=True),
sa.Column('role', sa.Enum('pending', 'approved', 'admin', name='userrole'), nullable=False, server_default='pending'),
sa.Column('is_active', sa.Boolean(), nullable=False, server_default='true'),
sa.Column('created_at', sa.DateTime(), nullable=False, server_default=sa.func.now()),
sa.Column('updated_at', sa.DateTime(), nullable=False, server_default=sa.func.now()),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('email'),
)
op.create_index('ix_users_email', 'users', ['email'])
op.create_table(
'decks',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('owner_id', sa.Integer(), nullable=False),
sa.Column('name', sa.String(200), nullable=False),
sa.Column('commander', sa.String(200), nullable=False),
sa.Column('description', sa.Text(), nullable=True),
sa.Column('mode', sa.Enum('generate', 'complete', 'cull', name='deckmode'), nullable=False),
sa.Column('playstyle', sa.String(100), nullable=True),
sa.Column('prefer_owned', sa.Boolean(), nullable=False, server_default='false'),
sa.Column('budget_enabled', sa.Boolean(), nullable=False, server_default='false'),
sa.Column('budget_amount', sa.Float(), nullable=True),
sa.Column('budget_scope', sa.String(20), nullable=False, server_default='purchase'),
sa.Column('ai_reasoning', sa.JSON(), nullable=True),
sa.Column('created_at', sa.DateTime(), nullable=False, server_default=sa.func.now()),
sa.Column('updated_at', sa.DateTime(), nullable=False, server_default=sa.func.now()),
sa.ForeignKeyConstraint(['owner_id'], ['users.id'], ondelete='CASCADE'),
sa.PrimaryKeyConstraint('id'),
)
op.create_index('ix_decks_owner_id', 'decks', ['owner_id'])
op.create_table(
'deck_cards',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('deck_id', sa.Integer(), nullable=False),
sa.Column('scryfall_id', sa.String(36), nullable=False),
sa.Column('card_name', sa.String(200), nullable=False),
sa.Column('slot', sa.Enum('creature', 'instant', 'sorcery', 'enchantment', 'artifact', 'planeswalker', 'land', 'battle', name='cardslot'), nullable=False),
sa.Column('quantity', sa.Integer(), nullable=False, server_default='1'),
sa.Column('is_owned', sa.Boolean(), nullable=False, server_default='false'),
sa.Column('is_commander', sa.Boolean(), nullable=False, server_default='false'),
sa.Column('ai_reasoning', sa.Text(), nullable=True),
sa.Column('scryfall_data', sa.JSON(), nullable=True),
sa.ForeignKeyConstraint(['deck_id'], ['decks.id'], ondelete='CASCADE'),
sa.PrimaryKeyConstraint('id'),
)
op.create_index('ix_deck_cards_deck_id', 'deck_cards', ['deck_id'])
op.create_table(
'user_collection',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('owner_id', sa.Integer(), nullable=False),
sa.Column('card_name', sa.String(200), nullable=False),
sa.Column('set_code', sa.String(10), nullable=False, server_default=''),
sa.Column('collector_number', sa.String(20), nullable=False, server_default=''),
sa.Column('quantity', sa.Integer(), nullable=False, server_default='0'),
sa.Column('foil_quantity', sa.Integer(), nullable=False, server_default='0'),
sa.Column('scryfall_id', sa.String(36), nullable=False, server_default=''),
sa.Column('scryfall_data', sa.JSON(), nullable=True),
sa.ForeignKeyConstraint(['owner_id'], ['users.id'], ondelete='CASCADE'),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('owner_id', 'scryfall_id', name='uq_owner_scryfall'),
)
op.create_index('ix_user_collection_owner_id', 'user_collection', ['owner_id'])
def downgrade() -> None:
op.drop_table('user_collection')
op.drop_table('deck_cards')
op.drop_table('decks')
op.drop_table('users')
op.execute("DROP TYPE IF EXISTS userrole")
op.execute("DROP TYPE IF EXISTS deckmode")
op.execute("DROP TYPE IF EXISTS cardslot")