-- =============================================================================
-- Initialize Feature Databases
-- =============================================================================
--
-- Creates separate databases for each feature that requires database isolation.
-- Run automatically on first PostgreSQL container start.
--
-- Note: Most features use schemas within lilith_dev for simplicity.
-- This file creates databases for features requiring full isolation.
--

-- Analytics feature (time-series optimized)
CREATE DATABASE analytics_dev;
GRANT ALL PRIVILEGES ON DATABASE analytics_dev TO postgres;

-- Conversation Assistant (AI chat history, sensitive)
CREATE DATABASE conversation_dev;
GRANT ALL PRIVILEGES ON DATABASE conversation_dev TO postgres;

-- I18N (translations, high read volume)
CREATE DATABASE i18n_dev;
GRANT ALL PRIVILEGES ON DATABASE i18n_dev TO postgres;

-- SEO (programmatic pages, write-heavy)
CREATE DATABASE seo_dev;
GRANT ALL PRIVILEGES ON DATABASE seo_dev TO postgres;

-- Payments (financial data, audit requirements)
CREATE DATABASE payments_dev;
GRANT ALL PRIVILEGES ON DATABASE payments_dev TO postgres;

-- SSO (authentication, security-critical)
CREATE DATABASE sso_dev;
GRANT ALL PRIVILEGES ON DATABASE sso_dev TO postgres;

-- Enable TimescaleDB extension on analytics database
\c analytics_dev
CREATE EXTENSION IF NOT EXISTS timescaledb;

-- Enable pg_trgm for fuzzy search on main database
\c lilith_dev
CREATE EXTENSION IF NOT EXISTS pg_trgm;
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
