Skip to content

Commit

Permalink
Added table schema checks to linearite demo triggers.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
FindAPattern authored Dec 1, 2024
1 parent 2a70daa commit e0bd9fd
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions demos/linearlite/db/migrations-client/01-create_tables.sql
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,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;
Expand Down Expand Up @@ -223,6 +224,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;
Expand All @@ -240,6 +242,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;
Expand Down

0 comments on commit e0bd9fd

Please sign in to comment.