"""Phase 4 standard accounting classification taxonomy. Revision ID: 20260822_accounting_taxonomy_p4 Revises: 20260822_business_profile_p3 """ from alembic import op import sqlalchemy as sa revision = "20260822_accounting_taxonomy_p4" down_revision = "20260822_business_profile_p3" branch_labels = None depends_on = None def upgrade() -> None: op.create_table( "accounting_natures", sa.Column("id", sa.Integer(), primary_key=True, autoincrement=True), sa.Column("tenant_id", sa.Integer(), sa.ForeignKey("tenants.id", ondelete="CASCADE"), nullable=False), sa.Column("code", sa.String(length=80), nullable=False), sa.Column("name", sa.String(length=160), nullable=False), sa.Column("parent_code", sa.String(length=80), nullable=True), sa.Column("classification_group", sa.String(length=40), nullable=False), sa.Column("capital_revenue", sa.String(length=20), nullable=False, server_default="revenue"), sa.Column("description", sa.Text(), nullable=True), sa.Column("sort_order", sa.Integer(), nullable=False, server_default="100"), sa.Column("is_posting_nature", sa.Boolean(), nullable=False, server_default=sa.true()), sa.Column("is_active", sa.Boolean(), nullable=False, server_default=sa.true()), sa.Column("is_system_defined", sa.Boolean(), nullable=False, server_default=sa.true()), sa.Column("created_by_user_id", sa.Integer(), sa.ForeignKey("users.id", ondelete="SET NULL"), nullable=True), sa.Column("updated_by_user_id", sa.Integer(), sa.ForeignKey("users.id", ondelete="SET NULL"), nullable=True), sa.Column("created_at_utc", sa.DateTime(timezone=True), nullable=False, server_default=sa.func.now()), sa.Column("updated_at_utc", sa.DateTime(timezone=True), nullable=False, server_default=sa.func.now()), sa.UniqueConstraint("tenant_id", "code", name="uq_accounting_natures_tenant_code"), ) op.create_index("ix_accounting_natures_tenant_id", "accounting_natures", ["tenant_id"]) op.create_index("ix_accounting_natures_code", "accounting_natures", ["code"]) op.create_index("ix_accounting_natures_name", "accounting_natures", ["name"]) op.create_index("ix_accounting_natures_parent_code", "accounting_natures", ["parent_code"]) op.create_index("ix_accounting_natures_classification_group", "accounting_natures", ["classification_group"]) op.create_index("ix_accounting_natures_capital_revenue", "accounting_natures", ["capital_revenue"]) op.create_index("ix_accounting_natures_is_posting_nature", "accounting_natures", ["is_posting_nature"]) op.create_index("ix_accounting_natures_is_active", "accounting_natures", ["is_active"]) def downgrade() -> None: op.drop_index("ix_accounting_natures_is_active", table_name="accounting_natures") op.drop_index("ix_accounting_natures_is_posting_nature", table_name="accounting_natures") op.drop_index("ix_accounting_natures_capital_revenue", table_name="accounting_natures") op.drop_index("ix_accounting_natures_classification_group", table_name="accounting_natures") op.drop_index("ix_accounting_natures_parent_code", table_name="accounting_natures") op.drop_index("ix_accounting_natures_name", table_name="accounting_natures") op.drop_index("ix_accounting_natures_code", table_name="accounting_natures") op.drop_index("ix_accounting_natures_tenant_id", table_name="accounting_natures") op.drop_table("accounting_natures")