"""create table fuerza_ventas.cat_metodos_pago
Revision ID: 0012
Revises: 0011
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
# revision identifiers, used by Alembic.
revision: str = "0012"
down_revision: Union[str, Sequence[str], None] = "0011"
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None:
op.create_table(
'cat_metodos_pago',
sa.Column('id', postgresql.UUID(as_uuid=True), server_default=sa.text('gen_random_uuid()'), nullable=False),
sa.Column(
"empresa_id",
sa.BigInteger(), nullable=False),
sa.Column('codigo', sa.String(length=30), nullable=False),
sa.Column('nombre', sa.String(length=100), nullable=False),
sa.Column('requiere_banco_referencia', sa.Boolean(), nullable=False),
sa.Column('requiere_imagen_comprobante', sa.Boolean(), nullable=False),
sa.Column('is_activo', sa.Boolean(), server_default=sa.text('true'), nullable=False),
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
sa.Column('deleted_at', sa.DateTime(timezone=True), nullable=True),
sa.Column('created_by', postgresql.UUID(as_uuid=True), nullable=True),
sa.Column('updated_by', postgresql.UUID(as_uuid=True), nullable=True),
sa.PrimaryKeyConstraint('id', name='pk_cat_metodos_pago'),
sa.UniqueConstraint('empresa_id', 'id', name='uq_cat_metodos_pago_empresa_id'),
sa.UniqueConstraint('empresa_id', 'codigo', name='uq_cat_metodos_pago_empresa_codigo'),
schema='fuerza_ventas'
)
op.create_index('ix_cat_metodos_pago_empresa_activo', 'cat_metodos_pago', ['empresa_id', 'is_activo'], unique=False, schema='fuerza_ventas')
op.execute('ALTER TABLE fuerza_ventas.cat_metodos_pago ENABLE ROW LEVEL SECURITY')
op.execute('''CREATE POLICY rls_cat_metodos_pago_tenant_isolation ON fuerza_ventas.cat_metodos_pago FOR ALL 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 POLICY IF EXISTS rls_cat_metodos_pago_tenant_isolation ON fuerza_ventas.cat_metodos_pago')
op.drop_index('ix_cat_metodos_pago_empresa_activo', table_name='cat_metodos_pago', schema='fuerza_ventas')
op.drop_table('cat_metodos_pago', schema='fuerza_ventas')