Files
armonia-api/app/db/schema.sql
T
kiskaadee effa1ee86c feat: scaffold FastAPI backend with Turso and anti-ghosting booking state machine
- Initialize project with uv, FastAPI, and libsql-client for Turso persistence
- Implement local SQLite fallback (`file:local.db`) for zero-friction development and testing
- Create schema and seeder with 9 therapy services from Armonía del Ser flyer
- Implement POST /bookings with automatic WhatsApp deep-link generation and SPEI instructions
- Implement POST /payments/verify 1-tap admin acknowledgment flow
- Add automated test suite with 5 passing tests and verification gates (ruff, pyright, pytest)
2026-10-18 09:01:34 -05:00

57 lines
2.1 KiB
SQL

-- Armonía del Ser Database Schema (Turso / SQLite3)
CREATE TABLE IF NOT EXISTS services (
id TEXT PRIMARY KEY,
slug TEXT UNIQUE NOT NULL,
name TEXT NOT NULL,
description TEXT,
service_type TEXT NOT NULL CHECK (service_type IN ('GROUP', 'ONE_ON_ONE')),
modality TEXT NOT NULL CHECK (modality IN ('PRESENCIAL', 'ONLINE')),
default_schedule TEXT,
price_mxn INTEGER NOT NULL DEFAULT 0,
max_capacity INTEGER NOT NULL DEFAULT 1,
duration_minutes INTEGER NOT NULL DEFAULT 60,
is_active INTEGER NOT NULL DEFAULT 1,
created_at TEXT NOT NULL DEFAULT (datetime('now'))
);
CREATE TABLE IF NOT EXISTS clients (
id TEXT PRIMARY KEY,
full_name TEXT NOT NULL,
phone_whatsapp TEXT NOT NULL,
email TEXT,
notes TEXT,
created_at TEXT NOT NULL DEFAULT (datetime('now'))
);
CREATE TABLE IF NOT EXISTS bookings (
id TEXT PRIMARY KEY,
booking_code TEXT UNIQUE NOT NULL,
service_id TEXT NOT NULL REFERENCES services(id),
client_id TEXT NOT NULL REFERENCES clients(id),
scheduled_at TEXT NOT NULL,
status TEXT NOT NULL DEFAULT 'PENDING_PAYMENT' CHECK (status IN ('PENDING_PAYMENT', 'CONFIRMED', 'CANCELLED', 'EXPIRED', 'NO_SHOW')),
amount_mxn INTEGER NOT NULL,
gcal_event_id TEXT,
expires_at TEXT NOT NULL,
created_at TEXT NOT NULL DEFAULT (datetime('now')),
confirmed_at TEXT
);
CREATE TABLE IF NOT EXISTS payments (
id TEXT PRIMARY KEY,
booking_id TEXT NOT NULL REFERENCES bookings(id),
amount_mxn INTEGER NOT NULL,
payment_method TEXT NOT NULL DEFAULT 'SPEI' CHECK (payment_method IN ('SPEI', 'OXXO', 'CASH')),
status TEXT NOT NULL DEFAULT 'PENDING' CHECK (status IN ('PENDING', 'VERIFIED', 'REJECTED')),
verified_at TEXT,
notes TEXT,
created_at TEXT NOT NULL DEFAULT (datetime('now'))
);
CREATE INDEX IF NOT EXISTS idx_services_slug ON services(slug);
CREATE INDEX IF NOT EXISTS idx_bookings_code ON bookings(booking_code);
CREATE INDEX IF NOT EXISTS idx_bookings_status ON bookings(status);
CREATE INDEX IF NOT EXISTS idx_bookings_scheduled ON bookings(scheduled_at);
CREATE INDEX IF NOT EXISTS idx_clients_phone ON clients(phone_whatsapp);