Debian Codegraph @

src/test/isolation/specs/temporal-range-integrity.spec

raw
1 # Temporal Range Integrity test
2 #
3 # Snapshot integrity fails with simple referential integrity tests,
4 # but those don't make for good demonstrations because people just
5 # say that foreign key definitions should be used instead. There
6 # are many integrity tests which are conceptually very similar but
7 # don't have built-in support which will fail when used in triggers.
8 # This is intended to illustrate such cases. It is obviously very
9 # hard to exercise all these permutations when the code is actually
10 # in a trigger; this test pulls what would normally be inside of
11 # triggers out to the top level to control the permutations.
12 #
13 # Any overlap between the transactions must cause a serialization failure.
14
15
16 setup
17 {
18 CREATE TABLE statute (statute_cite text NOT NULL, eff_date date NOT NULL, exp_date date, CONSTRAINT statute_pkey PRIMARY KEY (statute_cite, eff_date));
19 INSERT INTO statute VALUES ('123.45(1)a', DATE '2008-01-01', NULL);
20 CREATE TABLE offense (offense_no int NOT NULL, statute_cite text NOT NULL, offense_date date NOT NULL, CONSTRAINT offense_pkey PRIMARY KEY (offense_no));
21 }
22
23 teardown
24 {
25 DROP TABLE statute, offense;
26 }
27
28 session s1
29 setup { BEGIN ISOLATION LEVEL SERIALIZABLE; }
30 step rx1 { SELECT count(*) FROM statute WHERE statute_cite = '123.45(1)a' AND eff_date <= DATE '2009-05-15' AND (exp_date IS NULL OR exp_date > DATE '2009-05-15'); }
31 step wy1 { INSERT INTO offense VALUES (1, '123.45(1)a', DATE '2009-05-15'); }
32 step c1 { COMMIT; }
33
34 session s2
35 setup { BEGIN ISOLATION LEVEL SERIALIZABLE; }
36 step ry2 { SELECT count(*) FROM offense WHERE statute_cite = '123.45(1)a' AND offense_date >= DATE '2008-01-01'; }
37 step wx2 { DELETE FROM statute WHERE statute_cite = '123.45(1)a' AND eff_date = DATE '2008-01-01'; }
38 step c2 { COMMIT; }