From 27e18c9d0b5f49d930126335e4f3196e757307e6 Mon Sep 17 00:00:00 2001 From: Galindo97 Date: Mon, 12 Jan 2026 11:38:12 -0600 Subject: [PATCH] feat(database): add deleted_at column to units of measure tables and update DTO field lengths --- ...31bf8cdae06_create_material_types_table.py | 5 ++ .../7937209f9718_seed_initial_data.py | 4 ++ .../general_catalogs/units_of_measure/dto.py | 48 +++++++++---------- 3 files changed, 33 insertions(+), 24 deletions(-) diff --git a/backend/alembic/versions/531bf8cdae06_create_material_types_table.py b/backend/alembic/versions/531bf8cdae06_create_material_types_table.py index 5205a7e2..7e7b4630 100644 --- a/backend/alembic/versions/531bf8cdae06_create_material_types_table.py +++ b/backend/alembic/versions/531bf8cdae06_create_material_types_table.py @@ -178,6 +178,7 @@ def upgrade() -> None: sa.Column('description', sa.String(length=49), nullable=True), sa.Column('created_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False), sa.Column('updated_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False), + sa.Column('deleted_at', sa.DateTime(), nullable=True), sa.PrimaryKeyConstraint('id'), sa.UniqueConstraint('code', name='uq_uom_ace_code'), schema='a76' @@ -191,6 +192,7 @@ def upgrade() -> None: sa.Column('description', sa.String(length=200), nullable=True), sa.Column('created_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False), sa.Column('updated_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False), + sa.Column('deleted_at', sa.DateTime(), nullable=True), sa.PrimaryKeyConstraint('id'), sa.UniqueConstraint('code', name='uq_uom_oma_code'), schema='a76' @@ -204,6 +206,7 @@ def upgrade() -> None: sa.Column('description', sa.String(length=40), nullable=True), sa.Column('created_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False), sa.Column('updated_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False), + sa.Column('deleted_at', sa.DateTime(), nullable=True), sa.PrimaryKeyConstraint('id'), sa.UniqueConstraint('code', name='uq_uom_american_code'), schema='a76' @@ -218,6 +221,7 @@ def upgrade() -> None: sa.Column('scaii_unit_code', sa.String(length=5), nullable=True), sa.Column('created_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False), sa.Column('updated_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False), + sa.Column('deleted_at', sa.DateTime(), nullable=True), sa.PrimaryKeyConstraint('id'), sa.UniqueConstraint('code', name='uq_uom_customs_code'), schema='a76' @@ -238,6 +242,7 @@ def upgrade() -> None: sa.Column('company_id', sa.Integer(), nullable=False), sa.Column('created_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False), sa.Column('updated_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False), + sa.Column('deleted_at', sa.DateTime(), nullable=True), sa.ForeignKeyConstraint( ['customs_code'], ['a76.unit_of_measure_customs.code'], diff --git a/backend/alembic/versions/7937209f9718_seed_initial_data.py b/backend/alembic/versions/7937209f9718_seed_initial_data.py index 46eede98..a3ba52df 100644 --- a/backend/alembic/versions/7937209f9718_seed_initial_data.py +++ b/backend/alembic/versions/7937209f9718_seed_initial_data.py @@ -79,6 +79,10 @@ def upgrade() -> None: op.execute("ALTER TABLE a76.units_of_measure ALTER COLUMN american_code TYPE VARCHAR(20);") op.execute("ALTER TABLE a76.units_of_measure ALTER COLUMN ace_code TYPE VARCHAR(20);") op.execute("ALTER TABLE a76.units_of_measure ALTER COLUMN oma_code TYPE VARCHAR(20);") + + # --- AGREGAR COLUMNAS deleted_at --- + op.execute("ALTER TABLE a76.units_of_measure ADD COLUMN IF NOT EXISTS deleted_at TIMESTAMP;") + op.execute("ALTER TABLE a76.units_of_measure_general ADD COLUMN IF NOT EXISTS deleted_at TIMESTAMP;") # --- UTILIDAD DE FORMATEO --- def format_value(val): diff --git a/backend/api/v1/modules/a76/general_catalogs/units_of_measure/dto.py b/backend/api/v1/modules/a76/general_catalogs/units_of_measure/dto.py index 2864c135..aa75c493 100644 --- a/backend/api/v1/modules/a76/general_catalogs/units_of_measure/dto.py +++ b/backend/api/v1/modules/a76/general_catalogs/units_of_measure/dto.py @@ -21,29 +21,29 @@ class UnitOfMeasureAmericanBase(BaseModel): class UnitOfMeasureCustomsBase(BaseModel): - code: str = Field(..., max_length=2, description="Customs Code") - description: Optional[str] = Field(None, max_length=20) + code: str = Field(..., max_length=10, description="Customs Code") + description: Optional[str] = Field(None, max_length=50) scaii_unit_code: Optional[str] = Field(None, max_length=5) class UnitOfMeasureBase(BaseModel): - code: str = Field(..., max_length=5, description="Unit Code") + code: str = Field(..., max_length=20, description="Unit Code") description: Optional[str] = Field(None, max_length=100) description_en: Optional[str] = Field(None, max_length=100) - customs_code: Optional[str] = Field(None, max_length=2) - american_code: Optional[str] = Field(None, max_length=3) - ace_code: Optional[str] = Field(None, max_length=4) - oma_code: Optional[str] = Field(None, max_length=10) + customs_code: Optional[str] = Field(None, max_length=20) + american_code: Optional[str] = Field(None, max_length=20) + ace_code: Optional[str] = Field(None, max_length=20) + oma_code: Optional[str] = Field(None, max_length=20) class UnitOfMeasureGeneralBase(BaseModel): - code: str = Field(..., max_length=5, description="Unit Code") + code: str = Field(..., max_length=20, description="Unit Code") description: Optional[str] = Field(None, max_length=100) conversion_factor: Optional[Decimal] = None - mexico_unit: Optional[str] = Field(None, max_length=5) - american_unit_code: Optional[str] = Field(None, max_length=5) - customs_code: Optional[str] = Field(None, max_length=2) - ace_code: Optional[str] = Field(None, max_length=4) + mexico_unit: Optional[str] = Field(None, max_length=20) + american_unit_code: Optional[str] = Field(None, max_length=20) + customs_code: Optional[str] = Field(None, max_length=20) + ace_code: Optional[str] = Field(None, max_length=20) # --- Create DTOs --- @@ -90,29 +90,29 @@ class UnitOfMeasureAmericanUpdate(BaseModel): class UnitOfMeasureCustomsUpdate(BaseModel): - code: Optional[str] = Field(None, max_length=2) - description: Optional[str] = Field(None, max_length=20) + code: Optional[str] = Field(None, max_length=10) + description: Optional[str] = Field(None, max_length=50) scaii_unit_code: Optional[str] = Field(None, max_length=5) class UnitOfMeasureUpdate(BaseModel): - code: Optional[str] = Field(None, max_length=5) + code: Optional[str] = Field(None, max_length=20) description: Optional[str] = Field(None, max_length=100) description_en: Optional[str] = Field(None, max_length=100) - customs_code: Optional[str] = Field(None, max_length=2) - american_code: Optional[str] = Field(None, max_length=3) - ace_code: Optional[str] = Field(None, max_length=4) - oma_code: Optional[str] = Field(None, max_length=10) + customs_code: Optional[str] = Field(None, max_length=20) + american_code: Optional[str] = Field(None, max_length=20) + ace_code: Optional[str] = Field(None, max_length=20) + oma_code: Optional[str] = Field(None, max_length=20) class UnitOfMeasureGeneralUpdate(BaseModel): - code: Optional[str] = Field(None, max_length=5) + code: Optional[str] = Field(None, max_length=20) description: Optional[str] = Field(None, max_length=100) conversion_factor: Optional[Decimal] = None - mexico_unit: Optional[str] = Field(None, max_length=5) - american_unit_code: Optional[str] = Field(None, max_length=5) - customs_code: Optional[str] = Field(None, max_length=2) - ace_code: Optional[str] = Field(None, max_length=4) + mexico_unit: Optional[str] = Field(None, max_length=20) + american_unit_code: Optional[str] = Field(None, max_length=20) + customs_code: Optional[str] = Field(None, max_length=20) + ace_code: Optional[str] = Field(None, max_length=20) # --- Response DTOs ---