Files
DungeonsDragons/backend/app/alembic/versions/48846ed4fe0e_initial_schema.py
T
Thorsten f37dc9fa76 Add Phase 1 MVP: D&D text-adventure server
FastAPI + Postgres backend with fastapi-users auth, games/characters
CRUD, and a WebSocket chat endpoint where an x.ai Grok DM narrates
play, rolls dice, and maintains character sheets via tool calls.
React + Tailwind frontend covers registration/login, game list and
creation, participation-code join flow, character viewer, and a
real-time chat session view. Docker Compose skeleton (Postgres +
backend) included; Caddy/frontend container wiring is deferred to
the deploy milestone.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-08-31 18:43:08 +02:00

109 lines
5.2 KiB
Python

"""initial schema
Revision ID: 48846ed4fe0e
Revises:
Create Date: 2026-08-31 15:38:20.816566
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
import fastapi_users_db_sqlalchemy
from sqlalchemy.dialects import postgresql
# revision identifiers, used by Alembic.
revision: str = '48846ed4fe0e'
down_revision: Union[str, None] = None
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('users',
sa.Column('name', sa.String(length=100), nullable=False),
sa.Column('id', fastapi_users_db_sqlalchemy.generics.GUID(), nullable=False),
sa.Column('email', sa.String(length=320), nullable=False),
sa.Column('hashed_password', sa.String(length=1024), nullable=False),
sa.Column('is_active', sa.Boolean(), nullable=False),
sa.Column('is_superuser', sa.Boolean(), nullable=False),
sa.Column('is_verified', sa.Boolean(), nullable=False),
sa.PrimaryKeyConstraint('id')
)
op.create_index(op.f('ix_users_email'), 'users', ['email'], unique=True)
op.create_table('characters',
sa.Column('id', sa.UUID(), nullable=False),
sa.Column('owner_id', sa.UUID(), nullable=False),
sa.Column('name', sa.String(length=200), nullable=False),
sa.Column('race', sa.String(length=100), nullable=True),
sa.Column('char_class', sa.String(length=100), nullable=True),
sa.Column('level', sa.Integer(), nullable=False),
sa.Column('stats', postgresql.JSONB(astext_type=sa.Text()), nullable=False),
sa.Column('description', sa.Text(), nullable=False),
sa.Column('created_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False),
sa.Column('updated_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False),
sa.ForeignKeyConstraint(['owner_id'], ['users.id'], ),
sa.PrimaryKeyConstraint('id')
)
op.create_index(op.f('ix_characters_owner_id'), 'characters', ['owner_id'], unique=False)
op.create_table('games',
sa.Column('id', sa.UUID(), nullable=False),
sa.Column('name', sa.String(length=200), nullable=False),
sa.Column('description', sa.Text(), nullable=False),
sa.Column('creator_id', sa.UUID(), nullable=False),
sa.Column('participation_code', sa.String(length=16), nullable=False),
sa.Column('created_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False),
sa.ForeignKeyConstraint(['creator_id'], ['users.id'], ),
sa.PrimaryKeyConstraint('id')
)
op.create_index(op.f('ix_games_created_at'), 'games', ['created_at'], unique=False)
op.create_index(op.f('ix_games_participation_code'), 'games', ['participation_code'], unique=True)
op.create_table('game_participants',
sa.Column('id', sa.UUID(), nullable=False),
sa.Column('game_id', sa.UUID(), nullable=False),
sa.Column('user_id', sa.UUID(), nullable=False),
sa.Column('character_id', sa.UUID(), nullable=True),
sa.Column('joined_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False),
sa.ForeignKeyConstraint(['character_id'], ['characters.id'], ),
sa.ForeignKeyConstraint(['game_id'], ['games.id'], ondelete='CASCADE'),
sa.ForeignKeyConstraint(['user_id'], ['users.id'], ),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('game_id', 'user_id', name='uq_game_participant')
)
op.create_index(op.f('ix_game_participants_game_id'), 'game_participants', ['game_id'], unique=False)
op.create_table('messages',
sa.Column('id', sa.BigInteger(), autoincrement=True, nullable=False),
sa.Column('game_id', sa.UUID(), nullable=False),
sa.Column('sender_type', sa.Text(), nullable=False),
sa.Column('user_id', sa.UUID(), nullable=True),
sa.Column('character_id', sa.UUID(), nullable=True),
sa.Column('content', sa.Text(), nullable=False),
sa.Column('created_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False),
sa.CheckConstraint("sender_type IN ('player', 'dm', 'system')", name='ck_message_sender_type'),
sa.ForeignKeyConstraint(['character_id'], ['characters.id'], ),
sa.ForeignKeyConstraint(['game_id'], ['games.id'], ondelete='CASCADE'),
sa.ForeignKeyConstraint(['user_id'], ['users.id'], ),
sa.PrimaryKeyConstraint('id')
)
op.create_index(op.f('ix_messages_created_at'), 'messages', ['created_at'], unique=False)
op.create_index(op.f('ix_messages_game_id'), 'messages', ['game_id'], unique=False)
# ### end Alembic commands ###
def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.drop_index(op.f('ix_messages_game_id'), table_name='messages')
op.drop_index(op.f('ix_messages_created_at'), table_name='messages')
op.drop_table('messages')
op.drop_index(op.f('ix_game_participants_game_id'), table_name='game_participants')
op.drop_table('game_participants')
op.drop_index(op.f('ix_games_participation_code'), table_name='games')
op.drop_index(op.f('ix_games_created_at'), table_name='games')
op.drop_table('games')
op.drop_index(op.f('ix_characters_owner_id'), table_name='characters')
op.drop_table('characters')
op.drop_index(op.f('ix_users_email'), table_name='users')
op.drop_table('users')
# ### end Alembic commands ###