Files
hechakuaa_bot/migrations/001_initial_schema.sql
markosbenitez 076bc100af feat: Docker, health check, schema migrations y webhook opt-in
- migrations/001_initial_schema.sql: DDL idempotente con CREATE TABLE/INDEX IF NOT EXISTS
- database.py: run_migrations() aplica .sql pendientes en orden; init_db() queda como alias
- health.py: servidor aiohttp en puerto 8080 — GET /health, GET /health/history, POST /webhook
  Watcher loop alerta al admin por Telegram si el poller no actualiza en N horas
- config.py: webhook_url, webhook_secret, health_port, health_alert_hours
- poller.py: on_poll_done callback (conecta con health.record_poll)
- main.py: arranca HealthServer, llama run_migrations, modo webhook opt-in via WEBHOOK_URL
- Dockerfile + docker-compose.yml + .dockerignore
- pyproject.toml: aiohttp>=3.9

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-25 23:31:18 -03:00

43 lines
1.4 KiB
SQL

-- 001_initial_schema.sql — Schema base de Pedrito Hechakuaa
-- Idempotente: usa CREATE TABLE/INDEX IF NOT EXISTS
CREATE TABLE IF NOT EXISTS schema_migrations (
version TEXT PRIMARY KEY,
applied_at TEXT NOT NULL
);
CREATE TABLE IF NOT EXISTS invite_codes (
codigo TEXT PRIMARY KEY,
creado_at TEXT NOT NULL,
usado INTEGER DEFAULT 0,
usado_por INTEGER,
usado_at TEXT
);
CREATE TABLE IF NOT EXISTS tenants (
chat_id INTEGER PRIMARY KEY,
nombre_preferido TEXT,
tono TEXT DEFAULT 'cotidiano',
timezone TEXT DEFAULT 'America/Asuncion',
credentials_enc TEXT,
estado TEXT DEFAULT 'pendiente',
consentimiento_aceptado INTEGER DEFAULT 0,
created_at TEXT,
last_active TEXT
);
CREATE TABLE IF NOT EXISTS audit_log (
id INTEGER PRIMARY KEY AUTOINCREMENT,
timestamp TEXT NOT NULL,
timestamp_local TEXT,
chat_id INTEGER,
evento TEXT NOT NULL,
detalle TEXT,
resultado TEXT,
duracion_ms INTEGER
);
CREATE INDEX IF NOT EXISTS idx_audit_chat_id ON audit_log(chat_id);
CREATE INDEX IF NOT EXISTS idx_audit_timestamp ON audit_log(timestamp);
CREATE INDEX IF NOT EXISTS idx_audit_evento ON audit_log(evento);