From 554a0b1b75da744bf31bd1689bca99ec3ad08c4e Mon Sep 17 00:00:00 2001 From: Morgan Douglas Date: Thu, 2 Jan 2025 15:51:06 -0500 Subject: [PATCH] Test adding and satisfying constraint in same txn Signed-off-by: Morgan Douglas Tweak test Signed-off-by: Morgan Douglas Tweak test Signed-off-by: Morgan Douglas Tweak tests Signed-off-by: Morgan Douglas Teak tests Signed-off-by: Morgan Douglas Tweak tests Signed-off-by: Morgan Douglas Tweak tests Signed-off-by: Morgan Douglas Tweak tests Signed-off-by: Morgan Douglas Tweak tests Signed-off-by: Morgan Douglas Tweak tests Signed-off-by: Morgan Douglas Tweak tests Signed-off-by: Morgan Douglas Tweak tests Signed-off-by: Morgan Douglas Tweak tests Signed-off-by: Morgan Douglas Tweak tests Signed-off-by: Morgan Douglas Tweak tests Signed-off-by: Morgan Douglas Tweak tests Signed-off-by: Morgan Douglas Tweak tests Signed-off-by: Morgan Douglas Remove dummy test Signed-off-by: Morgan Douglas Update test Signed-off-by: Morgan Douglas Fix test Signed-off-by: Morgan Douglas --- tests/constraints.test/t10.req | 6 --- tests/constraints.test/t10.req.exp | 6 --- tests/constraints.test/t17.req | 5 +++ tests/constraints.test/t17.req.exp | 4 ++ tests/constraints.test/t18.req | 7 ++++ tests/constraints.test/t18.req.exp | 6 +++ tests/constraints.test/t19.req | 17 ++++++++ tests/constraints.test/t19.req.exp | 21 ++++++++++ tests/constraints.test/t20.req | 18 +++++++++ tests/constraints.test/t20.req.exp | 22 +++++++++++ tests/constraints.test/t21.req | 16 ++++++++ tests/constraints.test/t21.req.exp | 20 ++++++++++ tests/constraints.test/t22.req | 17 ++++++++ tests/constraints.test/t22.req.exp | 21 ++++++++++ tests/constraints.test/t23.req | 17 ++++++++ tests/constraints.test/t23.req.exp | 21 ++++++++++ tests/constraints.test/t24.req | 7 ++++ tests/constraints.test/t24.req.exp | 5 +++ tests/tran_foreign_key.test/Makefile | 8 ---- tests/tran_foreign_key.test/runit | 58 ---------------------------- 20 files changed, 224 insertions(+), 78 deletions(-) create mode 100644 tests/constraints.test/t17.req create mode 100644 tests/constraints.test/t17.req.exp create mode 100644 tests/constraints.test/t18.req create mode 100644 tests/constraints.test/t18.req.exp create mode 100644 tests/constraints.test/t19.req create mode 100644 tests/constraints.test/t19.req.exp create mode 100644 tests/constraints.test/t20.req create mode 100644 tests/constraints.test/t20.req.exp create mode 100644 tests/constraints.test/t21.req create mode 100644 tests/constraints.test/t21.req.exp create mode 100644 tests/constraints.test/t22.req create mode 100644 tests/constraints.test/t22.req.exp create mode 100644 tests/constraints.test/t23.req create mode 100644 tests/constraints.test/t23.req.exp create mode 100644 tests/constraints.test/t24.req create mode 100644 tests/constraints.test/t24.req.exp delete mode 100644 tests/tran_foreign_key.test/Makefile delete mode 100755 tests/tran_foreign_key.test/runit diff --git a/tests/constraints.test/t10.req b/tests/constraints.test/t10.req index 649cb4bd93..6480602310 100644 --- a/tests/constraints.test/t10.req +++ b/tests/constraints.test/t10.req @@ -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}} $$ diff --git a/tests/constraints.test/t10.req.exp b/tests/constraints.test/t10.req.exp index f21e5629ff..5ae73be008 100644 --- a/tests/constraints.test/t10.req.exp +++ b/tests/constraints.test/t10.req.exp @@ -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 diff --git a/tests/constraints.test/t17.req b/tests/constraints.test/t17.req new file mode 100644 index 0000000000..3eb0f9af8b --- /dev/null +++ b/tests/constraints.test/t17.req @@ -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 diff --git a/tests/constraints.test/t17.req.exp b/tests/constraints.test/t17.req.exp new file mode 100644 index 0000000000..68ec144642 --- /dev/null +++ b/tests/constraints.test/t17.req.exp @@ -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 diff --git a/tests/constraints.test/t18.req b/tests/constraints.test/t18.req new file mode 100644 index 0000000000..21c4832f91 --- /dev/null +++ b/tests/constraints.test/t18.req @@ -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 diff --git a/tests/constraints.test/t18.req.exp b/tests/constraints.test/t18.req.exp new file mode 100644 index 0000000000..cdf84e91f6 --- /dev/null +++ b/tests/constraints.test/t18.req.exp @@ -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 diff --git a/tests/constraints.test/t19.req b/tests/constraints.test/t19.req new file mode 100644 index 0000000000..dd16ddc3dc --- /dev/null +++ b/tests/constraints.test/t19.req @@ -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 diff --git a/tests/constraints.test/t19.req.exp b/tests/constraints.test/t19.req.exp new file mode 100644 index 0000000000..6e3ecaa102 --- /dev/null +++ b/tests/constraints.test/t19.req.exp @@ -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 diff --git a/tests/constraints.test/t20.req b/tests/constraints.test/t20.req new file mode 100644 index 0000000000..b5b35d0e4b --- /dev/null +++ b/tests/constraints.test/t20.req @@ -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 diff --git a/tests/constraints.test/t20.req.exp b/tests/constraints.test/t20.req.exp new file mode 100644 index 0000000000..476b84fdb7 --- /dev/null +++ b/tests/constraints.test/t20.req.exp @@ -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 diff --git a/tests/constraints.test/t21.req b/tests/constraints.test/t21.req new file mode 100644 index 0000000000..11a76e344d --- /dev/null +++ b/tests/constraints.test/t21.req @@ -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 diff --git a/tests/constraints.test/t21.req.exp b/tests/constraints.test/t21.req.exp new file mode 100644 index 0000000000..edc9a1717a --- /dev/null +++ b/tests/constraints.test/t21.req.exp @@ -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 diff --git a/tests/constraints.test/t22.req b/tests/constraints.test/t22.req new file mode 100644 index 0000000000..912a0909cf --- /dev/null +++ b/tests/constraints.test/t22.req @@ -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 diff --git a/tests/constraints.test/t22.req.exp b/tests/constraints.test/t22.req.exp new file mode 100644 index 0000000000..ca55563893 --- /dev/null +++ b/tests/constraints.test/t22.req.exp @@ -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 diff --git a/tests/constraints.test/t23.req b/tests/constraints.test/t23.req new file mode 100644 index 0000000000..034174dd93 --- /dev/null +++ b/tests/constraints.test/t23.req @@ -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 diff --git a/tests/constraints.test/t23.req.exp b/tests/constraints.test/t23.req.exp new file mode 100644 index 0000000000..306e786e1d --- /dev/null +++ b/tests/constraints.test/t23.req.exp @@ -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 diff --git a/tests/constraints.test/t24.req b/tests/constraints.test/t24.req new file mode 100644 index 0000000000..d276c8225a --- /dev/null +++ b/tests/constraints.test/t24.req @@ -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}} $$ diff --git a/tests/constraints.test/t24.req.exp b/tests/constraints.test/t24.req.exp new file mode 100644 index 0000000000..275d907568 --- /dev/null +++ b/tests/constraints.test/t24.req.exp @@ -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 diff --git a/tests/tran_foreign_key.test/Makefile b/tests/tran_foreign_key.test/Makefile deleted file mode 100644 index 4f1a0fb623..0000000000 --- a/tests/tran_foreign_key.test/Makefile +++ /dev/null @@ -1,8 +0,0 @@ -ifeq ($(TESTSROOTDIR),) - include ../testcase.mk -else - include $(TESTSROOTDIR)/testcase.mk -endif -ifeq ($(TEST_TIMEOUT),) - export TEST_TIMEOUT=10m -endif diff --git a/tests/tran_foreign_key.test/runit b/tests/tran_foreign_key.test/runit deleted file mode 100755 index 0ac8c21684..0000000000 --- a/tests/tran_foreign_key.test/runit +++ /dev/null @@ -1,58 +0,0 @@ -#!/bin/bash - -TMPDIR=${TMPDIR:-/tmp} -dbname=$1 - -echo db is $dbname -echo options $CDB2_OPTIONS - -( -cdb2sql ${CDB2_OPTIONS} ${dbname} default - <<'EOF' -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 { - "a" = a -} -} $$ -commit -EOF - -echo insert into t fails -cdb2sql ${CDB2_OPTIONS} ${dbname} "insert into t values(1)" ## fails -echo insert into q -cdb2sql ${CDB2_OPTIONS} ${dbname} "insert into q values(1)" -echo insert into t now succeeds -cdb2sql ${CDB2_OPTIONS} ${dbname} "insert into t values(1)" ## now succeeds -echo "select * from t" -cdb2sql ${CDB2_OPTIONS} ${dbname} "select * from t" ## 1 -echo "select * from t" -cdb2sql ${CDB2_OPTIONS} ${dbname} "select * from q" ## 1 -echo "delete from q" -cdb2sql ${CDB2_OPTIONS} ${dbname} "delete from q where 1" -echo "select * from t" -cdb2sql ${CDB2_OPTIONS} ${dbname} "select * from t" ## empty -echo "select * from q" -cdb2sql ${CDB2_OPTIONS} ${dbname} "select * from q" ## empty? -) > out 2>&1 -exit 0