animeinformationapi-rcbblj/alembic/versions/20231017_initial_tables.py
Automated Action 4d6c2e1778 Implement Anime Information API with FastAPI and SQLite
- Create project structure and dependencies
- Set up SQLAlchemy models for anime, genres, and their relationships
- Implement CRUD operations for all models
- Set up FastAPI endpoints for managing anime and genres
- Add health check endpoint
- Configure Alembic for database migrations
- Add data seeding capability
- Update README with project information
2025-05-17 21:37:16 +00:00

78 lines
2.9 KiB
Python

"""Initial tables
Revision ID: b57a40c2b63d
Revises:
Create Date: 2023-10-17 00:00:00.000000
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = 'b57a40c2b63d'
down_revision = None
branch_labels = None
depends_on = None
def upgrade() -> None:
# Create anime table
op.create_table(
'anime',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('title', sa.String(255), nullable=False),
sa.Column('alternative_titles', sa.String(500), nullable=True),
sa.Column('synopsis', sa.Text(), nullable=True),
sa.Column('episodes', sa.Integer(), nullable=True),
sa.Column('status', sa.String(50), nullable=True),
sa.Column('aired_from', sa.Date(), nullable=True),
sa.Column('aired_to', sa.Date(), nullable=True),
sa.Column('duration', sa.String(50), nullable=True),
sa.Column('rating', sa.String(50), nullable=True),
sa.Column('score', sa.Float(), nullable=True),
sa.Column('ranked', sa.Integer(), nullable=True),
sa.Column('popularity', sa.Integer(), nullable=True),
sa.Column('studio', sa.String(100), nullable=True),
sa.Column('source', sa.String(50), nullable=True),
sa.Column('image_url', sa.String(255), nullable=True),
sa.PrimaryKeyConstraint('id')
)
op.create_index(op.f('ix_anime_id'), 'anime', ['id'], unique=False)
op.create_index(op.f('ix_anime_title'), 'anime', ['title'], unique=False)
# Create genre table
op.create_table(
'genre',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('name', sa.String(50), nullable=False),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('name')
)
op.create_index(op.f('ix_genre_id'), 'genre', ['id'], unique=False)
op.create_index(op.f('ix_genre_name'), 'genre', ['name'], unique=False)
# Create anime_genre table for many-to-many relationship
op.create_table(
'animegenre',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('anime_id', sa.Integer(), nullable=False),
sa.Column('genre_id', sa.Integer(), nullable=False),
sa.ForeignKeyConstraint(['anime_id'], ['anime.id'], ondelete='CASCADE'),
sa.ForeignKeyConstraint(['genre_id'], ['genre.id'], ondelete='CASCADE'),
sa.PrimaryKeyConstraint('id')
)
op.create_index(op.f('ix_animegenre_id'), 'animegenre', ['id'], unique=False)
def downgrade() -> None:
op.drop_index(op.f('ix_animegenre_id'), table_name='animegenre')
op.drop_table('animegenre')
op.drop_index(op.f('ix_genre_name'), table_name='genre')
op.drop_index(op.f('ix_genre_id'), table_name='genre')
op.drop_table('genre')
op.drop_index(op.f('ix_anime_title'), table_name='anime')
op.drop_index(op.f('ix_anime_id'), table_name='anime')
op.drop_table('anime')