-- rSpace shared PostgreSQL — per-module schema isolation
-- Each module owns its schema. Modules that don't need a DB skip this.

-- Extensions available to all schemas
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
CREATE EXTENSION IF NOT EXISTS "cube";
CREATE EXTENSION IF NOT EXISTS "earthdistance";

-- Module schemas (created on init, populated by module migrations)
CREATE SCHEMA IF NOT EXISTS rbooks;
CREATE SCHEMA IF NOT EXISTS rcart;
CREATE SCHEMA IF NOT EXISTS providers;
CREATE SCHEMA IF NOT EXISTS rfiles;
CREATE SCHEMA IF NOT EXISTS rforum;
CREATE SCHEMA IF NOT EXISTS rsplat;

-- Grant usage to the rspace user
GRANT ALL ON SCHEMA rbooks TO rspace;
GRANT ALL ON SCHEMA rcart TO rspace;
GRANT ALL ON SCHEMA providers TO rspace;
GRANT ALL ON SCHEMA rfiles TO rspace;
GRANT ALL ON SCHEMA rforum TO rspace;
GRANT ALL ON SCHEMA rsplat TO rspace;
