34 lines
1.0 KiB
Python
34 lines
1.0 KiB
Python
"""create table for fruits
|
|
Revision ID: 2c8e7d9f9e4b
|
|
Revises: 6d5cd4bae0c6
|
|
Create Date: 2023-05-25 12:34:56
|
|
|
|
"""
|
|
from alembic import op
|
|
import sqlalchemy as sa
|
|
from sqlalchemy.sql import func
|
|
import uuid
|
|
|
|
# revision identifiers, used by Alembic.
|
|
revision = '2c8e7d9f9e4b'
|
|
down_revision = '6d5cd4bae0c6'
|
|
branch_labels = None
|
|
depends_on = None
|
|
|
|
def upgrade():
|
|
table_name = "fruits"
|
|
|
|
op.create_table(
|
|
table_name,
|
|
sa.Column('id', sa.String(36), primary_key=True, default=lambda: str(uuid.uuid4())),
|
|
sa.Column('name', sa.String(), nullable=False, unique=True),
|
|
sa.Column('description', sa.String(), nullable=True),
|
|
sa.Column('created_at', sa.DateTime(), server_default=func.now()),
|
|
sa.Column('updated_at', sa.DateTime(), server_default=func.now(), onupdate=func.now())
|
|
)
|
|
op.create_index(op.f('ix_fruits_name'), table_name, ['name'], unique=True)
|
|
|
|
def downgrade():
|
|
table_name = "fruits"
|
|
op.drop_index(op.f('ix_fruits_name'), table_name=table_name)
|
|
op.drop_table(table_name) |