Skip to content
Snippets Groups Projects
Commit 45f61e0d authored by Nikita Pettik's avatar Nikita Pettik Committed by Kirill Yukhin
Browse files

sql: make default constraint names be consistent

If during creation of constraint its name is not specified, then it is
generated automatically. Occasionally, default names for each type of
constraint turn out to be different. This patch makes them follow the
same pattern: "shortcut"_unnamed_"table_name"_"ordinal_numb". For
instance: fk_unnamed_T1_1 or ck_unnamed_T1_3 etc
parent 1f783f26
No related branches found
No related tags found
No related merge requests found
......@@ -620,8 +620,7 @@ sql_create_check_contraint(struct Parse *parser)
} else {
assert(! is_alter);
uint32_t ck_idx = ++parser->create_table_def.check_count;
name = tt_sprintf("CK_CONSTRAINT_%d_%s", ck_idx,
space->def->name);
name = tt_sprintf("ck_unnamed_%s_%d", space->def->name, ck_idx);
}
size_t name_len = strlen(name);
......@@ -1857,9 +1856,9 @@ sql_create_foreign_key(struct Parse *parse_context)
if (!is_alter) {
if (create_def->name.n == 0) {
constraint_name =
sqlMPrintf(db, "FK_CONSTRAINT_%d_%s",
++table_def->fkey_count,
space->def->name);
sqlMPrintf(db, "fk_unnamed_%s_%d",
space->def->name,
++table_def->fkey_count);
} else {
constraint_name =
sql_name_from_token(db, &create_def->name);
......
......@@ -55,7 +55,7 @@ test:do_catchsql_test(
INSERT INTO t1 VALUES(6,7, 2);
]], {
-- <check-1.3>
1, "Check constraint failed 'CK_CONSTRAINT_1_T1': x<5"
1, "Check constraint failed 'ck_unnamed_T1_1': x<5"
-- </check-1.3>
})
......@@ -75,7 +75,7 @@ test:do_catchsql_test(
INSERT INTO t1 VALUES(4,3, 2);
]], {
-- <check-1.5>
1, "Check constraint failed 'CK_CONSTRAINT_2_T1': y>x"
1, "Check constraint failed 'ck_unnamed_T1_2': y>x"
-- </check-1.5>
})
......@@ -147,7 +147,7 @@ test:do_catchsql_test(
UPDATE t1 SET x=7 WHERE x==2
]], {
-- <check-1.12>
1, "Check constraint failed 'CK_CONSTRAINT_1_T1': x<5"
1, "Check constraint failed 'ck_unnamed_T1_1': x<5"
-- </check-1.12>
})
......@@ -167,7 +167,7 @@ test:do_catchsql_test(
UPDATE t1 SET x=5 WHERE x==2
]], {
-- <check-1.14>
1, "Check constraint failed 'CK_CONSTRAINT_1_T1': x<5"
1, "Check constraint failed 'ck_unnamed_T1_1': x<5"
-- </check-1.14>
})
......@@ -320,7 +320,7 @@ test:do_catchsql_test(
);
]], {
-- <check-3.1>
1, "Failed to create check constraint 'CK_CONSTRAINT_1_T3': Subqueries are prohibited in a ck constraint definition"
1, "Failed to create check constraint 'ck_unnamed_T3_1': Subqueries are prohibited in a ck constraint definition"
-- </check-3.1>
})
......@@ -345,7 +345,7 @@ test:do_catchsql_test(
);
]], {
-- <check-3.3>
1, "Failed to create check constraint 'CK_CONSTRAINT_1_T3': Can’t resolve field 'Q'"
1, "Failed to create check constraint 'ck_unnamed_T3_1': Can’t resolve field 'Q'"
-- </check-3.3>
})
......@@ -369,7 +369,7 @@ test:do_catchsql_test(
);
]], {
-- <check-3.5>
1, "Failed to create check constraint 'CK_CONSTRAINT_1_T3': Field 'X' was not found in space 'T2' format"
1, "Failed to create check constraint 'ck_unnamed_T3_1': Field 'X' was not found in space 'T2' format"
-- </check-3.5>
})
......@@ -414,7 +414,7 @@ test:do_catchsql_test(
INSERT INTO t3 VALUES(111,222,333);
]], {
-- <check-3.9>
1, "Check constraint failed 'CK_CONSTRAINT_1_T3': t3.x<25"
1, "Check constraint failed 'ck_unnamed_T3_1': t3.x<25"
-- </check-3.9>
})
......@@ -485,7 +485,7 @@ test:do_catchsql_test(
UPDATE t4 SET x=0, y=1;
]], {
-- <check-4.6>
1, "Check constraint failed 'CK_CONSTRAINT_1_T4': x+y==11 OR x*y==12 OR x/y BETWEEN 5 AND 8 OR -x==y+10"
1, "Check constraint failed 'ck_unnamed_T4_1': x+y==11 OR x*y==12 OR x/y BETWEEN 5 AND 8 OR -x==y+10"
-- </check-4.6>
})
......@@ -505,7 +505,7 @@ test:do_catchsql_test(
UPDATE t4 SET x=0, y=2;
]], {
-- <check-4.9>
1, "Check constraint failed 'CK_CONSTRAINT_1_T4': x+y==11 OR x*y==12 OR x/y BETWEEN 5 AND 8 OR -x==y+10"
1, "Check constraint failed 'ck_unnamed_T4_1': x+y==11 OR x*y==12 OR x/y BETWEEN 5 AND 8 OR -x==y+10"
-- </check-4.9>
})
......@@ -517,7 +517,7 @@ test:do_catchsql_test(
);
]], {
-- <check-5.1>
1, "Failed to create check constraint 'CK_CONSTRAINT_1_T5': bindings are not allowed in DDL"
1, "Failed to create check constraint 'ck_unnamed_T5_1': bindings are not allowed in DDL"
-- </check-5.1>
})
......@@ -529,7 +529,7 @@ test:do_catchsql_test(
);
]], {
-- <check-5.2>
1, "Failed to create check constraint 'CK_CONSTRAINT_1_T5': bindings are not allowed in DDL"
1, "Failed to create check constraint 'ck_unnamed_T5_1': bindings are not allowed in DDL"
-- </check-5.2>
})
......@@ -582,7 +582,7 @@ test:do_catchsql_test(
UPDATE OR FAIL t1 SET x=7-x, y=y+1;
]], {
-- <check-6.5>
1, "Check constraint failed 'CK_CONSTRAINT_1_T1': x<5"
1, "Check constraint failed 'ck_unnamed_T1_1': x<5"
-- </check-6.5>
})
......@@ -604,7 +604,7 @@ test:do_catchsql_test(
INSERT OR ROLLBACK INTO t1 VALUES(8,40.0, 10);
]], {
-- <check-6.7>
1, "Check constraint failed 'CK_CONSTRAINT_1_T1': x<5"
1, "Check constraint failed 'ck_unnamed_T1_1': x<5"
-- </check-6.7>
})
......@@ -637,7 +637,7 @@ test:do_catchsql_test(
REPLACE INTO t1 VALUES(6,7, 11);
]], {
-- <check-6.12>
1, "Check constraint failed 'CK_CONSTRAINT_1_T1': x<5"
1, "Check constraint failed 'ck_unnamed_T1_1': x<5"
-- </check-6.12>
})
......@@ -701,7 +701,7 @@ test:do_catchsql_test(
7.3,
" INSERT INTO t6 VALUES(11) ", {
-- <7.3>
1, "Check constraint failed 'CK_CONSTRAINT_1_T6': myfunc(a)"
1, "Check constraint failed 'ck_unnamed_T6_1': myfunc(a)"
-- </7.3>
})
......
......@@ -217,7 +217,7 @@ test:do_catchsql_test(
CREATE TABLE c1(a INT PRIMARY KEY REFERENCES p1(x));
]], {
-- <fkey1-6.1>
1, "Failed to create foreign key constraint 'FK_CONSTRAINT_1_C1': referenced fields don't compose unique index"
1, "Failed to create foreign key constraint 'fk_unnamed_C1_1': referenced fields don't compose unique index"
-- </fkey1-6.1>
})
......
......@@ -362,7 +362,7 @@ test:do_catchsql_test(
UPDATE ab SET a = 5;
]], {
-- <fkey2-3.2>
1, "Check constraint failed 'CK_CONSTRAINT_1_EF': e!=5"
1, "Check constraint failed 'ck_unnamed_EF_1': e!=5"
-- </fkey2-3.2>
})
......@@ -382,7 +382,7 @@ test:do_catchsql_test(
UPDATE ab SET a = 5;
]], {
-- <fkey2-3.4>
1, "Check constraint failed 'CK_CONSTRAINT_1_EF': e!=5"
1, "Check constraint failed 'ck_unnamed_EF_1': e!=5"
-- </fkey2-3.4>
})
......@@ -722,7 +722,7 @@ test:do_catchsql_test(
CREATE TABLE c(x INT PRIMARY KEY REFERENCES p(c));
]], {
-- <fkey2-7.1>
1, "Failed to create foreign key constraint 'FK_CONSTRAINT_1_C': foreign key refers to nonexistent field C"
1, "Failed to create foreign key constraint 'fk_unnamed_C_1': foreign key refers to nonexistent field C"
-- </fkey2-7.1>
})
......@@ -733,7 +733,7 @@ test:do_catchsql_test(
CREATE TABLE c(x INT PRIMARY KEY REFERENCES v(y));
]], {
-- <fkey2-7.2>
1, "Failed to create foreign key constraint 'FK_CONSTRAINT_1_C': referenced space can't be VIEW"
1, "Failed to create foreign key constraint 'fk_unnamed_C_1': referenced space can't be VIEW"
-- </fkey2-7.2>
})
......@@ -748,7 +748,7 @@ test:do_catchsql_test(
CREATE TABLE c(x TEXT PRIMARY KEY REFERENCES p(a));
]], {
-- <fkey2-7.3>
1, "Failed to create foreign key constraint 'FK_CONSTRAINT_1_C': field collation mismatch"
1, "Failed to create foreign key constraint 'fk_unnamed_C_1': field collation mismatch"
-- </fkey2-7.3>
})
......@@ -761,7 +761,7 @@ test:do_catchsql_test(
CREATE TABLE c(x INT PRIMARY KEY REFERENCES p);
]], {
-- <fkey2-7.4>
1, "Failed to create foreign key constraint 'FK_CONSTRAINT_1_C': number of columns in foreign key does not match the number of columns in the primary index of referenced table"
1, "Failed to create foreign key constraint 'fk_unnamed_C_1': number of columns in foreign key does not match the number of columns in the primary index of referenced table"
-- </fkey2-7.4>
})
......@@ -1100,7 +1100,7 @@ test:do_catchsql_test(
CREATE TABLE cc(a INT PRIMARY KEY, b INT , FOREIGN KEY(a, b) REFERENCES pp(x, z));
]], {
-- <fkey2-10.14>
1, "Failed to create foreign key constraint 'FK_CONSTRAINT_1_CC': foreign key refers to nonexistent field Z"
1, "Failed to create foreign key constraint 'fk_unnamed_CC_1': foreign key refers to nonexistent field Z"
-- </fkey2-10.14>
})
......@@ -1162,7 +1162,7 @@ test:do_catchsql_test(
CREATE TABLE t1(x INT PRIMARY KEY REFERENCES v);
]], {
-- <fkey2-10.20>
1, "Failed to create foreign key constraint 'FK_CONSTRAINT_1_T1': referenced space can't be VIEW"
1, "Failed to create foreign key constraint 'fk_unnamed_T1_1': referenced space can't be VIEW"
-- </fkey2-10.20>
})
......
......@@ -112,7 +112,7 @@ test:do_catchsql_test(
CREATE TABLE t10(i INT PRIMARY KEY REFERENCES v0);
]], {
-- <sql-errors-1.10>
1,"Failed to create foreign key constraint 'FK_CONSTRAINT_1_T10': referenced space can't be VIEW"
1,"Failed to create foreign key constraint 'fk_unnamed_T10_1': referenced space can't be VIEW"
-- </sql-errors-1.10>
})
......@@ -313,7 +313,7 @@ test:do_catchsql_test(
CREATE TABLE t27 (i INT PRIMARY KEY, CHECK(i < (SELECT * FROM t0)));
]], {
-- <sql-errors-1.27>
1,"Failed to create check constraint 'CK_CONSTRAINT_1_T27': Subqueries are prohibited in a ck constraint definition"
1,"Failed to create check constraint 'ck_unnamed_T27_1': Subqueries are prohibited in a ck constraint definition"
-- </sql-errors-1.27>
})
......
......@@ -791,7 +791,7 @@ test:do_catchsql_test(
);
]], {
-- <table-10.7>
1, "Failed to create foreign key constraint 'FK_CONSTRAINT_1_T6': foreign key refers to nonexistent field B"
1, "Failed to create foreign key constraint 'fk_unnamed_T6_1': foreign key refers to nonexistent field B"
-- </table-10.7>
})
......@@ -820,7 +820,7 @@ test:do_catchsql_test(
);
]], {
-- <table-10.9>
1, "Failed to create foreign key constraint 'FK_CONSTRAINT_1_T6': number of columns in foreign key does not match the number of columns in the primary index of referenced table"
1, "Failed to create foreign key constraint 'fk_unnamed_T6_1': number of columns in foreign key does not match the number of columns in the primary index of referenced table"
-- </table-10.9>
})
......@@ -835,7 +835,7 @@ test:do_test(
]]
end, {
-- <table-10.10>
1, "Failed to create foreign key constraint 'FK_CONSTRAINT_1_T6': number of columns in foreign key does not match the number of columns in the primary index of referenced table"
1, "Failed to create foreign key constraint 'fk_unnamed_T6_1': number of columns in foreign key does not match the number of columns in the primary index of referenced table"
-- </table-10.10>
})
......@@ -848,7 +848,7 @@ test:do_test(
]]
end, {
-- <table-10.11>
1, "Failed to create foreign key constraint 'FK_CONSTRAINT_1_T6': number of columns in foreign key does not match the number of columns in the primary index of referenced table"
1, "Failed to create foreign key constraint 'fk_unnamed_T6_1': number of columns in foreign key does not match the number of columns in the primary index of referenced table"
-- </table-10.11>
})
......@@ -863,7 +863,7 @@ test:do_test(
]]
end, {
-- <table-10.12>
1, [[Failed to create foreign key constraint 'FK_CONSTRAINT_1_T6': unknown column X in foreign key definition]]
1, [[Failed to create foreign key constraint 'fk_unnamed_T6_1': unknown column X in foreign key definition]]
-- </table-10.12>
})
......@@ -878,7 +878,7 @@ test:do_test(
]]
end, {
-- <table-10.13>
1, [[Failed to create foreign key constraint 'FK_CONSTRAINT_1_T6': unknown column X in foreign key definition]]
1, [[Failed to create foreign key constraint 'fk_unnamed_T6_1': unknown column X in foreign key definition]]
-- </table-10.13>
})
......@@ -1221,7 +1221,7 @@ test:do_catchsql_test(
INSERT INTO T21 VALUES(2, -1, 1);
]], {
-- <table-21.3>
1, "Check constraint failed 'CK_CONSTRAINT_1_T21': B > 0"
1, "Check constraint failed 'ck_unnamed_T21_1': B > 0"
-- </table-21.3>
})
......@@ -1231,7 +1231,7 @@ test:do_catchsql_test(
INSERT INTO T21 VALUES(2, 1, -1);
]], {
-- <table-21.4>
1, "Check constraint failed 'CK_CONSTRAINT_2_T21': C > 0"
1, "Check constraint failed 'ck_unnamed_T21_2': C > 0"
-- </table-21.4>
})
......
......@@ -365,8 +365,7 @@ box.execute('SELECT row_count();')
box.space._fk_constraint:select{}
---
- - ['FK1', 518, 517, false, 'partial', 'cascade', 'set_null', [0], [0]]
- ['FK_CONSTRAINT_1_TC', 518, 517, false, 'full', 'set_null', 'no_action', [1],
[1]]
- ['fk_unnamed_TC_1', 518, 517, false, 'full', 'set_null', 'no_action', [1], [1]]
...
box.execute('ALTER TABLE tc DROP CONSTRAINT fk1;')
---
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment