From 0c4f54b2c0511704da2e86f3d351bfa22acf7c17 Mon Sep 17 00:00:00 2001 From: Galindo97 Date: Thu, 30 Apr 2026 11:09:07 -0500 Subject: [PATCH] fix: update VARCHAR lengths to prevent truncation errors in audit_log and discharges --- ...9l0m1n2_fix_varchar20_truncation_errors.py | 104 ++++++++++++++++++ .../api/v1/modules/a24/discharges/models.py | 2 +- .../api/v1/modules/a76/audit_log/models.py | 4 +- .../a76/rule_octave/balances/models.py | 2 +- docker-compose.yml | 2 +- 5 files changed, 109 insertions(+), 5 deletions(-) create mode 100644 backend/alembic/versions/i7j8k9l0m1n2_fix_varchar20_truncation_errors.py diff --git a/backend/alembic/versions/i7j8k9l0m1n2_fix_varchar20_truncation_errors.py b/backend/alembic/versions/i7j8k9l0m1n2_fix_varchar20_truncation_errors.py new file mode 100644 index 00000000..1dfec32a --- /dev/null +++ b/backend/alembic/versions/i7j8k9l0m1n2_fix_varchar20_truncation_errors.py @@ -0,0 +1,104 @@ +"""Fix VARCHAR(20) truncation errors in audit_log and discharges + +Revision ID: i7j8k9l0m1n2 +Revises: h1a2b3c4d5e6 +Create Date: 2026-04-30 13:00:00.000000 + +Issues fixed: +- audit_log.system: String(20) → String(50) +- audit_log.operation_type: String(20) → String(50) +- discharges.cancelled_by: String(20) → String(100) +- octave_balance.octave_permit: String(20) → String(100) +""" +from alembic import op +import sqlalchemy as sa + +# revision identifiers, used by Alembic. +revision = 'i7j8k9l0m1n2' +down_revision = 'h1a2b3c4d5e6' +branch_labels = None +depends_on = None + + +def upgrade() -> None: + # Fix audit_log.system + op.alter_column( + 'audit_logs', + 'system', + existing_type=sa.String(length=20), + type_=sa.String(length=50), + existing_nullable=False, + schema='a76', + ) + + # Fix audit_log.operation_type + op.alter_column( + 'audit_logs', + 'operation_type', + existing_type=sa.String(length=20), + type_=sa.String(length=50), + existing_nullable=True, + schema='a76', + ) + + # Fix discharges.cancelled_by + op.alter_column( + 'discharge_header', + 'cancelled_by', + existing_type=sa.String(length=20), + type_=sa.String(length=100), + existing_nullable=True, + schema='a24', + ) + + # Fix octave_balance.octave_permit + op.alter_column( + 'octave_balance', + 'octave_permit', + existing_type=sa.String(length=20), + type_=sa.String(length=100), + existing_nullable=False, + schema='a76', + ) + + +def downgrade() -> None: + # Revert octave_balance.octave_permit + op.alter_column( + 'octave_balance', + 'octave_permit', + existing_type=sa.String(length=100), + type_=sa.String(length=20), + existing_nullable=False, + schema='a76', + ) + + # Revert discharges.cancelled_by + op.alter_column( + 'discharge_header', + 'cancelled_by', + existing_type=sa.String(length=100), + type_=sa.String(length=20), + existing_nullable=True, + schema='a24', + ) + + # Revert audit_log.operation_type + op.alter_column( + 'audit_logs', + 'operation_type', + existing_type=sa.String(length=50), + type_=sa.String(length=20), + existing_nullable=True, + schema='a76', + ) + + # Revert audit_log.system + op.alter_column( + 'audit_logs', + 'system', + existing_type=sa.String(length=50), + type_=sa.String(length=20), + existing_nullable=False, + schema='a76', + ) diff --git a/backend/api/v1/modules/a24/discharges/models.py b/backend/api/v1/modules/a24/discharges/models.py index 47d5511a..13549411 100644 --- a/backend/api/v1/modules/a24/discharges/models.py +++ b/backend/api/v1/modules/a24/discharges/models.py @@ -132,7 +132,7 @@ class DischargeHeader(Base, TenantScopedMixin, TimestampMixin): ) # ── Cancellation trail ──────────────────────────────────────────────── - cancelled_by: Mapped[Optional[str]] = mapped_column(String(20)) + cancelled_by: Mapped[Optional[str]] = mapped_column(String(100)) cancellation_reason: Mapped[Optional[str]] = mapped_column(String(300)) # ── Relationships ───────────────────────────────────────────────────── diff --git a/backend/api/v1/modules/a76/audit_log/models.py b/backend/api/v1/modules/a76/audit_log/models.py index ace69a32..31b51f03 100644 --- a/backend/api/v1/modules/a76/audit_log/models.py +++ b/backend/api/v1/modules/a76/audit_log/models.py @@ -30,12 +30,12 @@ class AuditLog(Base, TenantScopedMixin, TimestampMixin): # Technical Columns timestamp = Column(DateTime(timezone=True), nullable=False, index=True) # Combined for queries - system = Column(String(20), nullable=False, index=True, default="fixed_asset") + system = Column(String(50), nullable=False, index=True, default="fixed_asset") # Traceability table_name = Column(String(100), nullable=True, index=True) record_id = Column(String(255), nullable=True, index=True) - operation_type = Column(String(20), nullable=True, index=True) # CREATE, UPDATE, DELETE, LOGIN + operation_type = Column(String(50), nullable=True, index=True) # CREATE, UPDATE, DELETE, LOGIN # Data Changes old_values = Column(JSONB, nullable=True) diff --git a/backend/api/v1/modules/a76/rule_octave/balances/models.py b/backend/api/v1/modules/a76/rule_octave/balances/models.py index 97aa262a..7ef83c83 100644 --- a/backend/api/v1/modules/a76/rule_octave/balances/models.py +++ b/backend/api/v1/modules/a76/rule_octave/balances/models.py @@ -42,7 +42,7 @@ class OctaveBalance(Base, TenantScopedMixin, TimestampMixin): origin_country: Mapped[str] = mapped_column(String(3)) # PAISORIGEN fraction_type: Mapped[str] = mapped_column(String(7)) # TIPOFRACIMPO sector: Mapped[str] = mapped_column(String(8)) # SECTOR - octave_permit: Mapped[str] = mapped_column(String(20)) # PERMISOROCTAVA + octave_permit: Mapped[str] = mapped_column(String(100)) # PERMISOROCTAVA origin: Mapped[str] = mapped_column(String(3)) # PROCEDENCIA ('TEM') system: Mapped[str] = mapped_column(String(5)) # SISTEMA ('fixed_asset | inventory') line: Mapped[int] = mapped_column(Integer) # LINEA diff --git a/docker-compose.yml b/docker-compose.yml index c121115c..a6c91756 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -310,5 +310,5 @@ networks: driver: bridge hub-net: - external: false + external: true name: aduanasoft-hub_default