Skip to content

Instantly share code, notes, and snippets.

@shadowhand
Created August 18, 2010 01:52
Show Gist options
  • Save shadowhand/533049 to your computer and use it in GitHub Desktop.
Save shadowhand/533049 to your computer and use it in GitHub Desktop.
SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
CREATE TABLE IF NOT EXISTS `associates` (
`id` tinyint(3) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(64) NOT NULL,
`website` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `name` (`name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=2 ;
CREATE TABLE IF NOT EXISTS `associates_projects` (
`associate_id` tinyint(3) unsigned NOT NULL,
`project_id` smallint(5) unsigned NOT NULL,
PRIMARY KEY (`associate_id`,`project_id`),
KEY `fk_project` (`project_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE IF NOT EXISTS `projects` (
`id` smallint(5) unsigned NOT NULL AUTO_INCREMENT,
`associate_id` tinyint(3) unsigned DEFAULT NULL,
`title` varchar(255) NOT NULL,
`slug` varchar(255) NOT NULL,
`completed` int(10) unsigned NOT NULL,
`website` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `uniq_slug` (`slug`),
KEY `fk_associate` (`associate_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=10 ;
CREATE TABLE IF NOT EXISTS `project_images` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`project_id` smallint(5) unsigned NOT NULL,
`file` varchar(255) NOT NULL,
`title` varchar(64) NOT NULL,
PRIMARY KEY (`id`),
KEY `fk_project` (`project_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=12 ;
CREATE TABLE IF NOT EXISTS `users` (
`id` tinyint(3) unsigned NOT NULL AUTO_INCREMENT,
`username` varchar(24) NOT NULL,
`password` varchar(40) DEFAULT NULL,
`last_login` int(10) unsigned DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `uniq_username` (`username`),
KEY `idx_last_login` (`last_login`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=2 ;
ALTER TABLE `associates_projects`
ADD CONSTRAINT `associates_projects_ibfk_1` FOREIGN KEY (`associate_id`) REFERENCES `associates` (`id`) ON DELETE CASCADE,
ADD CONSTRAINT `associates_projects_ibfk_2` FOREIGN KEY (`project_id`) REFERENCES `projects` (`id`) ON DELETE CASCADE;
ALTER TABLE `projects`
ADD CONSTRAINT `projects_ibfk_1` FOREIGN KEY (`associate_id`) REFERENCES `associates` (`id`);
ALTER TABLE `project_images`
ADD CONSTRAINT `project_images_ibfk_1` FOREIGN KEY (`project_id`) REFERENCES `projects` (`id`) ON DELETE CASCADE;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment