From b6c7f083af0a5c01f2c3efa0d802444c54379bcc Mon Sep 17 00:00:00 2001 From: Backend IM Bot Date: Thu, 27 Mar 2025 20:05:09 +0000 Subject: [PATCH] Add migration for Person --- .../20250327_200454_4e64b72e_create_person.py | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 alembic/versions/20250327_200454_4e64b72e_create_person.py diff --git a/alembic/versions/20250327_200454_4e64b72e_create_person.py b/alembic/versions/20250327_200454_4e64b72e_create_person.py new file mode 100644 index 0000000..afb5749 --- /dev/null +++ b/alembic/versions/20250327_200454_4e64b72e_create_person.py @@ -0,0 +1,39 @@ +"""create persons table + +Revision ID: b2c3d4e5f6g7 +Revises: +Create Date: 2024-01-10 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( + 'persons', + sa.Column('id', sa.String(), primary_key=True, default=lambda: str(uuid.uuid4())), + sa.Column('first_name', sa.String(), nullable=False), + sa.Column('last_name', sa.String(), nullable=False), + sa.Column('age', sa.Integer(), nullable=False), + sa.Column('email', sa.String(), unique=True), + sa.Column('phone', sa.String()), + sa.Column('is_active', 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_persons_age', 'persons', ['age']) + op.create_index('ix_persons_email', 'persons', ['email'], unique=True) + +def downgrade(): + op.drop_index('ix_persons_email', 'persons') + op.drop_index('ix_persons_age', 'persons') + op.drop_table('persons') \ No newline at end of file