Skip to content

Commit

Permalink
Add database migration for indexes and constraints
Browse files Browse the repository at this point in the history
  • Loading branch information
simonewebdesign committed Feb 23, 2013
1 parent 4f0a6a7 commit fe95228
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions 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.