From 9b038b3571e2ca77bc75c1059d721736f258e6e5 Mon Sep 17 00:00:00 2001 From: Daniel Schick Date: Sun, 1 Sep 2024 11:33:01 +0200 Subject: [PATCH] Database extension, first step --- misc/update_1.5_to_1.6.sql | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 misc/update_1.5_to_1.6.sql diff --git a/misc/update_1.5_to_1.6.sql b/misc/update_1.5_to_1.6.sql new file mode 100644 index 0000000..dc2e736 --- /dev/null +++ b/misc/update_1.5_to_1.6.sql @@ -0,0 +1,28 @@ +CREATE TABLE `port` ( + `id` int unsigned NOT NULL AUTO_INCREMENT, + `name` varchar(128) NOT NULL COMMENT 'Name of port', + `locode` char(5) DEFAULT NULL COMMENT 'UNECE locode', + `created` datetime DEFAULT CURRENT_TIMESTAMP, + `modified` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP, + `deleted` bit(1) DEFAULT b'0', + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Port as reference for shipcalls and berths'; + +-- Add default port to table +INSERT INTO port (id, name, locode) VALUES (1, 'Bremen', 'DEBRE'); + +-- Adding new ref column to berth +ALTER TABLE `bremen_calling_devel`.`berth` +ADD COLUMN `port_id` INT UNSIGNED NOT NULL DEFAULT 1 AFTER `authority_id`; +ALTER TABLE `bremen_calling_devel`.`berth` ALTER INDEX `FK_AUTHORITY_PART_idx` INVISIBLE; + +-- adding a foreign key berth.port_id -> port.id +ALTER TABLE `bremen_calling_devel`.`berth` +ADD INDEX `FK_PORT_PART_idx` (`port_id` ASC) VISIBLE; + +ALTER TABLE `bremen_calling_devel`.`berth` +ADD CONSTRAINT `FK_PORT` + FOREIGN KEY (`port_id`) + REFERENCES `bremen_calling_devel`.`port` (`id`) + ON DELETE RESTRICT + ON UPDATE RESTRICT;