Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add database migration for indexes and constraints
- Loading branch information
1 parent
4f0a6a7
commit fe95228
Showing
1 changed file
with
33 additions
and
0 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
db/migrations/23-02-2013-13-04-add-indexes-and-constraints.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
-- create index | ||
ALTER TABLE `users` ADD INDEX ( `list_id` ); | ||
|
||
-- add constraint | ||
ALTER TABLE `users` ADD FOREIGN KEY ( `list_id` ) | ||
REFERENCES `lists` ( `id` ) | ||
ON DELETE CASCADE ON UPDATE CASCADE; | ||
|
||
----------------- | ||
|
||
-- create index | ||
ALTER TABLE `resources` ADD INDEX ( `newsletter_id` ); | ||
|
||
-- add constraint | ||
ALTER TABLE `resources` ADD FOREIGN KEY ( `newsletter_id` ) | ||
REFERENCES `newsletters` ( `id` ) | ||
ON DELETE CASCADE ON UPDATE CASCADE; | ||
|
||
----------------- | ||
|
||
-- create index | ||
ALTER TABLE `newsletters` ADD INDEX ( `template_id` ); | ||
|
||
-- template_id can be NULL | ||
ALTER TABLE `newsletters` CHANGE `template_id` `template_id` INT( 10 ) UNSIGNED NULL DEFAULT NULL; | ||
ALTER TABLE `templates` CHANGE `id` `id` INT( 10 ) UNSIGNED NULL AUTO_INCREMENT; | ||
|
||
-- add constraint | ||
ALTER TABLE `newsletters` ADD FOREIGN KEY ( `template_id` ) | ||
REFERENCES `newsletter`.`templates` ( `id` ) | ||
ON DELETE SET NULL ON UPDATE CASCADE; | ||
|
||
|