salix/db/versions/10887-floranet/01-tables.sql

61 lines
2.6 KiB
SQL

CREATE OR REPLACE TABLE floranet.`builder` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`itemFk` int(11) NOT NULL,
`elementFk` int(11) NOT NULL,
`quantity` int(10) unsigned NOT NULL DEFAULT 1,
PRIMARY KEY (`id`),
KEY `builder_FK` (`itemFk`),
KEY `builder_FK_1` (`elementFk`),
CONSTRAINT `builder_FK` FOREIGN KEY (`itemFk`) REFERENCES `vn`.`item` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='Links handmade products with their elements';
CREATE OR REPLACE TABLE floranet.`element` (
`itemFk` int(11) NOT NULL,
`typeFk` smallint(5) unsigned DEFAULT NULL,
`size` int(11) DEFAULT NULL,
`inkFk` char(3) CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci DEFAULT NULL,
`originFk` tinyint(2) unsigned DEFAULT NULL,
`name` varchar(30) DEFAULT NULL,
`quantity` int(11) NOT NULL DEFAULT 1,
PRIMARY KEY (`itemFk`),
KEY `element_FK` (`itemFk`),
KEY `element_FK_1` (`typeFk`),
KEY `element_FK_2` (`inkFk`),
KEY `element_FK_3` (`originFk`),
CONSTRAINT `element_FK` FOREIGN KEY (`itemFk`) REFERENCES `vn`.`item` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `element_FK_1` FOREIGN KEY (`typeFk`) REFERENCES `vn`.`itemType` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `element_FK_2` FOREIGN KEY (`inkFk`) REFERENCES `vn`.`ink` (`id`) ON UPDATE CASCADE,
CONSTRAINT `element_FK_3` FOREIGN KEY (`originFk`) REFERENCES `vn`.`origin` (`id`) ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='Filtro para localizar posibles items que coincidan con la descripción';
ALTER TABLE floranet.builder ADD CONSTRAINT `builder_FK_1` FOREIGN KEY (`elementFk`) REFERENCES `element` (`itemFk`) ON UPDATE CASCADE;
CREATE OR REPLACE TABLE floranet.catalogue
(id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(50),
price DECIMAL(10,2) NOT NULL,
itemFk INT NOT NULL,
dated DATE,
postalCode VARCHAR(12),
`type` VARCHAR(50),
image VARCHAR(255),
description TEXT,
created TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
payed DATETIME,
FOREIGN KEY (itemFk) REFERENCES vn.item(id) ON DELETE RESTRICT ON UPDATE CASCADE);
CREATE OR REPLACE TABLE floranet.`order`
(id INT AUTO_INCREMENT PRIMARY KEY,
catalogueFk INT UNIQUE,
customerName VARCHAR(100),
email VARCHAR(100),
customerPhone VARCHAR(15),
message VARCHAR(255),
deliveryName VARCHAR(100),
address VARCHAR(200),
deliveryPhone VARCHAR(100),
isPaid BOOL NOT NULL DEFAULT FALSE,
payed DATETIME,
created TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (catalogueFk) REFERENCES catalogue(id) ON DELETE RESTRICT ON UPDATE CASCADE);