mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-12-27 13:21:32 +00:00
try to fix combined_transition_tables
This commit is contained in:
parent
0844a7612a
commit
8d1c633378
1 changed files with 7 additions and 27 deletions
|
@ -55,22 +55,14 @@ CREATE PROCEDURE r.create_triggers (table_name text, command text)
|
|||
LANGUAGE plpgsql
|
||||
AS $a$
|
||||
DECLARE
|
||||
-- `PERFORM` isn't used because it doesn't allow `WITH`
|
||||
defs text := $b$
|
||||
-- Delete
|
||||
CREATE FUNCTION r.thing_delete_statement ()
|
||||
RETURNS TRIGGER
|
||||
LANGUAGE plpgsql
|
||||
AS $$
|
||||
DECLARE
|
||||
foo int;
|
||||
BEGIN
|
||||
WITH combined_transition_tables AS (
|
||||
select_old_table
|
||||
),
|
||||
trigger_result AS command
|
||||
SELECT
|
||||
1 INTO foo;
|
||||
delete_command;
|
||||
RETURN NULL;
|
||||
END $$;
|
||||
CREATE TRIGGER delete_statement
|
||||
|
@ -82,15 +74,8 @@ END $$;
|
|||
RETURNS TRIGGER
|
||||
LANGUAGE plpgsql
|
||||
AS $$
|
||||
DECLARE
|
||||
foo int;
|
||||
BEGIN
|
||||
WITH combined_transition_tables AS (
|
||||
select_new_table
|
||||
),
|
||||
trigger_result AS command
|
||||
SELECT
|
||||
1 INTO foo;
|
||||
insert_command;
|
||||
RETURN NULL;
|
||||
END $$;
|
||||
CREATE TRIGGER insert_statement
|
||||
|
@ -102,16 +87,8 @@ END $$;
|
|||
RETURNS TRIGGER
|
||||
LANGUAGE plpgsql
|
||||
AS $$
|
||||
DECLARE
|
||||
foo int;
|
||||
BEGIN
|
||||
WITH combined_transition_tables AS (
|
||||
select_old_table
|
||||
UNION ALL select_new_table
|
||||
),
|
||||
trigger_result AS command
|
||||
SELECT
|
||||
1 INTO foo;
|
||||
update_command;
|
||||
RETURN NULL;
|
||||
END $$;
|
||||
CREATE TRIGGER update_statement
|
||||
|
@ -120,6 +97,10 @@ END $$;
|
|||
EXECUTE FUNCTION r.thing_update_statement ( );
|
||||
$b$;
|
||||
BEGIN
|
||||
-- Couldn't get `combined_transition_tables` to work using CTE
|
||||
defs := replace(defs, 'delete_command', replace(command, 'combined_transition_tables', '(select_old_table) AS combined_transition_tables'));
|
||||
defs := replace(defs, 'insert_command', replace(command, 'combined_transition_tables', '(select_new_table) AS combined_transition_tables'));
|
||||
defs := replace(defs, 'update_command', replace(command, 'combined_transition_tables', '(select_old_table UNION ALL select_new_table) AS combined_transition_tables'));
|
||||
defs := replace(defs, 'select_old_table', $$
|
||||
SELECT
|
||||
-1 AS count_diff, old_table::thing AS thing FROM old_table $$);
|
||||
|
@ -127,7 +108,6 @@ END $$;
|
|||
SELECT
|
||||
1 AS count_diff, new_table::thing AS thing FROM new_table $$);
|
||||
defs := replace(defs, 'thing', table_name);
|
||||
defs := replace(defs, 'command', format('(%s)', command));
|
||||
EXECUTE defs;
|
||||
END
|
||||
$a$;
|
||||
|
|
Loading…
Reference in a new issue