"""Initial migration Revision ID: 001 Revises: Create Date: 2024-01-01 00:00:00.000000 """ from alembic import op import sqlalchemy as sa # revision identifiers, used by Alembic. revision = "001" down_revision = None branch_labels = None depends_on = None def upgrade() -> None: # Create categories table op.create_table( "categories", sa.Column("id", sa.Integer(), nullable=False), sa.Column("name", sa.String(length=100), nullable=False), sa.Column("description", sa.Text()), sa.Column( "created_at", sa.DateTime(timezone=True), server_default=sa.text("CURRENT_TIMESTAMP"), ), sa.Column("updated_at", sa.DateTime(timezone=True)), sa.PrimaryKeyConstraint("id"), ) op.create_index(op.f("ix_categories_id"), "categories", ["id"], unique=False) op.create_index(op.f("ix_categories_name"), "categories", ["name"], unique=True) # Create suppliers table op.create_table( "suppliers", sa.Column("id", sa.Integer(), nullable=False), sa.Column("name", sa.String(length=200), nullable=False), sa.Column("contact_person", sa.String(length=100)), sa.Column("email", sa.String(length=100)), sa.Column("phone", sa.String(length=20)), sa.Column("address", sa.Text()), sa.Column( "created_at", sa.DateTime(timezone=True), server_default=sa.text("CURRENT_TIMESTAMP"), ), sa.Column("updated_at", sa.DateTime(timezone=True)), sa.PrimaryKeyConstraint("id"), ) op.create_index(op.f("ix_suppliers_id"), "suppliers", ["id"], unique=False) op.create_index(op.f("ix_suppliers_name"), "suppliers", ["name"], unique=True) # Create inventory_items table op.create_table( "inventory_items", sa.Column("id", sa.Integer(), nullable=False), sa.Column("name", sa.String(length=200), nullable=False), sa.Column("sku", sa.String(length=50), nullable=False), sa.Column("description", sa.Text()), sa.Column("category_id", sa.Integer()), sa.Column("supplier_id", sa.Integer()), sa.Column("quantity", sa.Integer(), default=0), sa.Column("min_quantity", sa.Integer(), default=0), sa.Column("unit_price", sa.Float(), nullable=False), sa.Column( "created_at", sa.DateTime(timezone=True), server_default=sa.text("CURRENT_TIMESTAMP"), ), sa.Column("updated_at", sa.DateTime(timezone=True)), sa.ForeignKeyConstraint(["category_id"], ["categories.id"]), sa.ForeignKeyConstraint(["supplier_id"], ["suppliers.id"]), sa.PrimaryKeyConstraint("id"), ) op.create_index( op.f("ix_inventory_items_id"), "inventory_items", ["id"], unique=False ) op.create_index( op.f("ix_inventory_items_name"), "inventory_items", ["name"], unique=False ) op.create_index( op.f("ix_inventory_items_sku"), "inventory_items", ["sku"], unique=True ) def downgrade() -> None: op.drop_index(op.f("ix_inventory_items_sku"), table_name="inventory_items") op.drop_index(op.f("ix_inventory_items_name"), table_name="inventory_items") op.drop_index(op.f("ix_inventory_items_id"), table_name="inventory_items") op.drop_table("inventory_items") op.drop_index(op.f("ix_suppliers_name"), table_name="suppliers") op.drop_index(op.f("ix_suppliers_id"), table_name="suppliers") op.drop_table("suppliers") op.drop_index(op.f("ix_categories_name"), table_name="categories") op.drop_index(op.f("ix_categories_id"), table_name="categories") op.drop_table("categories")