CREATE DATABASE [DB Name];
DO $$
DECLARE
    db_name text default '[SAME ONE USED ABOVE]';
    username text default '[APP NAME]';
    user_password text default '[MAKE A PASSWORD];
BEGIN
    EXECUTE format('CREATE USER %I WITH PASSWORD %L', username, user_password);

    EXECUTE format('GRANT ALL PRIVILEGES ON DATABASE %I TO %I', db_name, username);
    SET search_path TO db_name, public;

    EXECUTE format('GRANT ALL PRIVILEGES ON SCHEMA public TO %I', username);
    EXECUTE format('GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO %I', username);
    EXECUTE format('GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA public TO %I', username);
    EXECUTE format('ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT ALL ON TABLES TO %I', username);
    EXECUTE format('ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT ALL ON SEQUENCES TO %I', username);
END $$;