Add migration for Book
This commit is contained in:
parent
bd1a14a143
commit
e17e570d8a
40
alembic/versions/20250328_131816_12047daf_create_book.py
Normal file
40
alembic/versions/20250328_131816_12047daf_create_book.py
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
"""create books table
|
||||||
|
|
||||||
|
Revision ID: b2c3d4e5f6g7
|
||||||
|
Revises: 0001
|
||||||
|
Create Date: 2024-03-26 12:00:00.000000
|
||||||
|
"""
|
||||||
|
from alembic import op
|
||||||
|
import sqlalchemy as sa
|
||||||
|
from sqlalchemy.dialects.postgresql import UUID
|
||||||
|
from sqlalchemy.sql import func
|
||||||
|
|
||||||
|
# revision identifiers
|
||||||
|
revision = 'b2c3d4e5f6g7'
|
||||||
|
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),
|
||||||
|
sa.Column('title', sa.String(), nullable=False),
|
||||||
|
sa.Column('author', sa.String(), nullable=False),
|
||||||
|
sa.Column('description', sa.Text(), nullable=True),
|
||||||
|
sa.Column('isbn', sa.String(), nullable=False),
|
||||||
|
sa.Column('publication_year', sa.Integer(), nullable=True),
|
||||||
|
sa.Column('publisher', sa.String(), nullable=True),
|
||||||
|
sa.Column('page_count', sa.Integer(), nullable=True),
|
||||||
|
sa.Column('language', sa.String(), nullable=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())
|
||||||
|
)
|
||||||
|
|
||||||
|
op.create_index(op.f('ix_books_title'), 'books', ['title'], unique=False)
|
||||||
|
op.create_unique_constraint('uq_books_isbn', 'books', ['isbn'])
|
||||||
|
|
||||||
|
def downgrade():
|
||||||
|
op.drop_index(op.f('ix_books_title'), table_name='books')
|
||||||
|
op.drop_constraint('uq_books_isbn', 'books', type_='unique')
|
||||||
|
op.drop_table('books')
|
Loading…
x
Reference in New Issue
Block a user