fp/services/migrations/migrations/00001_create.sql

27 lines
982 B
SQL

-- api schema, which houses all the tables for api endpoints
-- example: api.discord_interactions becomes accessible at localhost:9000/discord_interactions
CREATE schema api;
-- authenticator is the role which can "impersonate" other users.
CREATE ROLE authenticator LOGIN NOINHERIT NOCREATEDB NOCREATEROLE NOSUPERUSER;
-- web_anon is the role assigned to anonymous web requests
CREATE ROLE web_anon NOLOGIN;
-- schema for @futureporn/capture and @futureporn/bot
CREATE TABLE api.discord_interactions (
id int PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
discord_message_id text NOT NULL,
capture_job_id text NOT NULL
);
-- roles & permissions for our backend automation user
CREATE ROLE automation NOLOGIN;
GRANT automation TO authenticator;
GRANT usage ON SCHEMA api TO automation;
GRANT all ON api.discord_interactions TO automation;
-- role & permissions for web_anon web user
GRANT usage on schema api TO web_anon;
GRANT SELECT ON api.discord_interactions TO web_anon;