-- Initialize Stock Oracle Database
-- This file is automatically executed when PostgreSQL container starts

-- Note: Database is already created by POSTGRES_DB environment variable

-- Create user if not exists (PostgreSQL syntax)
DO $$
BEGIN
   IF NOT EXISTS (SELECT FROM pg_catalog.pg_roles WHERE rolname = 'stockoracle') THEN
      CREATE ROLE stockoracle WITH LOGIN PASSWORD 'stockoracle2024';
   END IF;
END
$$;

-- Grant permissions
GRANT ALL PRIVILEGES ON DATABASE stock_oracle TO stockoracle;

-- Grant schema permissions
GRANT ALL ON SCHEMA public TO stockoracle;
GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO stockoracle;
GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA public TO stockoracle;