feat: Add migration for Book table
This commit is contained in:
parent
3f302f2a17
commit
81300c5768
37
alembic/versions/20250411_060400_8a1edfcc_create_book.py
Normal file
37
alembic/versions/20250411_060400_8a1edfcc_create_book.py
Normal file
@ -0,0 +1,37 @@
|
||||
"""create table for Book
|
||||
Revision ID: 2c8d38ab6ec3
|
||||
Revises: 0001
|
||||
Create Date: 2023-05-29 11:47:18.851105
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
from sqlalchemy.dialects.postgresql import UUID
|
||||
import uuid
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = '2c8d38ab6ec3'
|
||||
down_revision = '0001'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade():
|
||||
op.create_table(
|
||||
'books',
|
||||
sa.Column('id', UUID(as_uuid=True), primary_key=True, default=uuid.uuid4),
|
||||
sa.Column('title', sa.String(), nullable=False),
|
||||
sa.Column('author', sa.String(), nullable=False),
|
||||
sa.Column('description', sa.String(), nullable=True),
|
||||
sa.Column('page_count', sa.Integer(), nullable=False),
|
||||
sa.Column('genre', sa.String(), nullable=False),
|
||||
sa.Column('publisher_id', UUID(as_uuid=True), nullable=False),
|
||||
sa.Column('created_at', sa.DateTime(), server_default=sa.func.now()),
|
||||
sa.Column('updated_at', sa.DateTime(), server_default=sa.func.now(), onupdate=sa.func.now()),
|
||||
sa.ForeignKeyConstraint(['publisher_id'], ['publishers.id'], ),
|
||||
)
|
||||
|
||||
|
||||
def downgrade():
|
||||
op.drop_table('books')
|
Loading…
x
Reference in New Issue
Block a user