merge graphile_worker and postgrest db
ci / build (push) Failing after 8m20s Details

This commit is contained in:
CJ_Clippy 2024-08-04 08:40:13 -08:00
parent 11af3dc87b
commit b3d9035733
3 changed files with 30 additions and 2 deletions

View File

@ -8,7 +8,7 @@ if (!process.env.DATABASE_PASSWORD) throw new Error('DATABASE_PASSWORD is missin
async function main() { async function main() {
const dbConfig = { const dbConfig = {
database: "postgrest", database: "futureporn",
user: "postgres", user: "postgres",
password: process.env.DATABASE_PASSWORD, password: process.env.DATABASE_PASSWORD,
host: 'postgresql-primary.futureporn.svc.cluster.local', host: 'postgresql-primary.futureporn.svc.cluster.local',

View File

@ -0,0 +1,28 @@
-- one trigger function to rule them all @see https://worker.graphile.org/docs/sql-add-job#example-one-trigger-function-to-rule-them-all
CREATE FUNCTION trigger_job() RETURNS trigger AS $$
BEGIN
PERFORM graphile_worker.add_job(TG_ARGV[0], json_build_object(
'schema', TG_TABLE_SCHEMA,
'table', TG_TABLE_NAME,
'op', TG_OP,
'id', (CASE WHEN TG_OP = 'DELETE' THEN OLD.id ELSE NEW.id END)
));
RETURN NEW;
END;
$$ LANGUAGE plpgsql VOLATILE;
-- When a record is created, add a graphile_worker job to start recording
CREATE TRIGGER record
AFTER INSERT ON api.records
FOR EACH ROW
EXECUTE PROCEDURE trigger_job('record');
-- When a record is updated, add a graphile_worker job to update the discord message
CREATE TRIGGER update_discord_message
AFTER UPDATE ON api.records
FOR EACH ROW
EXECUTE PROCEDURE trigger_job('update_discord_message');
-- for more reference, @see https://worker.graphile.org/docs/sql-add-job#example-one-trigger-function-to-rule-them-all

View File

@ -1,7 +1,7 @@
{ {
"name": "@futureporn/migrations", "name": "@futureporn/migrations",
"type": "module", "type": "module",
"version": "0.5.0", "version": "0.6.0",
"description": "", "description": "",
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {