"""Add mirror-driven financial statement reporting configuration. Revision ID: 20260921_financial_statements Revises: f8aac1809dcd """ from alembic import op import sqlalchemy as sa revision = "20260921_financial_statements" down_revision = "f8aac1809dcd" branch_labels = None depends_on = None def upgrade() -> None: op.create_table( "accounting_financial_ledger_mappings", 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("client_id", sa.Integer(), sa.ForeignKey("clients.id", ondelete="CASCADE"), nullable=False), sa.Column("ledger_name", sa.String(length=255), nullable=False), sa.Column("statement_code", sa.String(length=20), nullable=False), sa.Column("schedule_code", sa.String(length=60), nullable=False), sa.Column("display_group", sa.String(length=160), nullable=False, server_default=""), 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.text("CURRENT_TIMESTAMP")), sa.Column("updated_at_utc", sa.DateTime(timezone=True), nullable=False, server_default=sa.text("CURRENT_TIMESTAMP")), sa.UniqueConstraint("tenant_id", "client_id", "ledger_name", name="uq_accounting_fs_mapping_client_ledger"), ) op.create_index("ix_accounting_financial_ledger_mappings_tenant_id", "accounting_financial_ledger_mappings", ["tenant_id"]) op.create_index("ix_accounting_financial_ledger_mappings_client_id", "accounting_financial_ledger_mappings", ["client_id"]) op.create_index("ix_accounting_financial_ledger_mappings_ledger_name", "accounting_financial_ledger_mappings", ["ledger_name"]) op.create_index("ix_accounting_financial_ledger_mappings_statement_code", "accounting_financial_ledger_mappings", ["statement_code"]) op.create_index("ix_accounting_financial_ledger_mappings_schedule_code", "accounting_financial_ledger_mappings", ["schedule_code"]) op.create_table( "accounting_partnership_profit_shares", 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("client_id", sa.Integer(), sa.ForeignKey("clients.id", ondelete="CASCADE"), nullable=False), sa.Column("financial_year", sa.String(length=7), nullable=False), sa.Column("partner_name", sa.String(length=200), nullable=False), sa.Column("profit_share_percent", sa.Numeric(7, 4), nullable=False, server_default="0"), sa.Column("target_ledger_name", sa.String(length=255), nullable=False, server_default=""), 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.text("CURRENT_TIMESTAMP")), sa.Column("updated_at_utc", sa.DateTime(timezone=True), nullable=False, server_default=sa.text("CURRENT_TIMESTAMP")), sa.UniqueConstraint("tenant_id", "client_id", "financial_year", "partner_name", name="uq_accounting_partner_share_client_fy_name"), ) op.create_index("ix_accounting_partnership_profit_shares_tenant_id", "accounting_partnership_profit_shares", ["tenant_id"]) op.create_index("ix_accounting_partnership_profit_shares_client_id", "accounting_partnership_profit_shares", ["client_id"]) op.create_index("ix_accounting_partnership_profit_shares_financial_year", "accounting_partnership_profit_shares", ["financial_year"]) def downgrade() -> None: op.drop_index("ix_accounting_partnership_profit_shares_financial_year", table_name="accounting_partnership_profit_shares") op.drop_index("ix_accounting_partnership_profit_shares_client_id", table_name="accounting_partnership_profit_shares") op.drop_index("ix_accounting_partnership_profit_shares_tenant_id", table_name="accounting_partnership_profit_shares") op.drop_table("accounting_partnership_profit_shares") op.drop_index("ix_accounting_financial_ledger_mappings_schedule_code", table_name="accounting_financial_ledger_mappings") op.drop_index("ix_accounting_financial_ledger_mappings_statement_code", table_name="accounting_financial_ledger_mappings") op.drop_index("ix_accounting_financial_ledger_mappings_ledger_name", table_name="accounting_financial_ledger_mappings") op.drop_index("ix_accounting_financial_ledger_mappings_client_id", table_name="accounting_financial_ledger_mappings") op.drop_index("ix_accounting_financial_ledger_mappings_tenant_id", table_name="accounting_financial_ledger_mappings") op.drop_table("accounting_financial_ledger_mappings")