Add migration for Book
This commit is contained in:
parent
fa41f9d565
commit
edff293d0f
35
alembic/versions/20250326_225559_3c4a4673_create_book.py
Normal file
35
alembic/versions/20250326_225559_3c4a4673_create_book.py
Normal file
@ -0,0 +1,35 @@
|
||||
"""create books table
|
||||
|
||||
Revision ID: 1234567890ab
|
||||
Revises:
|
||||
Create Date: 2023-05-25 10:00:00.000000
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
from sqlalchemy.sql import func
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = '1234567890ab'
|
||||
down_revision = None
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade():
|
||||
op.create_table(
|
||||
'books',
|
||||
sa.Column('id', sa.Integer, primary_key=True, index=True),
|
||||
sa.Column('title', sa.String, nullable=False),
|
||||
sa.Column('author', sa.String, nullable=False, index=True),
|
||||
sa.Column('description', sa.String, nullable=True),
|
||||
sa.Column('page_count', sa.Integer, nullable=False),
|
||||
sa.Column('published_date', sa.DateTime, nullable=False),
|
||||
sa.Column('isbn', sa.String, unique=True, nullable=False, index=True),
|
||||
sa.Column('created_at', sa.DateTime, server_default=func.now()),
|
||||
sa.Column('updated_at', sa.DateTime, server_default=func.now(), onupdate=func.now())
|
||||
)
|
||||
|
||||
|
||||
def downgrade():
|
||||
op.drop_table('books')
|
Loading…
x
Reference in New Issue
Block a user