From: Roland Haeder Date: Fri, 11 Sep 2015 15:55:06 +0000 (+0200) Subject: Added customer table X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=7e51492ed81726def9edb5a89e80fe1bef57e876;p=pizzaservice.git Added customer table Signed-off-by:Roland Häder --- diff --git a/install/install.sql b/install/install.sql index e8e4009..12e00c1 100644 --- a/install/install.sql +++ b/install/install.sql @@ -1,46 +1,56 @@ -DROP TABLE IF EXISTS `category`; CREATE TABLE IF NOT EXISTS `category` ( -`id` bigint(20) unsigned NOT NULL COMMENT 'Primary key', - `title` varchar(255) NOT NULL COMMENT 'Category title', - `parent` bigint(20) unsigned DEFAULT NULL COMMENT 'Parent category', - PRIMARY KEY (`id`), - INDEX `parent` (`parent`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='Categories' ; - -DROP TABLE IF EXISTS `contacts`; + `id` bigint(20) unsigned NOT NULL COMMENT 'Primary key', + `title` varchar(255) NOT NULL COMMENT 'Category title', + `parent` bigint(20) unsigned DEFAULT NULL COMMENT 'Parent category', + PRIMARY KEY (`id`), + INDEX `parent` (`parent`) +) ENGINE=InnoDBDEFAULT CHARSET=utf8mb4 COMMENT='Categories' ; + CREATE TABLE IF NOT EXISTS `contacts` ( -`id` bigint(20) unsigned NOT NULL COMMENT 'Primary key', - `own_contact` tinyint(1) NOT NULL DEFAULT '0' COMMENT 'Whether own contact', - `gender` varchar(10) NOT NULL DEFAULT 'UNKNOWN' COMMENT 'Gender', - `first_name` varchar(100) NOT NULL COMMENT 'First name', - `family_name` varchar(100) NOT NULL COMMENT 'Family name', - `company_name` varchar(255) DEFAULT NULL COMMENT 'Company name', - `street` varchar(255) DEFAULT NULL COMMENT 'Street name', - `house_number` smallint(5) unsigned DEFAULT NULL COMMENT 'House number', - `city` varchar(100) DEFAULT NULL COMMENT 'City name', - `zip_code` smallint(5) unsigned DEFAULT NULL COMMENT 'ZIP code', - `country_code` char(2) DEFAULT NULL COMMENT 'Country code', - `phone_number` varchar(100) DEFAULT NULL COMMENT 'Phone number', - `cellphone_number` varchar(100) DEFAULT NULL COMMENT 'Cellphone number', - `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', - `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Entry created', - `updated` timestamp NULL DEFAULT NULL COMMENT 'Entry updated', - PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='Contacts data' ; - -DROP TABLE IF EXISTS `products`; + `id` bigint(20) unsigned NOT NULL COMMENT 'Primary key', + `own_contact` tinyint(1) NOT NULL DEFAULT '0' COMMENT 'Whether own contact', + `gender` varchar(10) NOT NULL DEFAULT 'UNKNOWN' COMMENT 'Gender', + `first_name` varchar(100) NOT NULL COMMENT 'First name', + `family_name` varchar(100) NOT NULL COMMENT 'Family name', + `company_name` varchar(255) DEFAULT NULL COMMENT 'Company name', + `street` varchar(255) DEFAULT NULL COMMENT 'Street name', + `house_number` smallint(5) unsigned DEFAULT NULL COMMENT 'House number', + `city` varchar(100) DEFAULT NULL COMMENT 'City name', + `zip_code` smallint(5) unsigned DEFAULT NULL COMMENT 'ZIP code', + `country_code` char(2) DEFAULT NULL COMMENT 'Country code', + `phone_number` varchar(100) DEFAULT NULL COMMENT 'Phone number', + `cellphone_number` varchar(100) DEFAULT NULL COMMENT 'Cellphone number', + `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', + `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Entry created', + `updated` timestamp NULL DEFAULT NULL COMMENT 'Entry updated', + PRIMARY KEY (`id`) +) ENGINE=InnoDBDEFAULT CHARSET=utf8mb4 COMMENT='Contacts data' ; + +CREATE TABLE `customer` ( + `id` bigint(20) unsigned NOT NULL COMMENT 'Primay key', + `customer_contact_id` bigint(20) unsigned NOT NULL COMMENT 'Table reference on "contact"', + `customer_password_hash` varchar(255) COLLATE 'utf8mb4_general_ci' NOT 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', + PRIMARY KEY (`id`), + UNIQUE (`customer_confirm_key`), + INDEX (`customer_contact_id`) +) COMMENT='Customer data' ENGINE='InnoDB' COLLATE 'utf8mb4_general_ci'; + CREATE TABLE IF NOT EXISTS `products` ( -`id` bigint(20) unsigned NOT NULL COMMENT 'Primary key', - `category` bigint(20) unsigned DEFAULT NULL COMMENT 'Category id', - `title` varchar(255) NOT NULL COMMENT 'Title of product', - `price` decimal(20,2) unsigned NOT NULL COMMENT 'Product price', - `available` tinyint(1) NOT NULL DEFAULT '0' COMMENT 'Whether product is available', - PRIMARY KEY (`id`), - INDEX `category` (`category`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='Products' ; + `id` bigint(20) unsigned NOT NULL COMMENT 'Primary key', + `category` bigint(20) unsigned DEFAULT NULL COMMENT 'Category id', + `title` varchar(255) NOT NULL COMMENT 'Title of product', + `price` decimal(20,2) unsigned NOT NULL COMMENT 'Product price', + `available` tinyint(1) NOT NULL DEFAULT '0' COMMENT 'Whether product is available', + PRIMARY KEY (`id`), + INDEX `category` (`category`) +) ENGINE=InnoDBDEFAULT CHARSET=utf8mb4 COMMENT='Products' ; ALTER TABLE `category` MODIFY `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Primary key'; @@ -48,11 +58,17 @@ MODIFY `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Primary key'; ALTER TABLE `contacts` MODIFY `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Primary key'; +ALTER TABLE `customer` +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 `category` ADD FOREIGN KEY (`parent`) REFERENCES `category` (`id`) ON DELETE SET NULL; +ALTER TABLE `customer` +ADD FOREIGN KEY (`customer_contact_id`) REFERENCES `contacts` (`id`) ON DELETE CASCADE; + ALTER TABLE `products` ADD FOREIGN KEY (`category`) REFERENCES `category` (`id`) ON DELETE SET NULL;