"""add configuration tables
Revision ID: add_configuration_tables
Revises: a20294e6d633
Create Date: 2024-03-19 10:00:00.000000
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import sqlite
# revision identifiers, used by Alembic.
revision: str = 'add_configuration_tables'
down_revision: Union[str, None] = 'a20294e6d633'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None:
# Tabla para configuraciones de comportamiento
op.create_table(
'behavior_configs',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('key', sa.String(), nullable=False),
sa.Column('value', sqlite.JSON, nullable=False),
sa.Column('description', sa.String(), nullable=True),
sa.Column('category', sa.String(), nullable=True),
sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP')),
sa.Column('updated_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP')),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('key', 'category', name='uq_behavior_config_key_category')
)
# Tabla para dimensiones MECE
op.create_table(
'mece_dimensions',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('name', sa.String(), nullable=False),
sa.Column('is_required', sa.Boolean(), nullable=False),
sa.Column('description', sa.String(), nullable=True),
sa.Column('validation_rules', sqlite.JSON, nullable=True),
sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP')),
sa.Column('updated_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP')),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('name', name='uq_mece_dimension_name')
)
# Tabla para validaciones de taxonomía
op.create_table(
'taxonomy_validations',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('platform', sa.String(), nullable=True),
sa.Column('domain', sa.String(), nullable=True),
sa.Column('warning', sa.String(), nullable=False),
sa.Column('severity', sa.String(), nullable=False),
sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP')),
sa.PrimaryKeyConstraint('id')
)
# Tabla para orden de buckets
op.create_table(
'bucket_order',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('bucket_name', sa.String(), nullable=False),
sa.Column('order_index', sa.Integer(), nullable=False),
sa.Column('category', sa.String(), nullable=True),
sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP')),
sa.Column('updated_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP')),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('bucket_name', 'category', name='uq_bucket_order_name_category')
)
# Tabla para metadatos de comandos
op.create_table(
'commands',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('name', sa.String(), nullable=False),
sa.Column('description', sa.String(), nullable=False),
sa.Column('parameters', sqlite.JSON, nullable=True),
sa.Column('example', sa.String(), nullable=True),
sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP')),
sa.Column('updated_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP')),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('name', name='uq_command_name')
)
def downgrade() -> None:
op.drop_table('commands')
op.drop_table('bucket_order')
op.drop_table('taxonomy_validations')
op.drop_table('mece_dimensions')
op.drop_table('behavior_configs')