You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: mysql-test/r/rename_preserve_foreign_key_parent.result
+57Lines changed: 57 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -93,5 +93,62 @@ id hint
93
93
delete from _84371a37_6153_11eb_9917_f875a4d24e90_20210128122816_vrepl;
94
94
delete from parent_table where id=2;
95
95
ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`child_table`, CONSTRAINT `child_parent_fk` FOREIGN KEY (`parent_id`) REFERENCES `parent_table` (`id`))
96
+
# Test on another schema
97
+
select database();
98
+
database()
99
+
test
100
+
create database `test_preserve_fk`;
101
+
use `test_preserve_fk`;
102
+
create table parent (id int primary key, i int);
103
+
create table child1 (id int primary key, pid int, constraint child1_fk foreign key (pid) references parent(id));
104
+
insert into parent values (1,10), (2,20);
105
+
insert into child1 values (1,1), (2,2);
106
+
insert into child1 values (4, 4);
107
+
ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test_preserve_fk`.`child1`, CONSTRAINT `child1_fk` FOREIGN KEY (`pid`) REFERENCES `parent` (`id`))
108
+
create table _84371a37_6153_11eb_9917_f875a4d24e90_20210128122816_vrepl like parent;
109
+
insert into _84371a37_6153_11eb_9917_f875a4d24e90_20210128122816_vrepl select * from parent;
110
+
rename table parent to _vt_DROP_6ace8bcef73211ea87e9f875a4d24e90_20200915120410, _84371a37_6153_11eb_9917_f875a4d24e90_20210128122816_vrepl to parent, _vt_DROP_6ace8bcef73211ea87e9f875a4d24e90_20200915120410 to _84371a37_6153_11eb_9917_f875a4d24e90_20210128122816_vrepl;
ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test_preserve_fk`.`child1`, CONSTRAINT `child1_fk` FOREIGN KEY (`pid`) REFERENCES `parent` (`id`))
122
+
drop database `test_preserve_fk`;
123
+
use test;
124
+
# Test on schema with name that needs escaping
125
+
select database();
126
+
database()
127
+
test
128
+
create database `test-preserve-fk`;
129
+
use `test-preserve-fk`;
130
+
create table parent (id int primary key, i int);
131
+
create table child1 (id int primary key, pid int, constraint child1_fk foreign key (pid) references parent(id));
132
+
insert into parent values (1,10), (2,20);
133
+
insert into child1 values (1,1), (2,2);
134
+
insert into child1 values (4, 4);
135
+
ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test-preserve-fk`.`child1`, CONSTRAINT `child1_fk` FOREIGN KEY (`pid`) REFERENCES `parent` (`id`))
136
+
create table _84371a37_6153_11eb_9917_f875a4d24e90_20210128122816_vrepl like parent;
137
+
insert into _84371a37_6153_11eb_9917_f875a4d24e90_20210128122816_vrepl select * from parent;
138
+
rename table parent to _vt_DROP_6ace8bcef73211ea87e9f875a4d24e90_20200915120410, _84371a37_6153_11eb_9917_f875a4d24e90_20210128122816_vrepl to parent, _vt_DROP_6ace8bcef73211ea87e9f875a4d24e90_20200915120410 to _84371a37_6153_11eb_9917_f875a4d24e90_20210128122816_vrepl;
ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test-preserve-fk`.`child1`, CONSTRAINT `child1_fk` FOREIGN KEY (`pid`) REFERENCES `parent` (`id`))
150
+
drop database `test-preserve-fk`;
151
+
use test;
152
+
# Cleanup
96
153
drop table if exists _84371a37_6153_11eb_9917_f875a4d24e90_20210128122816_vrepl, _vt_HOLD_6ace8bcef73211ea87e9f875a4d24e90_20200915120410, child_table, child_table_old, child_table_new;
97
154
drop table if exists parent_table, parent_table_old, parent_table_new;
Copy file name to clipboardExpand all lines: mysql-test/t/rename_preserve_foreign_key_parent.test
+37-1Lines changed: 37 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -67,7 +67,43 @@ delete from _84371a37_6153_11eb_9917_f875a4d24e90_20210128122816_vrepl;
67
67
# This should error because of ON DELETE NO ACTION:
68
68
--error ER_ROW_IS_REFERENCED_2
69
69
delete from parent_table where id=2;
70
-
# Cleanup
70
+
--echo # Test on another schema
71
+
select database();
72
+
create database `test_preserve_fk`;
73
+
use `test_preserve_fk`;
74
+
create table parent (id int primary key, i int);
75
+
create table child1 (id int primary key, pid int, constraint child1_fk foreign key (pid) references parent(id));
76
+
insert into parent values (1,10), (2,20);
77
+
insert into child1 values (1,1), (2,2);
78
+
--error ER_NO_REFERENCED_ROW_2
79
+
insert into child1 values (4, 4);
80
+
create table _84371a37_6153_11eb_9917_f875a4d24e90_20210128122816_vrepl like parent;
81
+
insert into _84371a37_6153_11eb_9917_f875a4d24e90_20210128122816_vrepl select * from parent;
82
+
rename table parent to _vt_DROP_6ace8bcef73211ea87e9f875a4d24e90_20200915120410, _84371a37_6153_11eb_9917_f875a4d24e90_20210128122816_vrepl to parent, _vt_DROP_6ace8bcef73211ea87e9f875a4d24e90_20200915120410 to _84371a37_6153_11eb_9917_f875a4d24e90_20210128122816_vrepl;
83
+
show create table child1;
84
+
--error ER_NO_REFERENCED_ROW_2
85
+
insert into child1 values (7, 7);
86
+
drop database `test_preserve_fk`;
87
+
use test;
88
+
--echo # Test on schema with name that needs escaping
89
+
select database();
90
+
create database `test-preserve-fk`;
91
+
use `test-preserve-fk`;
92
+
create table parent (id int primary key, i int);
93
+
create table child1 (id int primary key, pid int, constraint child1_fk foreign key (pid) references parent(id));
94
+
insert into parent values (1,10), (2,20);
95
+
insert into child1 values (1,1), (2,2);
96
+
--error ER_NO_REFERENCED_ROW_2
97
+
insert into child1 values (4, 4);
98
+
create table _84371a37_6153_11eb_9917_f875a4d24e90_20210128122816_vrepl like parent;
99
+
insert into _84371a37_6153_11eb_9917_f875a4d24e90_20210128122816_vrepl select * from parent;
100
+
rename table parent to _vt_DROP_6ace8bcef73211ea87e9f875a4d24e90_20200915120410, _84371a37_6153_11eb_9917_f875a4d24e90_20210128122816_vrepl to parent, _vt_DROP_6ace8bcef73211ea87e9f875a4d24e90_20200915120410 to _84371a37_6153_11eb_9917_f875a4d24e90_20210128122816_vrepl;
101
+
show create table child1;
102
+
--error ER_NO_REFERENCED_ROW_2
103
+
insert into child1 values (7, 7);
104
+
drop database `test-preserve-fk`;
105
+
use test;
106
+
--echo # Cleanup
71
107
--disable_warnings
72
108
drop table if exists _84371a37_6153_11eb_9917_f875a4d24e90_20210128122816_vrepl, _vt_HOLD_6ace8bcef73211ea87e9f875a4d24e90_20200915120410, child_table, child_table_old, child_table_new;
73
109
drop table if exists parent_table, parent_table_old, parent_table_new;
0 commit comments