|
| 1 | +SET search_path = 'musicbrainz', 'public'; |
| 2 | + |
| 3 | +-------------------------------------------------------------------------------- |
| 4 | +BEGIN; |
| 5 | +SELECT no_plan(); |
| 6 | + |
| 7 | +INSERT INTO series (id, gid, name, comment, type, ordering_attribute, ordering_type) |
| 8 | + VALUES (1, '82ac9811-db47-4c05-9792-83cf4208afd0', 'Series', 'Series 1', 1, 788, 1), |
| 9 | + (2, '9baea67a-8d86-422d-b653-b0f6d0a93c7c', 'Series', 'Series 2', 1, 788, 1); |
| 10 | + |
| 11 | +INSERT INTO tag (id, name) VALUES (2, 'Unused tag'), (4, 'Used tag'), (5, 'Shared tag'); |
| 12 | +INSERT INTO series_tag (series, tag, count) VALUES |
| 13 | + (1, 2, 1), (1, 4, 1), (1, 5, 1), (2, 5, 1); |
| 14 | + |
| 15 | +-- Delete tag before commit to test AFTER INSERT ON tag trigger |
| 16 | +DELETE FROM series_tag WHERE tag = 2; |
| 17 | + |
| 18 | +-- Deleting but the re-adding should not garbage collect |
| 19 | +DELETE FROM series_tag WHERE tag = 4; |
| 20 | +INSERT INTO series_tag (series, tag, count) VALUES (1, 4, 1); |
| 21 | + |
| 22 | +DELETE FROM series_tag WHERE tag = 5 AND series = 1; |
| 23 | + |
| 24 | +SELECT set_eq( |
| 25 | + 'SELECT id FROM tag', '{2, 4, 5}'::INT[], |
| 26 | + 'Tag exists before commit' |
| 27 | +); |
| 28 | + |
| 29 | +-- Simulate the commit |
| 30 | +SET CONSTRAINTS ALL IMMEDIATE; |
| 31 | + |
| 32 | +SELECT set_eq( |
| 33 | + 'SELECT id FROM tag', '{4, 5}'::INT[], |
| 34 | + 'Tag deleted after commit by AFTER INSERT ON tag' |
| 35 | +); |
| 36 | + |
| 37 | +-- Delete tag after commit to test AFTER DELETE ON series_tag trigger |
| 38 | +DELETE FROM series_tag WHERE tag = 5; |
| 39 | + |
| 40 | +SELECT set_eq( |
| 41 | + 'SELECT id FROM tag', '{4}'::INT[], |
| 42 | + 'Tag deleted after commit by AFTER DELETE ON series_tag' |
| 43 | +); |
| 44 | + |
| 45 | +SELECT finish(); |
| 46 | +ROLLBACK; |
0 commit comments