Skip to content

Commit

Permalink
Test adding and satisfying constraint in same txn
Browse files Browse the repository at this point in the history
Signed-off-by: Morgan Douglas <[email protected]>

Tweak test

Signed-off-by: Morgan Douglas <[email protected]>

Tweak test

Signed-off-by: Morgan Douglas <[email protected]>

Tweak tests

Signed-off-by: Morgan Douglas <[email protected]>

Teak tests

Signed-off-by: Morgan Douglas <[email protected]>

Tweak tests

Signed-off-by: Morgan Douglas <[email protected]>

Tweak tests

Signed-off-by: Morgan Douglas <[email protected]>

Tweak tests

Signed-off-by: Morgan Douglas <[email protected]>

Tweak tests

Signed-off-by: Morgan Douglas <[email protected]>

Tweak tests

Signed-off-by: Morgan Douglas <[email protected]>

Tweak tests

Signed-off-by: Morgan Douglas <[email protected]>

Tweak tests

Signed-off-by: Morgan Douglas <[email protected]>

Tweak tests

Signed-off-by: Morgan Douglas <[email protected]>

Tweak tests

Signed-off-by: Morgan Douglas <[email protected]>

Tweak tests

Signed-off-by: Morgan Douglas <[email protected]>

Tweak tests

Signed-off-by: Morgan Douglas <[email protected]>

Tweak tests

Signed-off-by: Morgan Douglas <[email protected]>

Remove dummy test

Signed-off-by: Morgan Douglas <[email protected]>

Update test

Signed-off-by: Morgan Douglas <[email protected]>

Fix test

Signed-off-by: Morgan Douglas <[email protected]>
  • Loading branch information
morgando committed Jan 29, 2025
1 parent 1c5a513 commit 554a0b1
Show file tree
Hide file tree
Showing 20 changed files with 224 additions and 78 deletions.
6 changes: 0 additions & 6 deletions tests/constraints.test/t10.req
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,6 @@ alter table c {schema{int i}} $$
alter table c {schema{int i}} $$
drop table c

select "transactional create (bad case)"
begin
create table c {schema{int i} keys{dup "key" = i} constraints{"key" -> <"m" : "pk">}} $$
create table m {schema{int i} keys{"pk" = i}} $$
commit

select "transactional create"
begin
create table m {schema{int i} keys{"pk" = i}} $$
Expand Down
6 changes: 0 additions & 6 deletions tests/constraints.test/t10.req.exp
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,6 @@
[alter table c {schema{int i}}] rc 0
[alter table c {schema{int i}}] rc 0
[drop table c] rc 0
("transactional create (bad case)"='transactional create (bad case)')
[select "transactional create (bad case)"] rc 0
[begin] rc 0
[create table c {schema{int i} keys{dup "key" = i} constraints{"key" -> <"m" : "pk">}}] rc 0
[create table m {schema{int i} keys{"pk" = i}}] rc 0
[commit] failed with rc 240 constraint error for table "c" key "key" -> <"m":"pk">: parent table not found
("transactional create"='transactional create')
[select "transactional create"] rc 0
[begin] rc 0
Expand Down
5 changes: 5 additions & 0 deletions tests/constraints.test/t17.req
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-- add unsatisfied constraint with table create in txn
drop table if exists t
begin
create table t { schema { int a } keys { "a" = a } constraints { "a" -> "donut":"a" on delete cascade } }$$
commit
4 changes: 4 additions & 0 deletions tests/constraints.test/t17.req.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[drop table if exists t] rc 0
[begin] rc 0
[create table t { schema { int a } keys { "a" = a } constraints { "a" -> "donut":"a" on delete cascade } }] rc 0
[commit] failed with rc 240 constraint error for table "t" key "a" -> <"donut":"a">: parent table not found
7 changes: 7 additions & 0 deletions tests/constraints.test/t18.req
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-- add unsatisfied constraint with table create in txn (target table exists but doesn't have the right key)
drop table if exists t
drop table if exists q
begin
create table t { schema { int a } keys { "a" = a } constraints { "a" -> "q":"a" on delete cascade } }$$
create table q { schema { int a } keys { "wrong_name" = a } }$$
commit
6 changes: 6 additions & 0 deletions tests/constraints.test/t18.req.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[drop table if exists t] rc 0
[drop table if exists q] rc 0
[begin] rc 0
[create table t { schema { int a } keys { "a" = a } constraints { "a" -> "q":"a" on delete cascade } }] rc 0
[create table q { schema { int a } keys { "wrong_name" = a } }] rc 0
[commit] failed with rc 240 constraint error for table "t" key "a" -> <"q":"a">: parent key not found
17 changes: 17 additions & 0 deletions tests/constraints.test/t19.req
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
-- add constraint with table create and then satisfy it with table alter in a transaction.
drop table if exists foo
drop table if exists bar
create table foo { schema { int a } keys { "donut" = a } }$$
begin
create table bar { schema { int a } keys { "a" = a } constraints { "a" -> "foo":"a" on delete cascade } }$$
alter table foo { schema { int a } keys { "a" = a } }$$
commit
insert into bar values(1)
select 'shouldnt see me' from bar
insert into foo values(1)
insert into bar values(1)
select 'should see me' from bar
select 'should see me' from foo
delete from foo where 1
select 'shouldnt see me' from bar
select 'shouldnt see me' from foo
21 changes: 21 additions & 0 deletions tests/constraints.test/t19.req.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[drop table if exists foo] rc 0
[drop table if exists bar] rc 0
[create table foo { schema { int a } keys { "donut" = a } }] rc 0
[begin] rc 0
[create table bar { schema { int a } keys { "a" = a } constraints { "a" -> "foo":"a" on delete cascade } }] rc 0
[alter table foo { schema { int a } keys { "a" = a } }] rc 0
[commit] rc 0
[insert into bar values(1)] failed with rc 3 Transaction violates foreign key constraint bar(a) -> foo(a): key value does not exist in parent table
[select 'shouldnt see me' from bar] rc 0
(rows inserted=1)
[insert into foo values(1)] rc 0
(rows inserted=1)
[insert into bar values(1)] rc 0
('should see me'='should see me')
[select 'should see me' from bar] rc 0
('should see me'='should see me')
[select 'should see me' from foo] rc 0
(rows deleted=1)
[delete from foo where 1] rc 0
[select 'shouldnt see me' from bar] rc 0
[select 'shouldnt see me' from foo] rc 0
18 changes: 18 additions & 0 deletions tests/constraints.test/t20.req
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
-- add constraint with table alter and then satisfy it with table alter in a transaction.
drop table if exists bar
drop table if exists foo
create table foo(i int)$$
create table bar(i int)$$
begin
alter table foo {schema{int i} keys{dup "key" = i} constraints{"key" -> "bar":"pk" on delete cascade }} $$
alter table bar {schema{int i} keys{"pk" = i}} $$
commit
insert into foo values(1)
select 'shouldnt see me' from foo
insert into bar values(1)
insert into foo values(1)
select 'should see me' from foo
select 'should see me' from bar
delete from bar where 1
select 'shouldnt see me' from foo
select 'shouldnt see me' from bar
22 changes: 22 additions & 0 deletions tests/constraints.test/t20.req.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[drop table if exists bar] rc 0
[drop table if exists foo] rc 0
[create table foo(i int)] rc 0
[create table bar(i int)] rc 0
[begin] rc 0
[alter table foo {schema{int i} keys{dup "key" = i} constraints{"key" -> "bar":"pk" on delete cascade }}] rc 0
[alter table bar {schema{int i} keys{"pk" = i}}] rc 0
[commit] rc 0
[insert into foo values(1)] failed with rc 3 Transaction violates foreign key constraint foo(i) -> bar(i): key value does not exist in parent table
[select 'shouldnt see me' from foo] rc 0
(rows inserted=1)
[insert into bar values(1)] rc 0
(rows inserted=1)
[insert into foo values(1)] rc 0
('should see me'='should see me')
[select 'should see me' from foo] rc 0
('should see me'='should see me')
[select 'should see me' from bar] rc 0
(rows deleted=1)
[delete from bar where 1] rc 0
[select 'shouldnt see me' from foo] rc 0
[select 'shouldnt see me' from bar] rc 0
16 changes: 16 additions & 0 deletions tests/constraints.test/t21.req
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
-- add constraint with table create and then satisfy it with table create in a transaction.
drop table if exists foo
drop table if exists bar
begin
create table foo { schema { int a } keys { "a" = a } constraints { "a" -> "bar":"a" on delete cascade } }$$
create table bar { schema { int a } keys { "a" = a } }$$
commit
insert into foo values(1)
select 'shouldnt see me' from foo
insert into bar values(1)
insert into foo values(1)
select 'should see me' from foo
select 'should see me' from bar
delete from bar where 1
select 'shouldnt see me' from foo
select 'shouldnt see me' from bar
20 changes: 20 additions & 0 deletions tests/constraints.test/t21.req.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[drop table if exists foo] rc 0
[drop table if exists bar] rc 0
[begin] rc 0
[create table foo { schema { int a } keys { "a" = a } constraints { "a" -> "bar":"a" on delete cascade } }] rc 0
[create table bar { schema { int a } keys { "a" = a } }] rc 0
[commit] rc 0
[insert into foo values(1)] failed with rc 3 Transaction violates foreign key constraint foo(a) -> bar(a): key value does not exist in parent table
[select 'shouldnt see me' from foo] rc 0
(rows inserted=1)
[insert into bar values(1)] rc 0
(rows inserted=1)
[insert into foo values(1)] rc 0
('should see me'='should see me')
[select 'should see me' from foo] rc 0
('should see me'='should see me')
[select 'should see me' from bar] rc 0
(rows deleted=1)
[delete from bar where 1] rc 0
[select 'shouldnt see me' from foo] rc 0
[select 'shouldnt see me' from bar] rc 0
17 changes: 17 additions & 0 deletions tests/constraints.test/t22.req
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
-- add constraint with table alter and then satisfy it with table create in a transaction.
drop table if exists foo
drop table if exists bar
create table foo(i int)$$
begin
alter table foo { schema { int a } keys { "a" = a } constraints { "a" -> "bar":"a" on delete cascade } }$$
create table bar { schema { int a } keys { "a" = a } }$$
commit
insert into foo values(1)
select 'shouldnt see me' from foo
insert into bar values(1)
insert into foo values(1)
select 'should see me' from foo
select 'should see me' from bar
delete from bar where 1
select 'shouldnt see me' from foo
select 'shouldnt see me' from bar
21 changes: 21 additions & 0 deletions tests/constraints.test/t22.req.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[drop table if exists foo] rc 0
[drop table if exists bar] rc 0
[create table foo(i int)] rc 0
[begin] rc 0
[alter table foo { schema { int a } keys { "a" = a } constraints { "a" -> "bar":"a" on delete cascade } }] rc 0
[create table bar { schema { int a } keys { "a" = a } }] rc 0
[commit] rc 0
[insert into foo values(1)] failed with rc 3 Transaction violates foreign key constraint foo(a) -> bar(a): key value does not exist in parent table
[select 'shouldnt see me' from foo] rc 0
(rows inserted=1)
[insert into bar values(1)] rc 0
(rows inserted=1)
[insert into foo values(1)] rc 0
('should see me'='should see me')
[select 'should see me' from foo] rc 0
('should see me'='should see me')
[select 'should see me' from bar] rc 0
(rows deleted=1)
[delete from bar where 1] rc 0
[select 'shouldnt see me' from foo] rc 0
[select 'shouldnt see me' from bar] rc 0
17 changes: 17 additions & 0 deletions tests/constraints.test/t23.req
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
-- satisfy a constraint with table create and then add it with table alter in a txn
drop table if exists foo
drop table if exists bar
create table foo(i int)$$
begin
create table bar { schema { int a } keys { "a" = a } }$$
alter table foo { schema { int a } keys { "a" = a } constraints { "a" -> "bar":"a" on delete cascade } }$$
commit
insert into foo values(1)
select 'shouldnt see me' from foo
insert into bar values(1)
insert into foo values(1)
select 'should see me' from foo
select 'should see me' from bar
delete from bar where 1
select 'shouldnt see me' from foo
select 'shouldnt see me' from bar
21 changes: 21 additions & 0 deletions tests/constraints.test/t23.req.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[drop table if exists foo] rc 0
[drop table if exists bar] rc 0
[create table foo(i int)] rc 0
[begin] rc 0
[create table bar { schema { int a } keys { "a" = a } }] rc 0
[alter table foo { schema { int a } keys { "a" = a } constraints { "a" -> "bar":"a" on delete cascade } }] rc 0
[commit] rc 0
[insert into foo values(1)] failed with rc 3 Transaction violates foreign key constraint foo(a) -> bar(a): key value does not exist in parent table
[select 'shouldnt see me' from foo] rc 0
(rows inserted=1)
[insert into bar values(1)] rc 0
(rows inserted=1)
[insert into foo values(1)] rc 0
('should see me'='should see me')
[select 'should see me' from foo] rc 0
('should see me'='should see me')
[select 'should see me' from bar] rc 0
(rows deleted=1)
[delete from bar where 1] rc 0
[select 'shouldnt see me' from foo] rc 0
[select 'shouldnt see me' from bar] rc 0
7 changes: 7 additions & 0 deletions tests/constraints.test/t24.req
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-- Document that you can't change the parent key in a foreign key constraint
-- Although this isn't currently supported, we could add support for it in the future
drop table if exists foo
drop table if exists bar
create table bar {schema{int i int j} keys{"pk" = i+j}} $$
create table foo {schema{int i int j} keys{dup "key" = i+j} constraints{"key" -> "bar":"pk" on delete cascade }} $$
alter table bar {schema{int i} keys{"pk" = i}} $$
5 changes: 5 additions & 0 deletions tests/constraints.test/t24.req.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[drop table if exists foo] rc 0
[drop table if exists bar] rc 0
[create table bar {schema{int i int j} keys{"pk" = i+j}}] rc 0
[create table foo {schema{int i int j} keys{dup "key" = i+j} constraints{"key" -> "bar":"pk" on delete cascade }}] rc 0
[alter table bar {schema{int i} keys{"pk" = i}}] failed with rc 240 cannot change index referenced by other tables
8 changes: 0 additions & 8 deletions tests/tran_foreign_key.test/Makefile

This file was deleted.

58 changes: 0 additions & 58 deletions tests/tran_foreign_key.test/runit

This file was deleted.

0 comments on commit 554a0b1

Please sign in to comment.