Commit 77216cae authored by Peter Eisentraut's avatar Peter Eisentraut

Add tests for session_replication_role

This was hardly tested at all.  The trigger case was lightly tested by
the logical replication tests, but rules and event triggers were not
tested at all.
parent 2082b374
......@@ -88,16 +88,34 @@ create event trigger regress_event_trigger_noperms on ddl_command_start
ERROR: permission denied to create event trigger "regress_event_trigger_noperms"
HINT: Must be superuser to create an event trigger.
reset role;
-- all OK
alter event trigger regress_event_trigger enable replica;
alter event trigger regress_event_trigger enable always;
-- test enabling and disabling
alter event trigger regress_event_trigger disable;
alter event trigger regress_event_trigger disable;
-- regress_event_trigger2 and regress_event_trigger_end should fire, but not
-- fires _trigger2 and _trigger_end should fire, but not _trigger
create table event_trigger_fire1 (a int);
NOTICE: test_event_trigger: ddl_command_start CREATE TABLE
NOTICE: test_event_trigger: ddl_command_end CREATE TABLE
alter event trigger regress_event_trigger enable;
set session_replication_role = replica;
-- fires nothing
create table event_trigger_fire2 (a int);
alter event trigger regress_event_trigger enable replica;
-- fires only _trigger
create table event_trigger_fire3 (a int);
NOTICE: test_event_trigger: ddl_command_start CREATE TABLE
alter event trigger regress_event_trigger enable always;
-- fires only _trigger
create table event_trigger_fire4 (a int);
NOTICE: test_event_trigger: ddl_command_start CREATE TABLE
reset session_replication_role;
-- fires all three
create table event_trigger_fire5 (a int);
NOTICE: test_event_trigger: ddl_command_start CREATE TABLE
NOTICE: test_event_trigger: ddl_command_start CREATE TABLE
NOTICE: test_event_trigger: ddl_command_end CREATE TABLE
-- clean up
alter event trigger regress_event_trigger disable;
drop table event_trigger_fire2, event_trigger_fire3, event_trigger_fire4, event_trigger_fire5;
NOTICE: test_event_trigger: ddl_command_end DROP TABLE
-- regress_event_trigger_end should fire on these commands
grant all on table event_trigger_fire1 to public;
NOTICE: test_event_trigger: ddl_command_end GRANT
......
......@@ -3233,3 +3233,37 @@ CREATE RULE parted_table_insert AS ON INSERT to parted_table
DO INSTEAD INSERT INTO parted_table_1 VALUES (NEW.*);
ALTER RULE parted_table_insert ON parted_table RENAME TO parted_table_insert_redirect;
DROP TABLE parted_table;
--
-- Test enabling/disabling
--
CREATE TABLE ruletest1 (a int);
CREATE TABLE ruletest2 (b int);
CREATE RULE rule1 AS ON INSERT TO ruletest1
DO INSTEAD INSERT INTO ruletest2 VALUES (NEW.*);
INSERT INTO ruletest1 VALUES (1);
ALTER TABLE ruletest1 DISABLE RULE rule1;
INSERT INTO ruletest1 VALUES (2);
ALTER TABLE ruletest1 ENABLE RULE rule1;
SET session_replication_role = replica;
INSERT INTO ruletest1 VALUES (3);
ALTER TABLE ruletest1 ENABLE REPLICA RULE rule1;
INSERT INTO ruletest1 VALUES (4);
RESET session_replication_role;
INSERT INTO ruletest1 VALUES (5);
SELECT * FROM ruletest1;
a
---
2
3
5
(3 rows)
SELECT * FROM ruletest2;
b
---
1
4
(2 rows)
DROP TABLE ruletest1;
DROP TABLE ruletest2;
......@@ -569,6 +569,12 @@ insert into trigtest default values;
alter table trigtest enable trigger trigtest_a_stmt_tg;
insert into trigtest default values;
NOTICE: trigtest INSERT AFTER STATEMENT
set session_replication_role = replica;
insert into trigtest default values; -- does not trigger
alter table trigtest enable always trigger trigtest_a_stmt_tg;
insert into trigtest default values; -- now it does
NOTICE: trigtest INSERT AFTER STATEMENT
reset session_replication_role;
insert into trigtest2 values(1);
insert into trigtest2 values(2);
delete from trigtest where i=2;
......@@ -595,7 +601,9 @@ select * from trigtest;
3
4
5
(3 rows)
6
7
(5 rows)
drop table trigtest2;
drop table trigtest;
......
......@@ -89,15 +89,26 @@ create event trigger regress_event_trigger_noperms on ddl_command_start
execute procedure test_event_trigger();
reset role;
-- test enabling and disabling
alter event trigger regress_event_trigger disable;
-- fires _trigger2 and _trigger_end should fire, but not _trigger
create table event_trigger_fire1 (a int);
alter event trigger regress_event_trigger enable;
set session_replication_role = replica;
-- fires nothing
create table event_trigger_fire2 (a int);
alter event trigger regress_event_trigger enable replica;
-- fires only _trigger
create table event_trigger_fire3 (a int);
alter event trigger regress_event_trigger enable always;
alter event trigger regress_event_trigger enable always;
-- fires only _trigger
create table event_trigger_fire4 (a int);
reset session_replication_role;
-- fires all three
create table event_trigger_fire5 (a int);
-- clean up
alter event trigger regress_event_trigger disable;
alter event trigger regress_event_trigger disable;
-- regress_event_trigger2 and regress_event_trigger_end should fire, but not
-- regress_event_trigger
drop table event_trigger_fire2, event_trigger_fire3, event_trigger_fire4, event_trigger_fire5;
-- regress_event_trigger_end should fire on these commands
grant all on table event_trigger_fire1 to public;
......
......@@ -1177,3 +1177,29 @@ CREATE RULE parted_table_insert AS ON INSERT to parted_table
DO INSTEAD INSERT INTO parted_table_1 VALUES (NEW.*);
ALTER RULE parted_table_insert ON parted_table RENAME TO parted_table_insert_redirect;
DROP TABLE parted_table;
--
-- Test enabling/disabling
--
CREATE TABLE ruletest1 (a int);
CREATE TABLE ruletest2 (b int);
CREATE RULE rule1 AS ON INSERT TO ruletest1
DO INSTEAD INSERT INTO ruletest2 VALUES (NEW.*);
INSERT INTO ruletest1 VALUES (1);
ALTER TABLE ruletest1 DISABLE RULE rule1;
INSERT INTO ruletest1 VALUES (2);
ALTER TABLE ruletest1 ENABLE RULE rule1;
SET session_replication_role = replica;
INSERT INTO ruletest1 VALUES (3);
ALTER TABLE ruletest1 ENABLE REPLICA RULE rule1;
INSERT INTO ruletest1 VALUES (4);
RESET session_replication_role;
INSERT INTO ruletest1 VALUES (5);
SELECT * FROM ruletest1;
SELECT * FROM ruletest2;
DROP TABLE ruletest1;
DROP TABLE ruletest2;
......@@ -401,6 +401,11 @@ alter table trigtest disable trigger user;
insert into trigtest default values;
alter table trigtest enable trigger trigtest_a_stmt_tg;
insert into trigtest default values;
set session_replication_role = replica;
insert into trigtest default values; -- does not trigger
alter table trigtest enable always trigger trigtest_a_stmt_tg;
insert into trigtest default values; -- now it does
reset session_replication_role;
insert into trigtest2 values(1);
insert into trigtest2 values(2);
delete from trigtest where i=2;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment