DO $$
BEGIN
    IF NOT EXISTS (SELECT 1 FROM pg_roles WHERE rolname = 'quantengine_app') THEN
        CREATE ROLE quantengine_app LOGIN PASSWORD 'CHANGE_ME';
    END IF;
END
$$;

DO $$
BEGIN
    IF NOT EXISTS (SELECT 1 FROM pg_database WHERE datname = 'quantenginedb') THEN
        CREATE DATABASE quantenginedb OWNER quantengine_app;
    END IF;
END
$$;

\connect quantenginedb

CREATE SCHEMA IF NOT EXISTS quantengine AUTHORIZATION quantengine_app;
ALTER SCHEMA quantengine OWNER TO quantengine_app;
GRANT ALL PRIVILEGES ON DATABASE quantenginedb TO quantengine_app;
GRANT USAGE, CREATE ON SCHEMA quantengine TO quantengine_app;
