-- Create database for integration service
CREATE DATABASE self_serve_integration;

-- Connect to the integration database
\c self_serve_integration;

-- Create extensions if they don't exist
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";

-- Grant permissions to the self_serve user
GRANT ALL PRIVILEGES ON DATABASE self_serve_integration TO self_serve;
GRANT ALL PRIVILEGES ON SCHEMA public TO self_serve;
GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO self_serve;
GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA public TO self_serve;

-- Set default privileges for future objects
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT ALL ON TABLES TO self_serve;
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT ALL ON SEQUENCES TO self_serve;
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT ALL ON FUNCTIONS TO self_serve;
