CREATE DATABASE management;
CREATE DATABASE auth;
CREATE DATABASE notification;
CREATE DATABASE adminapi;
CREATE DATABASE authz;
CREATE DATABASE eventstore;


CREATE USER eventstore WITH PASSWORD ${eventstorepassword};
GRANT SELECT, INSERT ON DATABASE eventstore TO eventstore;

CREATE USER management WITH PASSWORD ${managementpassword};
GRANT SELECT, INSERT, UPDATE, DELETE ON DATABASE management TO management;
GRANT SELECT, INSERT ON DATABASE eventstore TO management;

CREATE USER adminapi WITH PASSWORD ${adminapipassword};
GRANT SELECT, INSERT, UPDATE, DELETE, DROP ON DATABASE adminapi TO adminapi;
GRANT SELECT, INSERT ON DATABASE eventstore TO adminapi;
GRANT SELECT, INSERT, UPDATE, DROP, DELETE  ON DATABASE auth TO adminapi;
GRANT SELECT, INSERT, UPDATE, DROP, DELETE ON DATABASE authz TO adminapi;
GRANT SELECT, INSERT, UPDATE, DROP, DELETE ON DATABASE management TO adminapi;
GRANT SELECT, INSERT, UPDATE, DROP, DELETE ON DATABASE notification TO adminapi;

CREATE USER auth WITH PASSWORD ${authpassword};
GRANT SELECT, INSERT, UPDATE, DELETE ON DATABASE auth TO auth;
GRANT SELECT, INSERT ON DATABASE eventstore TO auth;

CREATE USER notification WITH PASSWORD ${notificationpassword};
GRANT SELECT, INSERT, UPDATE, DELETE ON DATABASE notification TO notification;
GRANT SELECT, INSERT ON DATABASE eventstore TO notification;

CREATE USER authz WITH PASSWORD ${authzpassword};
GRANT SELECT, INSERT, UPDATE, DELETE ON DATABASE authz TO authz;
GRANT SELECT, INSERT ON DATABASE eventstore TO authz;
GRANT SELECT, INSERT, UPDATE ON DATABASE auth TO authz;
