1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
| CREATE TABLE IF NOT EXISTS `user` (
`user_id` int(11) NOT NULL auto_increment,
`created_at` datetime NOT NULL,
`updated_at` datetime NOT NULL,
`username` varchar(255) NOT NULL,
`password` varchar(255) NOT NULL,
`first_name` varchar(255) default NULL,
`last_name` varchar(255) default NULL,
`email` varchar(255) NOT NULL,
`is_active` tinyint(1) NOT NULL,
`is_admin` tinyint(1) NOT NULL,
PRIMARY KEY (`user_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
CREATE TABLE IF NOT EXISTS `article` (
`article_id` int(11) NOT NULL auto_increment,
`category_id` int(11) NOT NULL,
`user_id` int(11) NOT NULL,
`title` varchar(255) collate utf8_unicode_ci NOT NULL,
`created_at` datetime NOT NULL,
`updated_at` datetime NOT NULL,
`is_published` tinyint(1) NOT NULL,
`publication_date` datetime NOT NULL,
`expiration_date` datetime NULL,
`text` text collate utf8_unicode_ci NOT NULL,
`format` tinyint(1) NOT NULL,
PRIMARY KEY (`article_id`),
KEY `category_id` (`category_id`),
KEY `user_id` (`user_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
CREATE TABLE IF NOT EXISTS `article_category` (
`category_id` int(11) NOT NULL auto_increment,
`name` varchar(255) collate utf8_unicode_ci NOT NULL,
`v_order` tinyint(4) NOT NULL,
`description` varchar(255) collate utf8_unicode_ci default NULL,
PRIMARY KEY (`category_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
ALTER TABLE `article`
ADD CONSTRAINT `article_ibfk_1` FOREIGN KEY (`category_id`) REFERENCES `article_category` (`category_id`) ON DELETE CASCADE ON UPDATE CASCADE,
ADD CONSTRAINT `article_ibfk_2` FOREIGN KEY (`user_id`) REFERENCES `article` (`user_id`); |
Partager