From 85fec2c37e454f0ab98deeba5b563a78543bb48a Mon Sep 17 00:00:00 2001 From: ledouxm Date: Mon, 8 Jul 2024 14:33:35 +0200 Subject: [PATCH] fix: "clause"."hidden" --- db/migrations/04-add_chips_table.sql | 1 - db/migrations/903-fix_clausev1.sql | 1 + .../src/generated/client/migrations.ts | 23 +++++++++++++--- .../src/generated/client/pg-migrations.ts | 27 ++++++++++++++++--- 4 files changed, 43 insertions(+), 9 deletions(-) create mode 100644 db/migrations/903-fix_clausev1.sql diff --git a/db/migrations/04-add_chips_table.sql b/db/migrations/04-add_chips_table.sql index 6736581f..02846c34 100644 --- a/db/migrations/04-add_chips_table.sql +++ b/db/migrations/04-add_chips_table.sql @@ -4,7 +4,6 @@ CREATE TABLE clause( ,value text NOT NULL ,udap_id text ,text text NOT NULL - ,hidden boolean , PRIMARY KEY (key, value, udap_id) ); diff --git a/db/migrations/903-fix_clausev1.sql b/db/migrations/903-fix_clausev1.sql new file mode 100644 index 00000000..497e12de --- /dev/null +++ b/db/migrations/903-fix_clausev1.sql @@ -0,0 +1 @@ +ALTER TABLE clause ADD COLUMN "hidden" BOOLEAN; \ No newline at end of file diff --git a/packages/electric-client/src/generated/client/migrations.ts b/packages/electric-client/src/generated/client/migrations.ts index a72a1516..4c7f04b8 100644 --- a/packages/electric-client/src/generated/client/migrations.ts +++ b/packages/electric-client/src/generated/client/migrations.ts @@ -67,16 +67,16 @@ export default [ }, { "statements": [ - "CREATE TABLE \"clause\" (\n \"key\" TEXT NOT NULL,\n \"value\" TEXT NOT NULL,\n \"udap_id\" TEXT NOT NULL,\n \"text\" TEXT NOT NULL,\n \"hidden\" INTEGER,\n CONSTRAINT \"clause_pkey\" PRIMARY KEY (\"key\", \"value\", \"udap_id\")\n) WITHOUT ROWID;\n", + "CREATE TABLE \"clause\" (\n \"key\" TEXT NOT NULL,\n \"value\" TEXT NOT NULL,\n \"udap_id\" TEXT NOT NULL,\n \"text\" TEXT NOT NULL,\n CONSTRAINT \"clause_pkey\" PRIMARY KEY (\"key\", \"value\", \"udap_id\")\n) WITHOUT ROWID;\n", "INSERT OR IGNORE INTO _electric_trigger_settings (namespace, tablename, flag) VALUES ('main', 'clause', 1);", "DROP TRIGGER IF EXISTS update_ensure_main_clause_primarykey;", "CREATE TRIGGER update_ensure_main_clause_primarykey\n BEFORE UPDATE ON \"main\".\"clause\"\nBEGIN\n SELECT\n CASE\n WHEN old.\"key\" != new.\"key\" THEN\n \t\tRAISE (ABORT, 'cannot change the value of column key as it belongs to the primary key')\n WHEN old.\"udap_id\" != new.\"udap_id\" THEN\n \t\tRAISE (ABORT, 'cannot change the value of column udap_id as it belongs to the primary key')\n WHEN old.\"value\" != new.\"value\" THEN\n \t\tRAISE (ABORT, 'cannot change the value of column value as it belongs to the primary key')\n END;\nEND;", "DROP TRIGGER IF EXISTS insert_main_clause_into_oplog;", - "CREATE TRIGGER insert_main_clause_into_oplog\n AFTER INSERT ON \"main\".\"clause\"\n WHEN 1 = (SELECT flag from _electric_trigger_settings WHERE namespace = 'main' AND tablename = 'clause')\nBEGIN\n INSERT INTO _electric_oplog (namespace, tablename, optype, primaryKey, newRow, oldRow, timestamp)\n VALUES ('main', 'clause', 'INSERT', json_patch('{}', json_object('key', new.\"key\", 'udap_id', new.\"udap_id\", 'value', new.\"value\")), json_object('hidden', new.\"hidden\", 'key', new.\"key\", 'text', new.\"text\", 'udap_id', new.\"udap_id\", 'value', new.\"value\"), NULL, NULL);\nEND;", + "CREATE TRIGGER insert_main_clause_into_oplog\n AFTER INSERT ON \"main\".\"clause\"\n WHEN 1 = (SELECT flag from _electric_trigger_settings WHERE namespace = 'main' AND tablename = 'clause')\nBEGIN\n INSERT INTO _electric_oplog (namespace, tablename, optype, primaryKey, newRow, oldRow, timestamp)\n VALUES ('main', 'clause', 'INSERT', json_patch('{}', json_object('key', new.\"key\", 'udap_id', new.\"udap_id\", 'value', new.\"value\")), json_object('key', new.\"key\", 'text', new.\"text\", 'udap_id', new.\"udap_id\", 'value', new.\"value\"), NULL, NULL);\nEND;", "DROP TRIGGER IF EXISTS update_main_clause_into_oplog;", - "CREATE TRIGGER update_main_clause_into_oplog\n AFTER UPDATE ON \"main\".\"clause\"\n WHEN 1 = (SELECT flag from _electric_trigger_settings WHERE namespace = 'main' AND tablename = 'clause')\nBEGIN\n INSERT INTO _electric_oplog (namespace, tablename, optype, primaryKey, newRow, oldRow, timestamp)\n VALUES ('main', 'clause', 'UPDATE', json_patch('{}', json_object('key', new.\"key\", 'udap_id', new.\"udap_id\", 'value', new.\"value\")), json_object('hidden', new.\"hidden\", 'key', new.\"key\", 'text', new.\"text\", 'udap_id', new.\"udap_id\", 'value', new.\"value\"), json_object('hidden', old.\"hidden\", 'key', old.\"key\", 'text', old.\"text\", 'udap_id', old.\"udap_id\", 'value', old.\"value\"), NULL);\nEND;", + "CREATE TRIGGER update_main_clause_into_oplog\n AFTER UPDATE ON \"main\".\"clause\"\n WHEN 1 = (SELECT flag from _electric_trigger_settings WHERE namespace = 'main' AND tablename = 'clause')\nBEGIN\n INSERT INTO _electric_oplog (namespace, tablename, optype, primaryKey, newRow, oldRow, timestamp)\n VALUES ('main', 'clause', 'UPDATE', json_patch('{}', json_object('key', new.\"key\", 'udap_id', new.\"udap_id\", 'value', new.\"value\")), json_object('key', new.\"key\", 'text', new.\"text\", 'udap_id', new.\"udap_id\", 'value', new.\"value\"), json_object('key', old.\"key\", 'text', old.\"text\", 'udap_id', old.\"udap_id\", 'value', old.\"value\"), NULL);\nEND;", "DROP TRIGGER IF EXISTS delete_main_clause_into_oplog;", - "CREATE TRIGGER delete_main_clause_into_oplog\n AFTER DELETE ON \"main\".\"clause\"\n WHEN 1 = (SELECT flag from _electric_trigger_settings WHERE namespace = 'main' AND tablename = 'clause')\nBEGIN\n INSERT INTO _electric_oplog (namespace, tablename, optype, primaryKey, newRow, oldRow, timestamp)\n VALUES ('main', 'clause', 'DELETE', json_patch('{}', json_object('key', old.\"key\", 'udap_id', old.\"udap_id\", 'value', old.\"value\")), NULL, json_object('hidden', old.\"hidden\", 'key', old.\"key\", 'text', old.\"text\", 'udap_id', old.\"udap_id\", 'value', old.\"value\"), NULL);\nEND;" + "CREATE TRIGGER delete_main_clause_into_oplog\n AFTER DELETE ON \"main\".\"clause\"\n WHEN 1 = (SELECT flag from _electric_trigger_settings WHERE namespace = 'main' AND tablename = 'clause')\nBEGIN\n INSERT INTO _electric_oplog (namespace, tablename, optype, primaryKey, newRow, oldRow, timestamp)\n VALUES ('main', 'clause', 'DELETE', json_patch('{}', json_object('key', old.\"key\", 'udap_id', old.\"udap_id\", 'value', old.\"value\")), NULL, json_object('key', old.\"key\", 'text', old.\"text\", 'udap_id', old.\"udap_id\", 'value', old.\"value\"), NULL);\nEND;" ], "version": "4" }, @@ -147,5 +147,20 @@ export default [ "CREATE TRIGGER delete_main_clause_v2_into_oplog\n AFTER DELETE ON \"main\".\"clause_v2\"\n WHEN 1 = (SELECT flag from _electric_trigger_settings WHERE namespace = 'main' AND tablename = 'clause_v2')\nBEGIN\n INSERT INTO _electric_oplog (namespace, tablename, optype, primaryKey, newRow, oldRow, timestamp)\n VALUES ('main', 'clause_v2', 'DELETE', json_patch('{}', json_object('id', old.\"id\")), NULL, json_object('id', old.\"id\", 'key', old.\"key\", 'position', old.\"position\", 'text', old.\"text\", 'udap_id', old.\"udap_id\", 'value', old.\"value\"), NULL);\nEND;" ], "version": "902" + }, + { + "statements": [ + "ALTER TABLE \"clause\" ADD COLUMN \"hidden\" INTEGER;\n", + "INSERT OR IGNORE INTO _electric_trigger_settings (namespace, tablename, flag) VALUES ('main', 'clause', 1);", + "DROP TRIGGER IF EXISTS update_ensure_main_clause_primarykey;", + "CREATE TRIGGER update_ensure_main_clause_primarykey\n BEFORE UPDATE ON \"main\".\"clause\"\nBEGIN\n SELECT\n CASE\n WHEN old.\"key\" != new.\"key\" THEN\n \t\tRAISE (ABORT, 'cannot change the value of column key as it belongs to the primary key')\n WHEN old.\"udap_id\" != new.\"udap_id\" THEN\n \t\tRAISE (ABORT, 'cannot change the value of column udap_id as it belongs to the primary key')\n WHEN old.\"value\" != new.\"value\" THEN\n \t\tRAISE (ABORT, 'cannot change the value of column value as it belongs to the primary key')\n END;\nEND;", + "DROP TRIGGER IF EXISTS insert_main_clause_into_oplog;", + "CREATE TRIGGER insert_main_clause_into_oplog\n AFTER INSERT ON \"main\".\"clause\"\n WHEN 1 = (SELECT flag from _electric_trigger_settings WHERE namespace = 'main' AND tablename = 'clause')\nBEGIN\n INSERT INTO _electric_oplog (namespace, tablename, optype, primaryKey, newRow, oldRow, timestamp)\n VALUES ('main', 'clause', 'INSERT', json_patch('{}', json_object('key', new.\"key\", 'udap_id', new.\"udap_id\", 'value', new.\"value\")), json_object('hidden', new.\"hidden\", 'key', new.\"key\", 'text', new.\"text\", 'udap_id', new.\"udap_id\", 'value', new.\"value\"), NULL, NULL);\nEND;", + "DROP TRIGGER IF EXISTS update_main_clause_into_oplog;", + "CREATE TRIGGER update_main_clause_into_oplog\n AFTER UPDATE ON \"main\".\"clause\"\n WHEN 1 = (SELECT flag from _electric_trigger_settings WHERE namespace = 'main' AND tablename = 'clause')\nBEGIN\n INSERT INTO _electric_oplog (namespace, tablename, optype, primaryKey, newRow, oldRow, timestamp)\n VALUES ('main', 'clause', 'UPDATE', json_patch('{}', json_object('key', new.\"key\", 'udap_id', new.\"udap_id\", 'value', new.\"value\")), json_object('hidden', new.\"hidden\", 'key', new.\"key\", 'text', new.\"text\", 'udap_id', new.\"udap_id\", 'value', new.\"value\"), json_object('hidden', old.\"hidden\", 'key', old.\"key\", 'text', old.\"text\", 'udap_id', old.\"udap_id\", 'value', old.\"value\"), NULL);\nEND;", + "DROP TRIGGER IF EXISTS delete_main_clause_into_oplog;", + "CREATE TRIGGER delete_main_clause_into_oplog\n AFTER DELETE ON \"main\".\"clause\"\n WHEN 1 = (SELECT flag from _electric_trigger_settings WHERE namespace = 'main' AND tablename = 'clause')\nBEGIN\n INSERT INTO _electric_oplog (namespace, tablename, optype, primaryKey, newRow, oldRow, timestamp)\n VALUES ('main', 'clause', 'DELETE', json_patch('{}', json_object('key', old.\"key\", 'udap_id', old.\"udap_id\", 'value', old.\"value\")), NULL, json_object('hidden', old.\"hidden\", 'key', old.\"key\", 'text', old.\"text\", 'udap_id', old.\"udap_id\", 'value', old.\"value\"), NULL);\nEND;" + ], + "version": "903" } ] \ No newline at end of file diff --git a/packages/electric-client/src/generated/client/pg-migrations.ts b/packages/electric-client/src/generated/client/pg-migrations.ts index dfba45ec..953e0545 100644 --- a/packages/electric-client/src/generated/client/pg-migrations.ts +++ b/packages/electric-client/src/generated/client/pg-migrations.ts @@ -91,19 +91,19 @@ export default [ }, { "statements": [ - "CREATE TABLE clause (\n key text NOT NULL,\n value text NOT NULL,\n udap_id text NOT NULL,\n text text NOT NULL,\n hidden boolean,\n CONSTRAINT clause_pkey PRIMARY KEY (key, value, udap_id)\n)", + "CREATE TABLE clause (\n key text NOT NULL,\n value text NOT NULL,\n udap_id text NOT NULL,\n text text NOT NULL,\n CONSTRAINT clause_pkey PRIMARY KEY (key, value, udap_id)\n)", "INSERT INTO \"public\".\"_electric_trigger_settings\" (\"namespace\", \"tablename\", \"flag\")\n VALUES ('public', 'clause', 1)\n ON CONFLICT DO NOTHING;", "DROP TRIGGER IF EXISTS update_ensure_public_clause_primarykey ON \"public\".\"clause\";", "CREATE OR REPLACE FUNCTION update_ensure_public_clause_primarykey_function()\nRETURNS TRIGGER AS $$\nBEGIN\n IF OLD.\"key\" IS DISTINCT FROM NEW.\"key\" THEN\n RAISE EXCEPTION 'Cannot change the value of column key as it belongs to the primary key';\n END IF;\n IF OLD.\"udap_id\" IS DISTINCT FROM NEW.\"udap_id\" THEN\n RAISE EXCEPTION 'Cannot change the value of column udap_id as it belongs to the primary key';\n END IF;\n IF OLD.\"value\" IS DISTINCT FROM NEW.\"value\" THEN\n RAISE EXCEPTION 'Cannot change the value of column value as it belongs to the primary key';\n END IF;\n RETURN NEW;\nEND;\n$$ LANGUAGE plpgsql;", "CREATE TRIGGER update_ensure_public_clause_primarykey\n BEFORE UPDATE ON \"public\".\"clause\"\n FOR EACH ROW\n EXECUTE FUNCTION update_ensure_public_clause_primarykey_function();", "DROP TRIGGER IF EXISTS insert_public_clause_into_oplog ON \"public\".\"clause\";", - " CREATE OR REPLACE FUNCTION insert_public_clause_into_oplog_function()\n RETURNS TRIGGER AS $$\n BEGIN\n DECLARE\n flag_value INTEGER;\n BEGIN\n -- Get the flag value from _electric_trigger_settings\n SELECT flag INTO flag_value FROM \"public\"._electric_trigger_settings WHERE namespace = 'public' AND tablename = 'clause';\n\n IF flag_value = 1 THEN\n -- Insert into _electric_oplog\n INSERT INTO \"public\"._electric_oplog (namespace, tablename, optype, \"primaryKey\", \"newRow\", \"oldRow\", timestamp)\n VALUES (\n 'public',\n 'clause',\n 'INSERT',\n json_strip_nulls(json_build_object('key', new.\"key\", 'udap_id', new.\"udap_id\", 'value', new.\"value\")),\n jsonb_build_object('hidden', new.\"hidden\", 'key', new.\"key\", 'text', new.\"text\", 'udap_id', new.\"udap_id\", 'value', new.\"value\"),\n NULL,\n NULL\n );\n END IF;\n\n RETURN NEW;\n END;\n END;\n $$ LANGUAGE plpgsql;", + " CREATE OR REPLACE FUNCTION insert_public_clause_into_oplog_function()\n RETURNS TRIGGER AS $$\n BEGIN\n DECLARE\n flag_value INTEGER;\n BEGIN\n -- Get the flag value from _electric_trigger_settings\n SELECT flag INTO flag_value FROM \"public\"._electric_trigger_settings WHERE namespace = 'public' AND tablename = 'clause';\n\n IF flag_value = 1 THEN\n -- Insert into _electric_oplog\n INSERT INTO \"public\"._electric_oplog (namespace, tablename, optype, \"primaryKey\", \"newRow\", \"oldRow\", timestamp)\n VALUES (\n 'public',\n 'clause',\n 'INSERT',\n json_strip_nulls(json_build_object('key', new.\"key\", 'udap_id', new.\"udap_id\", 'value', new.\"value\")),\n jsonb_build_object('key', new.\"key\", 'text', new.\"text\", 'udap_id', new.\"udap_id\", 'value', new.\"value\"),\n NULL,\n NULL\n );\n END IF;\n\n RETURN NEW;\n END;\n END;\n $$ LANGUAGE plpgsql;", "CREATE TRIGGER insert_public_clause_into_oplog\n AFTER INSERT ON \"public\".\"clause\"\n FOR EACH ROW\n EXECUTE FUNCTION insert_public_clause_into_oplog_function();", "DROP TRIGGER IF EXISTS update_public_clause_into_oplog ON \"public\".\"clause\";", - " CREATE OR REPLACE FUNCTION update_public_clause_into_oplog_function()\n RETURNS TRIGGER AS $$\n BEGIN\n DECLARE\n flag_value INTEGER;\n BEGIN\n -- Get the flag value from _electric_trigger_settings\n SELECT flag INTO flag_value FROM \"public\"._electric_trigger_settings WHERE namespace = 'public' AND tablename = 'clause';\n\n IF flag_value = 1 THEN\n -- Insert into _electric_oplog\n INSERT INTO \"public\"._electric_oplog (namespace, tablename, optype, \"primaryKey\", \"newRow\", \"oldRow\", timestamp)\n VALUES (\n 'public',\n 'clause',\n 'UPDATE',\n json_strip_nulls(json_build_object('key', new.\"key\", 'udap_id', new.\"udap_id\", 'value', new.\"value\")),\n jsonb_build_object('hidden', new.\"hidden\", 'key', new.\"key\", 'text', new.\"text\", 'udap_id', new.\"udap_id\", 'value', new.\"value\"),\n jsonb_build_object('hidden', old.\"hidden\", 'key', old.\"key\", 'text', old.\"text\", 'udap_id', old.\"udap_id\", 'value', old.\"value\"),\n NULL\n );\n END IF;\n\n RETURN NEW;\n END;\n END;\n $$ LANGUAGE plpgsql;", + " CREATE OR REPLACE FUNCTION update_public_clause_into_oplog_function()\n RETURNS TRIGGER AS $$\n BEGIN\n DECLARE\n flag_value INTEGER;\n BEGIN\n -- Get the flag value from _electric_trigger_settings\n SELECT flag INTO flag_value FROM \"public\"._electric_trigger_settings WHERE namespace = 'public' AND tablename = 'clause';\n\n IF flag_value = 1 THEN\n -- Insert into _electric_oplog\n INSERT INTO \"public\"._electric_oplog (namespace, tablename, optype, \"primaryKey\", \"newRow\", \"oldRow\", timestamp)\n VALUES (\n 'public',\n 'clause',\n 'UPDATE',\n json_strip_nulls(json_build_object('key', new.\"key\", 'udap_id', new.\"udap_id\", 'value', new.\"value\")),\n jsonb_build_object('key', new.\"key\", 'text', new.\"text\", 'udap_id', new.\"udap_id\", 'value', new.\"value\"),\n jsonb_build_object('key', old.\"key\", 'text', old.\"text\", 'udap_id', old.\"udap_id\", 'value', old.\"value\"),\n NULL\n );\n END IF;\n\n RETURN NEW;\n END;\n END;\n $$ LANGUAGE plpgsql;", "CREATE TRIGGER update_public_clause_into_oplog\n AFTER UPDATE ON \"public\".\"clause\"\n FOR EACH ROW\n EXECUTE FUNCTION update_public_clause_into_oplog_function();", "DROP TRIGGER IF EXISTS delete_public_clause_into_oplog ON \"public\".\"clause\";", - " CREATE OR REPLACE FUNCTION delete_public_clause_into_oplog_function()\n RETURNS TRIGGER AS $$\n BEGIN\n DECLARE\n flag_value INTEGER;\n BEGIN\n -- Get the flag value from _electric_trigger_settings\n SELECT flag INTO flag_value FROM \"public\"._electric_trigger_settings WHERE namespace = 'public' AND tablename = 'clause';\n\n IF flag_value = 1 THEN\n -- Insert into _electric_oplog\n INSERT INTO \"public\"._electric_oplog (namespace, tablename, optype, \"primaryKey\", \"newRow\", \"oldRow\", timestamp)\n VALUES (\n 'public',\n 'clause',\n 'DELETE',\n json_strip_nulls(json_build_object('key', old.\"key\", 'udap_id', old.\"udap_id\", 'value', old.\"value\")),\n NULL,\n jsonb_build_object('hidden', old.\"hidden\", 'key', old.\"key\", 'text', old.\"text\", 'udap_id', old.\"udap_id\", 'value', old.\"value\"),\n NULL\n );\n END IF;\n\n RETURN NEW;\n END;\n END;\n $$ LANGUAGE plpgsql;", + " CREATE OR REPLACE FUNCTION delete_public_clause_into_oplog_function()\n RETURNS TRIGGER AS $$\n BEGIN\n DECLARE\n flag_value INTEGER;\n BEGIN\n -- Get the flag value from _electric_trigger_settings\n SELECT flag INTO flag_value FROM \"public\"._electric_trigger_settings WHERE namespace = 'public' AND tablename = 'clause';\n\n IF flag_value = 1 THEN\n -- Insert into _electric_oplog\n INSERT INTO \"public\"._electric_oplog (namespace, tablename, optype, \"primaryKey\", \"newRow\", \"oldRow\", timestamp)\n VALUES (\n 'public',\n 'clause',\n 'DELETE',\n json_strip_nulls(json_build_object('key', old.\"key\", 'udap_id', old.\"udap_id\", 'value', old.\"value\")),\n NULL,\n jsonb_build_object('key', old.\"key\", 'text', old.\"text\", 'udap_id', old.\"udap_id\", 'value', old.\"value\"),\n NULL\n );\n END IF;\n\n RETURN NEW;\n END;\n END;\n $$ LANGUAGE plpgsql;", "CREATE TRIGGER delete_public_clause_into_oplog\n AFTER DELETE ON \"public\".\"clause\"\n FOR EACH ROW\n EXECUTE FUNCTION delete_public_clause_into_oplog_function();" ], "version": "4" @@ -195,5 +195,24 @@ export default [ "CREATE TRIGGER delete_public_clause_v2_into_oplog\n AFTER DELETE ON \"public\".\"clause_v2\"\n FOR EACH ROW\n EXECUTE FUNCTION delete_public_clause_v2_into_oplog_function();" ], "version": "902" + }, + { + "statements": [ + "ALTER TABLE clause ADD COLUMN \"hidden\" BOOLEAN", + "INSERT INTO \"public\".\"_electric_trigger_settings\" (\"namespace\", \"tablename\", \"flag\")\n VALUES ('public', 'clause', 1)\n ON CONFLICT DO NOTHING;", + "DROP TRIGGER IF EXISTS update_ensure_public_clause_primarykey ON \"public\".\"clause\";", + "CREATE OR REPLACE FUNCTION update_ensure_public_clause_primarykey_function()\nRETURNS TRIGGER AS $$\nBEGIN\n IF OLD.\"key\" IS DISTINCT FROM NEW.\"key\" THEN\n RAISE EXCEPTION 'Cannot change the value of column key as it belongs to the primary key';\n END IF;\n IF OLD.\"udap_id\" IS DISTINCT FROM NEW.\"udap_id\" THEN\n RAISE EXCEPTION 'Cannot change the value of column udap_id as it belongs to the primary key';\n END IF;\n IF OLD.\"value\" IS DISTINCT FROM NEW.\"value\" THEN\n RAISE EXCEPTION 'Cannot change the value of column value as it belongs to the primary key';\n END IF;\n RETURN NEW;\nEND;\n$$ LANGUAGE plpgsql;", + "CREATE TRIGGER update_ensure_public_clause_primarykey\n BEFORE UPDATE ON \"public\".\"clause\"\n FOR EACH ROW\n EXECUTE FUNCTION update_ensure_public_clause_primarykey_function();", + "DROP TRIGGER IF EXISTS insert_public_clause_into_oplog ON \"public\".\"clause\";", + " CREATE OR REPLACE FUNCTION insert_public_clause_into_oplog_function()\n RETURNS TRIGGER AS $$\n BEGIN\n DECLARE\n flag_value INTEGER;\n BEGIN\n -- Get the flag value from _electric_trigger_settings\n SELECT flag INTO flag_value FROM \"public\"._electric_trigger_settings WHERE namespace = 'public' AND tablename = 'clause';\n\n IF flag_value = 1 THEN\n -- Insert into _electric_oplog\n INSERT INTO \"public\"._electric_oplog (namespace, tablename, optype, \"primaryKey\", \"newRow\", \"oldRow\", timestamp)\n VALUES (\n 'public',\n 'clause',\n 'INSERT',\n json_strip_nulls(json_build_object('key', new.\"key\", 'udap_id', new.\"udap_id\", 'value', new.\"value\")),\n jsonb_build_object('hidden', new.\"hidden\", 'key', new.\"key\", 'text', new.\"text\", 'udap_id', new.\"udap_id\", 'value', new.\"value\"),\n NULL,\n NULL\n );\n END IF;\n\n RETURN NEW;\n END;\n END;\n $$ LANGUAGE plpgsql;", + "CREATE TRIGGER insert_public_clause_into_oplog\n AFTER INSERT ON \"public\".\"clause\"\n FOR EACH ROW\n EXECUTE FUNCTION insert_public_clause_into_oplog_function();", + "DROP TRIGGER IF EXISTS update_public_clause_into_oplog ON \"public\".\"clause\";", + " CREATE OR REPLACE FUNCTION update_public_clause_into_oplog_function()\n RETURNS TRIGGER AS $$\n BEGIN\n DECLARE\n flag_value INTEGER;\n BEGIN\n -- Get the flag value from _electric_trigger_settings\n SELECT flag INTO flag_value FROM \"public\"._electric_trigger_settings WHERE namespace = 'public' AND tablename = 'clause';\n\n IF flag_value = 1 THEN\n -- Insert into _electric_oplog\n INSERT INTO \"public\"._electric_oplog (namespace, tablename, optype, \"primaryKey\", \"newRow\", \"oldRow\", timestamp)\n VALUES (\n 'public',\n 'clause',\n 'UPDATE',\n json_strip_nulls(json_build_object('key', new.\"key\", 'udap_id', new.\"udap_id\", 'value', new.\"value\")),\n jsonb_build_object('hidden', new.\"hidden\", 'key', new.\"key\", 'text', new.\"text\", 'udap_id', new.\"udap_id\", 'value', new.\"value\"),\n jsonb_build_object('hidden', old.\"hidden\", 'key', old.\"key\", 'text', old.\"text\", 'udap_id', old.\"udap_id\", 'value', old.\"value\"),\n NULL\n );\n END IF;\n\n RETURN NEW;\n END;\n END;\n $$ LANGUAGE plpgsql;", + "CREATE TRIGGER update_public_clause_into_oplog\n AFTER UPDATE ON \"public\".\"clause\"\n FOR EACH ROW\n EXECUTE FUNCTION update_public_clause_into_oplog_function();", + "DROP TRIGGER IF EXISTS delete_public_clause_into_oplog ON \"public\".\"clause\";", + " CREATE OR REPLACE FUNCTION delete_public_clause_into_oplog_function()\n RETURNS TRIGGER AS $$\n BEGIN\n DECLARE\n flag_value INTEGER;\n BEGIN\n -- Get the flag value from _electric_trigger_settings\n SELECT flag INTO flag_value FROM \"public\"._electric_trigger_settings WHERE namespace = 'public' AND tablename = 'clause';\n\n IF flag_value = 1 THEN\n -- Insert into _electric_oplog\n INSERT INTO \"public\"._electric_oplog (namespace, tablename, optype, \"primaryKey\", \"newRow\", \"oldRow\", timestamp)\n VALUES (\n 'public',\n 'clause',\n 'DELETE',\n json_strip_nulls(json_build_object('key', old.\"key\", 'udap_id', old.\"udap_id\", 'value', old.\"value\")),\n NULL,\n jsonb_build_object('hidden', old.\"hidden\", 'key', old.\"key\", 'text', old.\"text\", 'udap_id', old.\"udap_id\", 'value', old.\"value\"),\n NULL\n );\n END IF;\n\n RETURN NEW;\n END;\n END;\n $$ LANGUAGE plpgsql;", + "CREATE TRIGGER delete_public_clause_into_oplog\n AFTER DELETE ON \"public\".\"clause\"\n FOR EACH ROW\n EXECUTE FUNCTION delete_public_clause_into_oplog_function();" + ], + "version": "903" } ] \ No newline at end of file