From d2e5ec46607bcb71818befc50e4838cbc73c7695 Mon Sep 17 00:00:00 2001 From: FindAPattern Date: Tue, 3 Dec 2024 11:17:41 -0500 Subject: [PATCH] Added table schema checks to linearite demo triggers. (#449) * Swap to postgres.js so compatible with CF Workers * Added table schema checks to linearite demo triggers. I ran into an issue using these triggers on a table with the same name as a table in another schema. Adding table schema checks fixes the issue. --------- Co-authored-by: Sam Willis --- demos/linearlite/db/migrations-client/01-create_tables.sql | 3 +++ 1 file changed, 3 insertions(+) diff --git a/demos/linearlite/db/migrations-client/01-create_tables.sql b/demos/linearlite/db/migrations-client/01-create_tables.sql index 7129fac7..c0a5c1e4 100644 --- a/demos/linearlite/db/migrations-client/01-create_tables.sql +++ b/demos/linearlite/db/migrations-client/01-create_tables.sql @@ -122,6 +122,7 @@ BEGIN FOR col_name IN SELECT column_name FROM information_schema.columns WHERE table_name = TG_TABLE_NAME AND + table_schema = TG_TABLE_SCHEMA AND column_name NOT IN ('id', 'synced', 'modified_columns', 'backup', 'deleted', 'new', 'sent_to_server', 'search_vector') LOOP EXECUTE format('SELECT $1.%I', col_name) USING NEW INTO new_value; EXECUTE format('SELECT %I FROM %I WHERE id = $1', col_name, TG_TABLE_NAME) USING NEW.id INTO old_value; @@ -207,6 +208,7 @@ BEGIN FOR column_name IN SELECT columns.column_name FROM information_schema.columns WHERE columns.table_name = TG_TABLE_NAME + AND columns.table_schema = TG_TABLE_SCHEMA AND columns.column_name NOT IN ('id', 'synced', 'modified_columns', 'backup', 'deleted', 'new', 'sent_to_server', 'search_vector') LOOP IF column_name != ANY(OLD.modified_columns) THEN EXECUTE format('SELECT ($1).%I', column_name) USING NEW INTO new_value; @@ -224,6 +226,7 @@ BEGIN FOR column_name IN SELECT columns.column_name FROM information_schema.columns WHERE columns.table_name = TG_TABLE_NAME + AND columns.table_schema = TG_TABLE_SCHEMA AND columns.column_name NOT IN ('id', 'synced', 'modified_columns', 'backup', 'deleted', 'new', 'sent_to_server', 'search_vector') LOOP EXECUTE format('SELECT ($1).%I', column_name) USING NEW INTO new_value; EXECUTE format('SELECT ($1).%I', column_name) USING OLD INTO old_value;