-- Trading Bot Database Schema Initialization

-- Create schemas
CREATE SCHEMA IF NOT EXISTS trading;
CREATE SCHEMA IF NOT EXISTS strategy;
CREATE SCHEMA IF NOT EXISTS risk;
CREATE SCHEMA IF NOT EXISTS audit;

-- Set search path for the database
ALTER DATABASE trading_bot SET search_path TO trading, strategy, risk, audit, public;

-- Create extensions
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
CREATE EXTENSION IF NOT EXISTS "btree_gin";
CREATE EXTENSION IF NOT EXISTS "pg_stat_statements";

-- Create a read-only user for analytics
CREATE USER trading_reader WITH PASSWORD 'reader_pass_dev';
GRANT CONNECT ON DATABASE trading_bot TO trading_reader;
GRANT USAGE ON SCHEMA trading, strategy, risk, audit TO trading_reader;
