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]>
  • Loading branch information
morgando committed Jan 9, 2025
1 parent d7bd5c4 commit 2e1645e
Show file tree
Hide file tree
Showing 18 changed files with 169 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
9 changes: 9 additions & 0 deletions tests/constraints.test/t19.req
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
-- add constraint with table create and then satisfy it with table alter in a transaction.
-- fails with an error now but can be supported in the future
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
7 changes: 7 additions & 0 deletions tests/constraints.test/t19.req.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[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] failed with rc 240 constraint error for table "bar" key "a" -> <"foo":"a">: parent key not found
10 changes: 10 additions & 0 deletions tests/constraints.test/t20.req
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
-- add constraint with table alter and then satisfy it with table alter in a transaction.
-- fails with an error now but can be supported in the future
drop table if exists foo
drop table if exists bar
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">}} $$
alter table bar {schema{int i} keys{"pk" = i}} $$
commit
8 changes: 8 additions & 0 deletions tests/constraints.test/t20.req.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[drop table if exists foo] rc 0
[drop table if exists bar] 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">}}] rc 0
[alter table bar {schema{int i} keys{"pk" = i}}] rc 0
[commit] failed with rc 240 constraint error for table "foo" key "key" -> <"bar":"pk">: parent key not found
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
18 changes: 18 additions & 0 deletions tests/constraints.test/t22.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 create in a transaction.
-- BUGGY -- cascade doesn't get registered somehow
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
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 2e1645e

Please sign in to comment.