`fax_number` varchar(100) DEFAULT NULL COMMENT 'Fax number',
`email_address` varchar(100) DEFAULT NULL COMMENT 'Email addres',
`birthday` date DEFAULT NULL COMMENT 'Birth day',
- `comment` tinytext NOT NULL COMMENT 'Comment',
+ `comment` tinytext NULL DEFAULT NULL COMMENT 'Comment',
`created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Entry created',
`updated` timestamp NULL DEFAULT NULL COMMENT 'Entry updated',
PRIMARY KEY (`id`)
`id` bigint(20) unsigned NOT NULL COMMENT 'Primay key',
`customer_contact_id` bigint(20) unsigned NOT NULL COMMENT 'Table reference on "contact"',
`customer_number` varchar(20) COLLATE 'utf8mb4_general_ci' NOT NULL COMMENT 'Customer number',
- `customer_password_hash` varchar(255) COLLATE 'utf8mb4_general_ci' NOT NULL COMMENT 'Password hash',
+ `customer_password_hash` varchar(255) COLLATE 'utf8mb4_general_ci' NULL DEFAULT NULL COMMENT 'Password hash',
`customer_confirm_key` varchar(50) COLLATE 'utf8mb4_general_ci' NULL DEFAULT NULL COMMENT 'Email confirmation key',
`customer_status` enum('UNCONFIRMED','CONFIRMED','LOCKED') COLLATE 'utf8mb4_general_ci' NOT NULL DEFAULT 'UNCONFIRMED' COMMENT 'Account status',
`customer_created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Account creation',
- `customer_locked` datetime NULL COMMENT 'Last locked timestamp',
+ `customer_locked` datetime NULL DEFAULT NULL COMMENT 'Last locked timestamp',
PRIMARY KEY (`id`),
UNIQUE (`customer_confirm_key`),
UNIQUE (`customer_number`),
INDEX `category` (`category`)
) ENGINE=InnoDBDEFAULT CHARSET=utf8mb4 COMMENT='Products' ;
+CREATE TABLE IF NOT EXISTS `orders` (
+ `id` bigint(20) unsigned NOT NULL COMMENT 'Primary key',
+ `order_status` enum('UNCONFIRMED','CONFIRMED','DELIVERED','CANCELED') NOT NULL DEFAULT 'UNCONFIRMED' COMMENT 'Order status',
+ `customer_id` bigint(20) unsigned DEFAULT NULL COMMENT 'Table reference customer',
+ `product_id` bigint(20) unsigned NOT NULL COMMENT 'Table reference products',
+ `amount` bigint(20) unsigned NOT NULL COMMENT 'Ordered amount',
+ `added` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Record inserted',
+ PRIMARY KEY (`id`),
+ INDEX `product_id` (`product_id`),
+ INDEX `customer_product` (`customer_id`,`product_id`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='Customer orders';
+
ALTER TABLE `category`
MODIFY `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Primary key';
ALTER TABLE `products`
MODIFY `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Primary key';
+ALTER TABLE `orders`
+MODIFY `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Primary key';
+
ALTER TABLE `category`
ADD FOREIGN KEY (`parent`) REFERENCES `category` (`id`) ON DELETE SET NULL;
ALTER TABLE `products`
ADD FOREIGN KEY (`category`) REFERENCES `category` (`id`) ON DELETE SET NULL;
+
+ALTER TABLE `orders`
+ADD CONSTRAINT `orders_ibfk_1` FOREIGN KEY (`customer_id`) REFERENCES `customer` (`id`) ON DELETE SET NULL,
+ADD CONSTRAINT `orders_ibfk_2` FOREIGN KEY (`product_id`) REFERENCES `products` (`id`) ON DELETE CASCADE;