Permalink
Browse files

Add database migration for indexes and constraints

  • Loading branch information...
simonewebdesign committed Feb 23, 2013
1 parent 4f0a6a7 commit fe952280cc536f5839f95f96d9ba15ab8a09ddde
Showing with 33 additions and 0 deletions.
  1. +33 −0 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;
+
+

0 comments on commit fe95228

Please sign in to comment.