Files
plantillas-proyectos/backend/alembic/versions/f4258dfb6651_create_initial_tables.py
acazares 2a10d7d267 feat: Add frontend and backend initialization scripts, implement Keycloak and PostgreSQL setup
- Implemented SvelteKit frontend with authentication callback handling.
- Created demo routes and paraglide localization functionality.
- Added health check and entrypoint scripts for backend services.
- Established PostgreSQL and Keycloak initialization scripts with health checks.
- Introduced models for database schema using SQLAlchemy.
- Configured Vite and SvelteKit for development and testing environments.
- Added health check script to verify service statuses and resource usage.
- Created Docker entrypoint scripts for seamless service startup.
2025-10-19 00:14:06 -05:00

213 lines
11 KiB
Python

"""create initial tables
Revision ID: f4258dfb6651
Revises:
Create Date: 2025-10-19 05:10:20.031133
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision: str = 'f4258dfb6651'
down_revision: Union[str, Sequence[str], None] = None
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None:
"""Upgrade schema."""
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('tenants',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('name', sa.String(length=255), nullable=False),
sa.Column('slug', sa.String(length=100), nullable=False),
sa.Column('type', sa.Enum('SHARED', 'DEDICATED', name='tenanttype'), nullable=False),
sa.Column('keycloak_realm', sa.String(length=255), nullable=False),
sa.Column('db_config', sa.Text(), nullable=True),
sa.Column('contact_name', sa.String(length=255), nullable=True),
sa.Column('contact_email', sa.String(length=255), nullable=True),
sa.Column('contact_phone', sa.String(length=50), nullable=True),
sa.Column('is_active', sa.Boolean(), 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.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('keycloak_realm'),
schema='a76'
)
op.create_index(op.f('ix_a76_tenants_id'), 'tenants', ['id'], unique=False, schema='a76')
op.create_index(op.f('ix_a76_tenants_name'), 'tenants', ['name'], unique=False, schema='a76')
op.create_index(op.f('ix_a76_tenants_slug'), 'tenants', ['slug'], unique=True, schema='a76')
op.create_table('containers',
sa.Column('key', sa.String(length=3), nullable=False),
sa.Column('description', sa.String(length=500), nullable=False),
sa.PrimaryKeyConstraint('key', name='containers_pkey'),
schema='public'
)
op.create_table('countries',
sa.Column('m3_key', sa.String(length=3), nullable=False),
sa.Column('mex_key', sa.String(length=2), nullable=False),
sa.Column('ame_key', sa.String(length=2), nullable=False),
sa.Column('description_es', sa.String(length=50), nullable=False),
sa.Column('description_en', sa.String(length=50), nullable=False),
sa.PrimaryKeyConstraint('m3_key', name='countries_pkey'),
schema='public'
)
op.create_index('ak_country_ame', 'countries', ['ame_key'], unique=True, schema='public')
op.create_table('customs_sections',
sa.Column('customs_code', sa.String(length=3), nullable=False),
sa.Column('section_name', sa.String(length=50), nullable=False),
sa.PrimaryKeyConstraint('customs_code', name='customs_code_pkey'),
schema='public'
)
op.create_table('customs_warehouses',
sa.Column('key', sa.String(length=3), nullable=False),
sa.Column('customs', sa.String(length=100), nullable=False),
sa.Column('fiscalized_warehouse', sa.String(length=1000), nullable=False),
sa.PrimaryKeyConstraint('key', 'customs', name='pk_customs_warehouse'),
schema='public'
)
op.create_table('incoterms',
sa.Column('code', sa.String(length=5), nullable=False),
sa.Column('description_es', sa.String(length=256), nullable=False),
sa.Column('description_en', sa.String(length=256), nullable=False),
sa.PrimaryKeyConstraint('code', name='incoterms_pkey'),
schema='public'
)
op.create_table('material_types',
sa.Column('key', sa.String(length=10), nullable=False),
sa.Column('origin_type', sa.String(length=15), nullable=False),
sa.Column('description', sa.String(length=256), nullable=False),
sa.PrimaryKeyConstraint('key', name='material_types_pkey'),
schema='public'
)
op.create_table('payment_methods',
sa.Column('key', sa.String(length=2), nullable=False),
sa.Column('description', sa.String(length=100), nullable=False),
sa.PrimaryKeyConstraint('key', name='payment_methods_pkey'),
schema='public'
)
op.create_table('pedimento_codes',
sa.Column('code', sa.String(length=3), nullable=False),
sa.Column('description', sa.String(length=250), nullable=False),
sa.PrimaryKeyConstraint('code', name='pedimento_codes_pkey'),
schema='public'
)
op.create_table('pedimento_regimens',
sa.Column('code', sa.String(length=3), nullable=False),
sa.Column('description', sa.String(length=100), nullable=False),
sa.PrimaryKeyConstraint('code', name='pedimento_regimens_pkey'),
schema='public'
)
op.create_table('sectors',
sa.Column('key', sa.String(length=8), nullable=False),
sa.Column('description', sa.String(length=150), nullable=False),
sa.Column('authorized', sa.SmallInteger(), nullable=False),
sa.PrimaryKeyConstraint('key', name='sectors_pkey'),
schema='public'
)
op.create_table('states',
sa.Column('m3_key', sa.String(length=3), nullable=False),
sa.Column('description', sa.String(length=50), nullable=False),
sa.Column('mex_key', sa.String(length=3), nullable=True),
sa.Column('ame_key', sa.String(length=2), nullable=True),
sa.PrimaryKeyConstraint('m3_key', 'description', name='states_pkey'),
schema='public'
)
op.create_table('transport_modes',
sa.Column('key', sa.String(length=3), nullable=False),
sa.Column('name', sa.String(length=30), nullable=False),
sa.PrimaryKeyConstraint('key', name='transport_modes_pkey'),
schema='public'
)
op.create_table('valuation_methods',
sa.Column('key', sa.String(length=2), nullable=False),
sa.Column('description', sa.String(length=200), nullable=False),
sa.PrimaryKeyConstraint('key', name='valuation_methods_pkey'),
schema='public'
)
op.create_table('license_usage',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('tenant_id', sa.Integer(), nullable=False),
sa.Column('period_start', sa.DateTime(timezone=True), nullable=False),
sa.Column('period_end', sa.DateTime(timezone=True), nullable=False),
sa.Column('active_users', sa.Integer(), nullable=True),
sa.Column('storage_used_gb', sa.Integer(), nullable=True),
sa.Column('operations_count', sa.Integer(), nullable=True),
sa.Column('api_calls_count', sa.Integer(), nullable=True),
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.ForeignKeyConstraint(['tenant_id'], ['a76.tenants.id'], ),
sa.PrimaryKeyConstraint('id'),
schema='a76'
)
op.create_index(op.f('ix_a76_license_usage_id'), 'license_usage', ['id'], unique=False, schema='a76')
op.create_index(op.f('ix_a76_license_usage_tenant_id'), 'license_usage', ['tenant_id'], unique=False, schema='a76')
op.create_table('licenses',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('tenant_id', sa.Integer(), nullable=False),
sa.Column('plan', sa.Enum('FREE', 'BASIC', 'PROFESSIONAL', 'ENTERPRISE', name='licenseplan'), nullable=False),
sa.Column('status', sa.Enum('ACTIVE', 'EXPIRED', 'SUSPENDED', 'PENDING', 'CANCELLED', name='licensestatus'), nullable=False),
sa.Column('max_users', sa.Integer(), nullable=False),
sa.Column('max_storage_gb', sa.Integer(), nullable=False),
sa.Column('max_monthly_operations', sa.Integer(), nullable=False),
sa.Column('feature_api_access', sa.Boolean(), nullable=True),
sa.Column('feature_advanced_reports', sa.Boolean(), nullable=True),
sa.Column('feature_integrations', sa.Boolean(), nullable=True),
sa.Column('feature_dedicated_support', sa.Boolean(), nullable=True),
sa.Column('starts_at', sa.DateTime(timezone=True), nullable=False),
sa.Column('expires_at', sa.DateTime(timezone=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.ForeignKeyConstraint(['tenant_id'], ['a76.tenants.id'], ),
sa.PrimaryKeyConstraint('id'),
schema='a76'
)
op.create_index(op.f('ix_a76_licenses_id'), 'licenses', ['id'], unique=False, schema='a76')
op.create_index(op.f('ix_a76_licenses_tenant_id'), 'licenses', ['tenant_id'], unique=True, schema='a76')
op.create_table('code_pedimento_regimens',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('pedimento_code', sa.String(length=3), nullable=False),
sa.Column('regimen_code', sa.String(length=3), nullable=False),
sa.Column('type_code', sa.String(length=1), nullable=True),
sa.ForeignKeyConstraint(['pedimento_code'], ['public.pedimento_codes.code'], name='fk_claveped'),
sa.ForeignKeyConstraint(['regimen_code'], ['public.pedimento_regimens.code'], name='fk_regimenped'),
sa.PrimaryKeyConstraint('id', name='clave_pedimento_regimens_pkey'),
schema='public'
)
# ### end Alembic commands ###
def downgrade() -> None:
"""Downgrade schema."""
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('code_pedimento_regimens', schema='public')
op.drop_index(op.f('ix_a76_licenses_tenant_id'), table_name='licenses', schema='a76')
op.drop_index(op.f('ix_a76_licenses_id'), table_name='licenses', schema='a76')
op.drop_table('licenses', schema='a76')
op.drop_index(op.f('ix_a76_license_usage_tenant_id'), table_name='license_usage', schema='a76')
op.drop_index(op.f('ix_a76_license_usage_id'), table_name='license_usage', schema='a76')
op.drop_table('license_usage', schema='a76')
op.drop_table('valuation_methods', schema='public')
op.drop_table('transport_modes', schema='public')
op.drop_table('states', schema='public')
op.drop_table('sectors', schema='public')
op.drop_table('pedimento_regimens', schema='public')
op.drop_table('pedimento_codes', schema='public')
op.drop_table('payment_methods', schema='public')
op.drop_table('material_types', schema='public')
op.drop_table('incoterms', schema='public')
op.drop_table('customs_warehouses', schema='public')
op.drop_table('customs_sections', schema='public')
op.drop_index('ak_country_ame', table_name='countries', schema='public')
op.drop_table('countries', schema='public')
op.drop_table('containers', schema='public')
op.drop_index(op.f('ix_a76_tenants_slug'), table_name='tenants', schema='a76')
op.drop_index(op.f('ix_a76_tenants_name'), table_name='tenants', schema='a76')
op.drop_index(op.f('ix_a76_tenants_id'), table_name='tenants', schema='a76')
op.drop_table('tenants', schema='a76')
# ### end Alembic commands ###