Add Phase 20 stored bank reuse and richer reconciliation
This commit is contained in:
+147
@@ -0,0 +1,147 @@
|
||||
"""Phase 20 Bank Analyzer stored-statement reuse + richer reconciliation.
|
||||
|
||||
Revision ID: 20260824_bank_analyzer_reuse_p20
|
||||
Revises: 20260824_bank_reconciliation_p19
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
revision = "20260824_bank_analyzer_reuse_p20"
|
||||
down_revision = "20260824_bank_reconciliation_p19"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade():
|
||||
op.add_column(
|
||||
"bank_statement_analysis_jobs",
|
||||
sa.Column("stored_source_versions_json", sa.Text(), nullable=True),
|
||||
)
|
||||
op.add_column(
|
||||
"bank_statement_analysis_jobs",
|
||||
sa.Column("source_hashes_json", sa.Text(), nullable=True),
|
||||
)
|
||||
|
||||
op.add_column(
|
||||
"accounting_bank_reconciliation_runs",
|
||||
sa.Column("account_number", sa.String(100), nullable=False, server_default=""),
|
||||
)
|
||||
op.add_column(
|
||||
"accounting_bank_reconciliation_runs",
|
||||
sa.Column("date_tolerance_days", sa.Integer(), nullable=False, server_default="15"),
|
||||
)
|
||||
op.create_index(
|
||||
"ix_accounting_bank_reconciliation_runs_account_number",
|
||||
"accounting_bank_reconciliation_runs",
|
||||
["account_number"],
|
||||
)
|
||||
|
||||
op.add_column(
|
||||
"accounting_bank_reconciliation_items",
|
||||
sa.Column("resolution_status", sa.String(30), nullable=False, server_default="unresolved"),
|
||||
)
|
||||
op.add_column(
|
||||
"accounting_bank_reconciliation_items",
|
||||
sa.Column("resolution_note", sa.Text(), nullable=False, server_default=""),
|
||||
)
|
||||
op.add_column(
|
||||
"accounting_bank_reconciliation_items",
|
||||
sa.Column(
|
||||
"resolved_by_user_id",
|
||||
sa.Integer(),
|
||||
sa.ForeignKey("users.id", ondelete="SET NULL"),
|
||||
nullable=True,
|
||||
),
|
||||
)
|
||||
op.add_column(
|
||||
"accounting_bank_reconciliation_items",
|
||||
sa.Column("resolved_at_utc", sa.DateTime(timezone=True), nullable=True),
|
||||
)
|
||||
op.create_index(
|
||||
"ix_accounting_bank_reconciliation_items_resolution_status",
|
||||
"accounting_bank_reconciliation_items",
|
||||
["resolution_status"],
|
||||
)
|
||||
|
||||
op.create_table(
|
||||
"accounting_bank_ledger_mappings",
|
||||
sa.Column("id", sa.Integer(), primary_key=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("account_number", sa.String(100), nullable=False),
|
||||
sa.Column("bank_name", sa.String(160), nullable=False, server_default=""),
|
||||
sa.Column("tally_guid", sa.String(120), nullable=False),
|
||||
sa.Column("company_name", sa.String(255), nullable=False, server_default=""),
|
||||
sa.Column("bank_ledger_name", sa.String(255), nullable=False),
|
||||
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",
|
||||
"client_id",
|
||||
"account_number",
|
||||
"tally_guid",
|
||||
name="uq_accounting_bank_ledger_mapping",
|
||||
),
|
||||
)
|
||||
for name in ("tenant_id", "client_id", "account_number", "tally_guid"):
|
||||
op.create_index(
|
||||
f"ix_accounting_bank_ledger_mappings_{name}",
|
||||
"accounting_bank_ledger_mappings",
|
||||
[name],
|
||||
)
|
||||
|
||||
|
||||
def downgrade():
|
||||
op.drop_table("accounting_bank_ledger_mappings")
|
||||
|
||||
op.drop_index(
|
||||
"ix_accounting_bank_reconciliation_items_resolution_status",
|
||||
table_name="accounting_bank_reconciliation_items",
|
||||
)
|
||||
op.drop_column("accounting_bank_reconciliation_items", "resolved_at_utc")
|
||||
op.drop_column("accounting_bank_reconciliation_items", "resolved_by_user_id")
|
||||
op.drop_column("accounting_bank_reconciliation_items", "resolution_note")
|
||||
op.drop_column("accounting_bank_reconciliation_items", "resolution_status")
|
||||
|
||||
op.drop_index(
|
||||
"ix_accounting_bank_reconciliation_runs_account_number",
|
||||
table_name="accounting_bank_reconciliation_runs",
|
||||
)
|
||||
op.drop_column("accounting_bank_reconciliation_runs", "date_tolerance_days")
|
||||
op.drop_column("accounting_bank_reconciliation_runs", "account_number")
|
||||
|
||||
op.drop_column("bank_statement_analysis_jobs", "source_hashes_json")
|
||||
op.drop_column("bank_statement_analysis_jobs", "stored_source_versions_json")
|
||||
Reference in New Issue
Block a user