Skip to content

Instantly share code, notes, and snippets.

@faizalmansor
Last active August 29, 2015 14:21
Show Gist options
  • Save faizalmansor/8d705e7633160858e793 to your computer and use it in GitHub Desktop.
Save faizalmansor/8d705e7633160858e793 to your computer and use it in GitHub Desktop.
Yii 2.0 - Sample Project Database
CREATE TABLE IF NOT EXISTS `catalog` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`product_name` varchar(50) NOT NULL,
`product_description` text NOT NULL,
`photo` varchar(50) DEFAULT NULL,
`price` float(4,2) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
-- --------------------------------------------------------
--
-- Table structure for table `country`
--
CREATE TABLE IF NOT EXISTS `country` (
`code` char(2) NOT NULL,
`name` char(52) NOT NULL,
PRIMARY KEY (`code`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
--
-- Dumping data for table `country`
--
INSERT INTO `country` (`code`, `name`) VALUES
('AU', 'Australia'),
('BR', 'Brazil'),
('CA', 'Canada'),
('CN', 'China'),
('DE', 'Germany'),
('FR', 'France'),
('GB', 'United Kingdom'),
('IN', 'India'),
('MY', 'Malaysia'),
('RU', 'Russia'),
('US', 'USA');
-- --------------------------------------------------------
--
-- Table structure for table `customer`
--
CREATE TABLE IF NOT EXISTS `customer` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`user_id` int(11) NOT NULL,
`name` varchar(50) NOT NULL,
`email` varchar(100) NOT NULL,
`address` varchar(100) DEFAULT NULL,
`postcode` varchar(5) DEFAULT NULL,
`country` char(2) NOT NULL,
`contact_number` varchar(12) NOT NULL,
PRIMARY KEY (`id`),
KEY `country` (`country`),
KEY `user_id` (`user_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
-- --------------------------------------------------------
--
-- Table structure for table `order`
--
CREATE TABLE IF NOT EXISTS `order` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`catalog_id` int(11) NOT NULL,
`customer_id` int(11) NOT NULL,
`quantity` tinyint(5) NOT NULL,
`total` float(4,2) NOT NULL,
PRIMARY KEY (`id`),
KEY `catalog_id` (`catalog_id`),
KEY `customer_id` (`customer_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
-- --------------------------------------------------------
--
-- Table structure for table `user`
--
CREATE TABLE IF NOT EXISTS `user` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`username` varchar(10) NOT NULL,
`password` varchar(60) NOT NULL,
`authKey` varchar(13) NOT NULL,
`accessToken` varchar(32) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=2 ;
--
-- Dumping data for table `user`
--
INSERT INTO `user` (`id`, `username`, `password`, `authKey`, `accessToken`) VALUES
(1, 'admin', '$2y$13$FtpDZdQZGoI5Iit0Cicr9eR4oHqA8dI95WCBp.2ZTA6uM3NZG5IR2', '55521e470261b', '202cb962ac59075b964b07152d234b70');
--
-- Constraints for dumped tables
--
--
-- Constraints for table `customer`
--
ALTER TABLE `customer`
ADD CONSTRAINT `fk_customer_country_code` FOREIGN KEY (`country`) REFERENCES `country` (`code`) ON DELETE CASCADE ON UPDATE CASCADE,
ADD CONSTRAINT `fk_customer_user_id` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;
--
-- Constraints for table `order`
--
ALTER TABLE `order`
ADD CONSTRAINT `fk_order_customer_id` FOREIGN KEY (`customer_id`) REFERENCES `customer` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
ADD CONSTRAINT `fk_catalog_id` FOREIGN KEY (`catalog_id`) REFERENCES `catalog` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment