-- =====================================================
-- Claim Guard Database Initialization Script
-- =====================================================

-- Create database if it doesn't exist (handled by POSTGRES_DB env var)
-- But we can create additional databases if needed

-- Enable pgvector extension
CREATE EXTENSION IF NOT EXISTS vector;

-- Enable other useful extensions
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
CREATE EXTENSION IF NOT EXISTS "pg_trgm";
CREATE EXTENSION IF NOT EXISTS "btree_gin";
CREATE EXTENSION IF NOT EXISTS "btree_gist";

-- Create application user if needed (optional)
-- The main user is already created via POSTGRES_USER

-- Set up database permissions
GRANT ALL PRIVILEGES ON DATABASE claim_guard TO postgres;

-- Create schema for application (optional, Prisma will use public by default)
-- CREATE SCHEMA IF NOT EXISTS claim_guard;

-- Log successful initialization
DO $$
BEGIN
    RAISE NOTICE 'Claim Guard database initialized successfully';
    RAISE NOTICE 'pgvector extension: %', (SELECT EXISTS(SELECT 1 FROM pg_extension WHERE extname = 'vector'));
    RAISE NOTICE 'Database ready for Prisma migrations';
END $$;
