mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-11-25 13:51:19 +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
|
LANGUAGE plpgsql
|
||||||
AS $a$
|
AS $a$
|
||||||
DECLARE
|
DECLARE
|
||||||
-- `PERFORM` isn't used because it doesn't allow `WITH`
|
|
||||||
defs text := $b$
|
defs text := $b$
|
||||||
-- Delete
|
-- Delete
|
||||||
CREATE FUNCTION r.thing_delete_statement ()
|
CREATE FUNCTION r.thing_delete_statement ()
|
||||||
RETURNS TRIGGER
|
RETURNS TRIGGER
|
||||||
LANGUAGE plpgsql
|
LANGUAGE plpgsql
|
||||||
AS $$
|
AS $$
|
||||||
DECLARE
|
|
||||||
foo int;
|
|
||||||
BEGIN
|
BEGIN
|
||||||
WITH combined_transition_tables AS (
|
delete_command;
|
||||||
select_old_table
|
|
||||||
),
|
|
||||||
trigger_result AS command
|
|
||||||
SELECT
|
|
||||||
1 INTO foo;
|
|
||||||
RETURN NULL;
|
RETURN NULL;
|
||||||
END $$;
|
END $$;
|
||||||
CREATE TRIGGER delete_statement
|
CREATE TRIGGER delete_statement
|
||||||
|
@ -82,15 +74,8 @@ END $$;
|
||||||
RETURNS TRIGGER
|
RETURNS TRIGGER
|
||||||
LANGUAGE plpgsql
|
LANGUAGE plpgsql
|
||||||
AS $$
|
AS $$
|
||||||
DECLARE
|
|
||||||
foo int;
|
|
||||||
BEGIN
|
BEGIN
|
||||||
WITH combined_transition_tables AS (
|
insert_command;
|
||||||
select_new_table
|
|
||||||
),
|
|
||||||
trigger_result AS command
|
|
||||||
SELECT
|
|
||||||
1 INTO foo;
|
|
||||||
RETURN NULL;
|
RETURN NULL;
|
||||||
END $$;
|
END $$;
|
||||||
CREATE TRIGGER insert_statement
|
CREATE TRIGGER insert_statement
|
||||||
|
@ -102,16 +87,8 @@ END $$;
|
||||||
RETURNS TRIGGER
|
RETURNS TRIGGER
|
||||||
LANGUAGE plpgsql
|
LANGUAGE plpgsql
|
||||||
AS $$
|
AS $$
|
||||||
DECLARE
|
|
||||||
foo int;
|
|
||||||
BEGIN
|
BEGIN
|
||||||
WITH combined_transition_tables AS (
|
update_command;
|
||||||
select_old_table
|
|
||||||
UNION ALL select_new_table
|
|
||||||
),
|
|
||||||
trigger_result AS command
|
|
||||||
SELECT
|
|
||||||
1 INTO foo;
|
|
||||||
RETURN NULL;
|
RETURN NULL;
|
||||||
END $$;
|
END $$;
|
||||||
CREATE TRIGGER update_statement
|
CREATE TRIGGER update_statement
|
||||||
|
@ -120,6 +97,10 @@ END $$;
|
||||||
EXECUTE FUNCTION r.thing_update_statement ( );
|
EXECUTE FUNCTION r.thing_update_statement ( );
|
||||||
$b$;
|
$b$;
|
||||||
BEGIN
|
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', $$
|
defs := replace(defs, 'select_old_table', $$
|
||||||
SELECT
|
SELECT
|
||||||
-1 AS count_diff, old_table::thing AS thing FROM old_table $$);
|
-1 AS count_diff, old_table::thing AS thing FROM old_table $$);
|
||||||
|
@ -127,7 +108,6 @@ END $$;
|
||||||
SELECT
|
SELECT
|
||||||
1 AS count_diff, new_table::thing AS thing FROM new_table $$);
|
1 AS count_diff, new_table::thing AS thing FROM new_table $$);
|
||||||
defs := replace(defs, 'thing', table_name);
|
defs := replace(defs, 'thing', table_name);
|
||||||
defs := replace(defs, 'command', format('(%s)', command));
|
|
||||||
EXECUTE defs;
|
EXECUTE defs;
|
||||||
END
|
END
|
||||||
$a$;
|
$a$;
|
||||||
|
|
Loading…
Reference in a new issue