Files
LibraryAPI/migrations/versions/9d7a43ac5dfc_genres.py

46 lines
1.4 KiB
Python

"""genres
Revision ID: 9d7a43ac5dfc
Revises: d266fdc61e99
Create Date: 2025-06-25 11:24:30.229418
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
import sqlmodel
# revision identifiers, used by Alembic.
revision: str = '9d7a43ac5dfc'
down_revision: Union[str, None] = 'd266fdc61e99'
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('genre',
sa.Column('name', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
sa.Column('id', sa.Integer(), nullable=False),
sa.PrimaryKeyConstraint('id')
)
op.create_index(op.f('ix_genre_id'), 'genre', ['id'], unique=False)
op.create_table('genrebooklink',
sa.Column('genre_id', sa.Integer(), nullable=False),
sa.Column('book_id', sa.Integer(), nullable=False),
sa.ForeignKeyConstraint(['book_id'], ['book.id'], ),
sa.ForeignKeyConstraint(['genre_id'], ['genre.id'], ),
sa.PrimaryKeyConstraint('genre_id', 'book_id')
)
# ### end Alembic commands ###
def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('genrebooklink')
op.drop_index(op.f('ix_genre_id'), table_name='genre')
op.drop_table('genre')
# ### end Alembic commands ###