]> git.mxchange.org Git - pizzaservice-ejb.git/blob - install/install.sql
Added customer table
[pizzaservice-ejb.git] / install / install.sql
1 CREATE TABLE IF NOT EXISTS `category` (
2         `id` bigint(20) unsigned NOT NULL COMMENT 'Primary key',
3         `title` varchar(255) NOT NULL COMMENT 'Category title',
4         `parent` bigint(20) unsigned DEFAULT NULL COMMENT 'Parent category',
5         PRIMARY KEY (`id`),
6         INDEX `parent` (`parent`)
7 ) ENGINE=InnoDBDEFAULT CHARSET=utf8mb4 COMMENT='Categories' ;
8
9 CREATE TABLE IF NOT EXISTS `contacts` (
10         `id` bigint(20) unsigned NOT NULL COMMENT 'Primary key',
11         `own_contact` tinyint(1) NOT NULL DEFAULT '0' COMMENT 'Whether own contact',
12         `gender` varchar(10) NOT NULL DEFAULT 'UNKNOWN' COMMENT 'Gender',
13         `first_name` varchar(100) NOT NULL COMMENT 'First name',
14         `family_name` varchar(100) NOT NULL COMMENT 'Family name',
15         `company_name` varchar(255) DEFAULT NULL COMMENT 'Company name',
16         `street` varchar(255) DEFAULT NULL COMMENT 'Street name',
17         `house_number` smallint(5) unsigned DEFAULT NULL COMMENT 'House number',
18         `city` varchar(100) DEFAULT NULL COMMENT 'City name',
19         `zip_code` smallint(5) unsigned DEFAULT NULL COMMENT 'ZIP code',
20         `country_code` char(2) DEFAULT NULL COMMENT 'Country code',
21         `phone_number` varchar(100) DEFAULT NULL COMMENT 'Phone number',
22         `cellphone_number` varchar(100) DEFAULT NULL COMMENT 'Cellphone number',
23         `fax_number` varchar(100) DEFAULT NULL COMMENT 'Fax number',
24         `email_address` varchar(100) DEFAULT NULL COMMENT 'Email addres',
25         `birthday` date DEFAULT NULL COMMENT 'Birth day',
26         `comment` tinytext NOT NULL COMMENT 'Comment',
27         `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Entry created',
28         `updated` timestamp NULL DEFAULT NULL COMMENT 'Entry updated',
29         PRIMARY KEY (`id`)
30 ) ENGINE=InnoDBDEFAULT CHARSET=utf8mb4 COMMENT='Contacts data' ;
31
32 CREATE TABLE `customer` (
33         `id` bigint(20) unsigned NOT NULL COMMENT 'Primay key',
34         `customer_contact_id` bigint(20) unsigned NOT NULL COMMENT 'Table reference on "contact"',
35         `customer_password_hash` varchar(255) COLLATE 'utf8mb4_general_ci' NOT NULL COMMENT 'Password hash',
36         `customer_confirm_key` varchar(50) COLLATE 'utf8mb4_general_ci' NULL DEFAULT NULL COMMENT 'Email confirmation key',
37         `customer_status` enum('UNCONFIRMED','CONFIRMED','LOCKED') COLLATE 'utf8mb4_general_ci' NOT NULL DEFAULT 'UNCONFIRMED' COMMENT 'Account status',
38         `customer_created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Account creation',
39         `customer_locked` datetime NULL COMMENT 'Last locked timestamp',
40         PRIMARY KEY (`id`),
41         UNIQUE (`customer_confirm_key`),
42         INDEX (`customer_contact_id`)
43 ) COMMENT='Customer data' ENGINE='InnoDB' COLLATE 'utf8mb4_general_ci';
44
45 CREATE TABLE IF NOT EXISTS `products` (
46         `id` bigint(20) unsigned NOT NULL COMMENT 'Primary key',
47         `category` bigint(20) unsigned DEFAULT NULL COMMENT 'Category id',
48         `title` varchar(255) NOT NULL COMMENT 'Title of product',
49         `price` decimal(20,2) unsigned NOT NULL COMMENT 'Product price',
50         `available` tinyint(1) NOT NULL DEFAULT '0' COMMENT 'Whether product is available',
51         PRIMARY KEY (`id`),
52         INDEX `category` (`category`)
53 ) ENGINE=InnoDBDEFAULT CHARSET=utf8mb4 COMMENT='Products' ;
54
55 ALTER TABLE `category`
56 MODIFY `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Primary key';
57
58 ALTER TABLE `contacts`
59 MODIFY `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Primary key';
60
61 ALTER TABLE `customer`
62 MODIFY `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Primary key';
63
64 ALTER TABLE `products`
65 MODIFY `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Primary key';
66
67 ALTER TABLE `category`
68 ADD FOREIGN KEY (`parent`) REFERENCES `category` (`id`) ON DELETE SET NULL;
69
70 ALTER TABLE `customer`
71 ADD FOREIGN KEY (`customer_contact_id`) REFERENCES `contacts` (`id`) ON DELETE CASCADE;
72
73 ALTER TABLE `products`
74 ADD FOREIGN KEY (`category`) REFERENCES `category` (`id`) ON DELETE SET NULL;