
- Add proper model relationships for better querying - Implement character model and endpoints for managing anime characters - Add advanced filtering options (year, score range, source, studio, etc.) - Add statistics endpoint for analyzing anime collection - Include pagination metadata for easier navigation - Create Alembic migration for the new character model - Update README with new features and documentation
47 lines
1.6 KiB
Python
47 lines
1.6 KiB
Python
"""Add character model
|
|
|
|
Revision ID: c57a40c2b63e
|
|
Revises: b57a40c2b63d
|
|
Create Date: 2023-10-18 00:00:00.000000
|
|
|
|
"""
|
|
from alembic import op
|
|
import sqlalchemy as sa
|
|
|
|
|
|
# revision identifiers, used by Alembic.
|
|
revision = 'c57a40c2b63e'
|
|
down_revision = 'b57a40c2b63d'
|
|
branch_labels = None
|
|
depends_on = None
|
|
|
|
|
|
def upgrade() -> None:
|
|
# Create character table
|
|
op.create_table(
|
|
'character',
|
|
sa.Column('id', sa.Integer(), nullable=False),
|
|
sa.Column('name', sa.String(255), nullable=False),
|
|
sa.Column('role', sa.String(50), nullable=True),
|
|
sa.Column('description', sa.Text(), nullable=True),
|
|
sa.Column('voice_actor', sa.String(255), nullable=True),
|
|
sa.Column('image_url', sa.String(255), nullable=True),
|
|
sa.Column('anime_id', sa.Integer(), nullable=False),
|
|
sa.ForeignKeyConstraint(['anime_id'], ['anime.id'], ondelete='CASCADE'),
|
|
sa.PrimaryKeyConstraint('id')
|
|
)
|
|
op.create_index(op.f('ix_character_id'), 'character', ['id'], unique=False)
|
|
op.create_index(op.f('ix_character_name'), 'character', ['name'], unique=False)
|
|
|
|
# Add unique constraint to anime_genre table (if not already present)
|
|
op.create_unique_constraint('uix_anime_genre', 'animegenre', ['anime_id', 'genre_id'])
|
|
|
|
|
|
def downgrade() -> None:
|
|
# Drop the character table
|
|
op.drop_index(op.f('ix_character_name'), table_name='character')
|
|
op.drop_index(op.f('ix_character_id'), table_name='character')
|
|
op.drop_table('character')
|
|
|
|
# Drop unique constraint from anime_genre
|
|
op.drop_constraint('uix_anime_genre', 'animegenre', type_='unique') |