0005 - cat_terminos_pago
"""cat_terminos_pago
Revision ID: 0005
Revises: 0004
Create Date: 2026-09-20
"""
from typing import Sequence, Union
from alembic import op
# revision identifiers, used by Alembic.
revision: str = "0005"
down_revision: Union[str, None] = "0004"
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None:
op.execute(
"""
CREATE TABLE clientes.cat_terminos_pago (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
empresa_id BIGINT NOT NULL,
codigo VARCHAR(30) NOT NULL,
nombre VARCHAR(100) NOT NULL,
dias_plazo SMALLINT NOT NULL,
descripcion TEXT,
is_activo BOOLEAN NOT NULL DEFAULT true,
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT now(),
deleted_at TIMESTAMPTZ,
created_by UUID,
updated_by UUID,
CONSTRAINT ck_terminos_pago_dias_no_negativos CHECK (dias_plazo >= 0),
CONSTRAINT uq_terminos_pago_empresa_id UNIQUE (empresa_id, id),
CONSTRAINT uq_terminos_pago_empresa_codigo UNIQUE (empresa_id, codigo)
);
ALTER TABLE clientes.cat_terminos_pago ENABLE ROW LEVEL SECURITY;
CREATE POLICY rls_terminos_pago_empresa
ON clientes.cat_terminos_pago
USING (empresa_id = current_setting('app.current_empresa_id', true)::BIGINT)
WITH CHECK (empresa_id = current_setting('app.current_empresa_id', true)::BIGINT);
"""
)
def downgrade() -> None:
op.execute("DROP TABLE IF EXISTS clientes.cat_terminos_pago;")