- 00-auth-base.sql: Extracted auth.tenants+users from recreate-database.sh - 03b-core-companies.sql: DDL for auth.companies entity - 21b-inventory-extended.sql: 7 new tables for inventory entities without DDL - 24-invoices.sql: billing→operations schema to resolve duplication - 27/28/29-cfdi: Track existing CFDI DDL files - recreate-database.sh: Updated ddl_files array (17→43 entries) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
53 lines
1.7 KiB
SQL
53 lines
1.7 KiB
SQL
-- =============================================================
|
|
-- ARCHIVO: 00-auth-base.sql
|
|
-- DESCRIPCION: Tablas base de autenticacion (tenants y users)
|
|
-- Estas tablas son prerequisito para todos los demas DDL
|
|
-- VERSION: 1.0.0
|
|
-- PROYECTO: ERP-Core V2
|
|
-- FECHA: 2026-02-05
|
|
-- =============================================================
|
|
|
|
-- =====================
|
|
-- SCHEMA: auth (si no existe)
|
|
-- =====================
|
|
CREATE SCHEMA IF NOT EXISTS auth;
|
|
|
|
-- =====================
|
|
-- TABLA: tenants
|
|
-- Organizaciones/empresas en el sistema multi-tenant
|
|
-- =====================
|
|
CREATE TABLE IF NOT EXISTS auth.tenants (
|
|
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
name VARCHAR(200) NOT NULL,
|
|
slug VARCHAR(100) UNIQUE NOT NULL,
|
|
is_active BOOLEAN DEFAULT TRUE,
|
|
created_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP,
|
|
updated_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP,
|
|
deleted_at TIMESTAMPTZ
|
|
);
|
|
|
|
-- =====================
|
|
-- TABLA: users
|
|
-- Usuarios del sistema, vinculados a un tenant
|
|
-- =====================
|
|
CREATE TABLE IF NOT EXISTS auth.users (
|
|
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
tenant_id UUID REFERENCES auth.tenants(id) ON DELETE CASCADE,
|
|
email VARCHAR(255) NOT NULL,
|
|
password_hash TEXT,
|
|
first_name VARCHAR(100),
|
|
last_name VARCHAR(100),
|
|
is_active BOOLEAN DEFAULT TRUE,
|
|
email_verified BOOLEAN DEFAULT FALSE,
|
|
created_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP,
|
|
updated_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP,
|
|
deleted_at TIMESTAMPTZ,
|
|
UNIQUE(tenant_id, email)
|
|
);
|
|
|
|
-- =====================
|
|
-- INDICES
|
|
-- =====================
|
|
CREATE INDEX IF NOT EXISTS idx_users_tenant ON auth.users(tenant_id);
|
|
CREATE INDEX IF NOT EXISTS idx_users_email ON auth.users(email);
|