From e17e570d8a7b58a45c951426567347b74680e895 Mon Sep 17 00:00:00 2001 From: Backend IM Bot Date: Fri, 28 Mar 2025 13:18:32 +0000 Subject: [PATCH] Add migration for Book --- .../20250328_131816_12047daf_create_book.py | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 alembic/versions/20250328_131816_12047daf_create_book.py diff --git a/alembic/versions/20250328_131816_12047daf_create_book.py b/alembic/versions/20250328_131816_12047daf_create_book.py new file mode 100644 index 0000000..27992b3 --- /dev/null +++ b/alembic/versions/20250328_131816_12047daf_create_book.py @@ -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') \ No newline at end of file