Add migration for Book
This commit is contained in:
parent
2c35902086
commit
b0eb4cc121
41
alembic/versions/20250327_102938_14f5c13f_create_book.py
Normal file
41
alembic/versions/20250327_102938_14f5c13f_create_book.py
Normal file
@ -0,0 +1,41 @@
|
||||
"""create books table
|
||||
|
||||
Revision ID: b2c3d4e5f6g7
|
||||
Revises:
|
||||
Create Date: 2023-12-14 10:00:00.000000
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
from sqlalchemy.sql import func
|
||||
import uuid
|
||||
|
||||
# revision identifiers
|
||||
revision = 'b2c3d4e5f6g7'
|
||||
down_revision = None
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
def upgrade():
|
||||
op.create_table(
|
||||
'books',
|
||||
sa.Column('id', sa.String(), primary_key=True, default=lambda: str(uuid.uuid4())),
|
||||
sa.Column('title', sa.String(), nullable=False),
|
||||
sa.Column('author', sa.String(), nullable=False),
|
||||
sa.Column('isbn', sa.String(), nullable=False),
|
||||
sa.Column('description', sa.String()),
|
||||
sa.Column('publication_year', sa.Integer()),
|
||||
sa.Column('pages', sa.Integer()),
|
||||
sa.Column('publisher', sa.String()),
|
||||
sa.Column('is_available', sa.Boolean(), default=True),
|
||||
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.PrimaryKeyConstraint('id')
|
||||
)
|
||||
|
||||
op.create_index('ix_books_title', 'books', ['title'])
|
||||
op.create_index('ix_books_isbn', 'books', ['isbn'], unique=True)
|
||||
|
||||
def downgrade():
|
||||
op.drop_index('ix_books_isbn', 'books')
|
||||
op.drop_index('ix_books_title', 'books')
|
||||
op.drop_table('books')
|
Loading…
x
Reference in New Issue
Block a user