| 1 |
# |
| 2 |
# Test ALTER ADD FOREIGN KEYS |
| 3 |
# |
| 4 |
--source connect.inc |
| 5 |
|
| 6 |
if (!$algorithm) |
| 7 |
{ |
| 8 |
die Need the algortihm to use when testing the ALTER; |
| 9 |
} |
| 10 |
|
| 11 |
--echo # Setup |
| 12 |
create table parent ( |
| 13 |
pk int primary key, |
| 14 |
id1 int unique, |
| 15 |
id2 int unique, |
| 16 |
id3 int unique, |
| 17 |
ref1 int, |
| 18 |
ref2 int, |
| 19 |
ref3 int |
| 20 |
) engine ndb; |
| 21 |
|
| 22 |
create table child ( |
| 23 |
pk int primary key, |
| 24 |
ref1 int, |
| 25 |
ref2 int |
| 26 |
) engine ndb; |
| 27 |
|
| 28 |
--echo # Add self referential foreign keys |
| 29 |
--echo # Add one with a user specified constraint name |
| 30 |
eval alter table parent |
| 31 |
add constraint fk_p1 foreign key ref1_idx(ref1) references parent (id1), |
| 32 |
algorithm = $algorithm; |
| 33 |
|
| 34 |
--echo # Verify the foreign keys on parent |
| 35 |
--let $ndb_table_name=parent |
| 36 |
--source verify_foreign_keys.inc |
| 37 |
|
| 38 |
--echo # Add one with generated constraint name |
| 39 |
eval alter table parent |
| 40 |
add foreign key ref2_idx(ref2) references parent (id2), |
| 41 |
algorithm = $algorithm; |
| 42 |
|
| 43 |
--echo # Verify the foreign keys on parent |
| 44 |
--let $ndb_table_name=parent |
| 45 |
--source verify_foreign_keys.inc |
| 46 |
|
| 47 |
--echo # Add foreign keys on child referencing parent |
| 48 |
--echo # Add one with a user specified constraint name |
| 49 |
eval alter table child |
| 50 |
add constraint fk_c1 foreign key ref1_idx(ref1) references parent (id1), |
| 51 |
algorithm = $algorithm; |
| 52 |
|
| 53 |
--echo # Verify the foreign keys on child |
| 54 |
--let $ndb_table_name=child |
| 55 |
--source verify_foreign_keys.inc |
| 56 |
|
| 57 |
--echo # Add one with generated constraint name |
| 58 |
eval alter table child |
| 59 |
add foreign key ref2_idx(ref2) references parent (id2), |
| 60 |
algorithm = $algorithm; |
| 61 |
|
| 62 |
--echo # Verify the foreign keys on child |
| 63 |
--let $ndb_table_name=child |
| 64 |
--source verify_foreign_keys.inc |
| 65 |
|
| 66 |
--echo # Add a foreign key to the parent and verify that the |
| 67 |
--echo # exisiting foreign key constraints are consistent |
| 68 |
eval alter table parent |
| 69 |
add foreign key ref3_idx(ref3) references parent (id3), |
| 70 |
algorithm = $algorithm; |
| 71 |
|
| 72 |
--echo # Verify the foreign keys on parent and child |
| 73 |
--let $ndb_table_name=parent |
| 74 |
--source verify_foreign_keys.inc |
| 75 |
--let $ndb_table_name=child |
| 76 |
--source verify_foreign_keys.inc |
| 77 |
|
| 78 |
--echo # Cleanup |
| 79 |
drop table child, parent; |
| 80 |
|
| 81 |
# Reset algorithm |
| 82 |
--let $algorithm= |
| 83 |
|