From fe952280cc536f5839f95f96d9ba15ab8a09ddde Mon Sep 17 00:00:00 2001 From: Simone Date: Sat, 23 Feb 2013 19:17:00 +0100 Subject: [PATCH] Add database migration for indexes and constraints --- ...2013-13-04-add-indexes-and-constraints.sql | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 db/migrations/23-02-2013-13-04-add-indexes-and-constraints.sql diff --git a/db/migrations/23-02-2013-13-04-add-indexes-and-constraints.sql b/db/migrations/23-02-2013-13-04-add-indexes-and-constraints.sql new file mode 100644 index 0000000..879cb7a --- /dev/null +++ b/db/migrations/23-02-2013-13-04-add-indexes-and-constraints.sql @@ -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; + +