-- --------------------------------------------------------
-- Host:                         127.0.0.1
-- Server Version:               8.0.34-0ubuntu0.22.04.1 - (Ubuntu)
-- Server Betriebssystem:        Linux
-- HeidiSQL Version:             10.2.0.5599
-- --------------------------------------------------------

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET NAMES utf8 */;
/*!50503 SET NAMES utf8mb4 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;

-- Exportiere Struktur von Tabelle bremen_calling.berth
CREATE TABLE IF NOT EXISTS `berth` (
  `id` int unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(128) DEFAULT NULL COMMENT 'Descriptive name',
  `participant_id` int unsigned DEFAULT NULL COMMENT 'If berth belongs to a participant, reference it here',
  `lock` bit(1) DEFAULT NULL COMMENT 'The lock must be used',
  `created` datetime DEFAULT CURRENT_TIMESTAMP,
  `modified` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `deleted` bit(1) DEFAULT b'0',
  PRIMARY KEY (`id`),
  KEY `FK_BERTH_PART` (`participant_id`),
  CONSTRAINT `FK_BERTH_PART` FOREIGN KEY (`participant_id`) REFERENCES `participant` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Berth of ship for a ship call';

-- Daten Export vom Benutzer nicht ausgewählt

-- Exportiere Struktur von Tabelle bremen_calling.notification
CREATE TABLE IF NOT EXISTS `notification` (
  `id` int unsigned NOT NULL AUTO_INCREMENT,
  `times_id` int unsigned NOT NULL COMMENT 'times record that caused the notification',
  `participant_id` int unsigned NOT NULL COMMENT 'participant ref',
  `acknowledged` bit(1) DEFAULT b'0' COMMENT 'true if UI acknowledged',
  `level` tinyint DEFAULT NULL COMMENT 'severity of the notification',
  `type` tinyint DEFAULT NULL COMMENT 'Email/UI/Other',
  `message` varchar(256) DEFAULT NULL COMMENT 'individual message',
  `created` datetime DEFAULT CURRENT_TIMESTAMP,
  `modified` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  KEY `FK_NOT_TIMES` (`times_id`),
  KEY `FK_NOT_PART` (`participant_id`),
  CONSTRAINT `FK_NOT_PART` FOREIGN KEY (`participant_id`) REFERENCES `participant` (`id`),
  CONSTRAINT `FK_NOT_TIMES` FOREIGN KEY (`times_id`) REFERENCES `times` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='An entry corresponds to an alarm given by a violated rule during times update';

-- Daten Export vom Benutzer nicht ausgewählt

-- Exportiere Struktur von Tabelle bremen_calling.participant
CREATE TABLE IF NOT EXISTS `participant` (
  `id` int unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(128) DEFAULT NULL,
  `street` varchar(128) DEFAULT NULL,
  `postal_code` varchar(5) DEFAULT NULL,
  `city` varchar(64) DEFAULT NULL,
  `type` int DEFAULT NULL,
  `flags` int unsigned DEFAULT NULL,
  `created` datetime DEFAULT CURRENT_TIMESTAMP,
  `modified` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `deleted` bit(1) DEFAULT b'0',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=12 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='An organization taking part';

-- Daten Export vom Benutzer nicht ausgewählt

-- Exportiere Struktur von Tabelle bremen_calling.role
CREATE TABLE IF NOT EXISTS `role` (
  `id` int unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(50) NOT NULL DEFAULT '0' COMMENT 'unique role name',
  `description` varchar(255) DEFAULT '0' COMMENT 'role description',
  `created` datetime DEFAULT CURRENT_TIMESTAMP,
  `modified` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  UNIQUE KEY `name` (`name`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='logical group of securables for one or more user';

-- Daten Export vom Benutzer nicht ausgewählt

-- Exportiere Struktur von Tabelle bremen_calling.role_securable_map
CREATE TABLE IF NOT EXISTS `role_securable_map` (
  `id` int unsigned NOT NULL AUTO_INCREMENT,
  `role_id` int unsigned NOT NULL,
  `securable_id` int unsigned NOT NULL,
  `created` datetime DEFAULT CURRENT_TIMESTAMP,
  `modified` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  KEY `FK_ROLE_SECURABLE` (`role_id`),
  KEY `FK_SECURABLE_ROLE` (`securable_id`),
  CONSTRAINT `FK_ROLE_SECURABLE` FOREIGN KEY (`role_id`) REFERENCES `role` (`id`),
  CONSTRAINT `FK_SECURABLE_ROLE` FOREIGN KEY (`securable_id`) REFERENCES `securable` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Assigns securables to roles';

-- Daten Export vom Benutzer nicht ausgewählt

-- Exportiere Struktur von Tabelle bremen_calling.securable
CREATE TABLE IF NOT EXISTS `securable` (
  `id` int unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(50) NOT NULL DEFAULT '',
  `created` datetime DEFAULT CURRENT_TIMESTAMP,
  `modified` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  UNIQUE KEY `name` (`name`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Actual permission on a single(!) feature or operation';

-- Daten Export vom Benutzer nicht ausgewählt

-- Exportiere Struktur von Tabelle bremen_calling.ship
CREATE TABLE IF NOT EXISTS `ship` (
  `id` int unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(64) DEFAULT NULL,
  `imo` int DEFAULT NULL,
  `callsign` varchar(8) DEFAULT NULL,
  `participant_id` int unsigned DEFAULT NULL,
  `length` float DEFAULT NULL,
  `width` float DEFAULT NULL,
  `is_tug` bit(1) DEFAULT b'0',
  `bollard_pull` int DEFAULT NULL,
  `eni` int DEFAULT NULL,
  `created` datetime DEFAULT CURRENT_TIMESTAMP,
  `modified` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  `deleted` bit(1) DEFAULT b'0',
  PRIMARY KEY (`id`),
  KEY `FK_SHIP_PARTICIPANT` (`participant_id`),
  CONSTRAINT `FK_SHIP_PARTICIPANT` FOREIGN KEY (`participant_id`) REFERENCES `participant` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

-- Daten Export vom Benutzer nicht ausgewählt

-- Exportiere Struktur von Tabelle bremen_calling.shipcall
CREATE TABLE IF NOT EXISTS `shipcall` (
  `id` int unsigned NOT NULL AUTO_INCREMENT,
  `ship_id` int unsigned DEFAULT NULL,
  `type` tinyint DEFAULT NULL,
  `eta` datetime DEFAULT NULL,
  `voyage` varchar(16) DEFAULT NULL,
  `etd` datetime DEFAULT NULL,
  `arrival_berth_id` int unsigned DEFAULT NULL,
  `departure_berth_id` int unsigned DEFAULT NULL,
  `tug_required` bit(1) DEFAULT NULL,
  `pilot_required` bit(1) DEFAULT NULL,
  `flags` int unsigned DEFAULT '0',
  `pier_side` bit(1) DEFAULT NULL,
  `bunkering` bit(1) DEFAULT NULL,
  `replenishing_terminal` bit(1) DEFAULT NULL,
  `replenishing_lock` bit(1) DEFAULT NULL,
  `draft` float DEFAULT NULL,
  `tidal_window_from` datetime DEFAULT NULL,
  `tidal_window_to` datetime DEFAULT NULL,
  `rain_sensitive_cargo` bit(1) DEFAULT b'0',
  `recommended_tugs` int DEFAULT '0',
  `anchored` bit(1) DEFAULT NULL,
  `moored_lock` bit(1) DEFAULT NULL,
  `canceled` bit(1) DEFAULT NULL,
  `created` datetime DEFAULT CURRENT_TIMESTAMP,
  `modified` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  KEY `FK_SHIPCALL_SHIP` (`ship_id`),
  KEY `FK_SHIPCALL_BERTH_ARRIVAL` (`arrival_berth_id`),
  KEY `FK_SHIPCALL_BERTH_DEPARTURE` (`departure_berth_id`),
  CONSTRAINT `FK_SHIPCALL_BERTH_ARRIVAL` FOREIGN KEY (`arrival_berth_id`) REFERENCES `berth` (`id`),
  CONSTRAINT `FK_SHIPCALL_BERTH_DEPARTURE` FOREIGN KEY (`departure_berth_id`) REFERENCES `berth` (`id`),
  CONSTRAINT `FK_SHIPCALL_SHIP` FOREIGN KEY (`ship_id`) REFERENCES `ship` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Incoming, outgoing or moving to another berth';

-- Daten Export vom Benutzer nicht ausgewählt

-- Exportiere Struktur von Tabelle bremen_calling.shipcall_participant_map
CREATE TABLE IF NOT EXISTS `shipcall_participant_map` (
  `id` int NOT NULL AUTO_INCREMENT,
  `shipcall_id` int unsigned DEFAULT NULL,
  `participant_id` int unsigned DEFAULT NULL,
  `created` datetime DEFAULT CURRENT_TIMESTAMP,
  `modified` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  KEY `FK_MAP_PARTICIPANT_SHIPCALL` (`shipcall_id`),
  KEY `FK_MAP_SHIPCALL_PARTICIPANT` (`participant_id`),
  CONSTRAINT `FK_MAP_PARTICIPANT_SHIPCALL` FOREIGN KEY (`shipcall_id`) REFERENCES `shipcall` (`id`),
  CONSTRAINT `FK_MAP_SHIPCALL_PARTICIPANT` FOREIGN KEY (`participant_id`) REFERENCES `participant` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=28 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Associates a participant with a shipcall';

-- Daten Export vom Benutzer nicht ausgewählt

-- Exportiere Struktur von Tabelle bremen_calling.shipcall_tug_map
CREATE TABLE IF NOT EXISTS `shipcall_tug_map` (
  `id` int NOT NULL AUTO_INCREMENT,
  `shipcall_id` int unsigned NOT NULL COMMENT 'Ref to ship call',
  `ship_id` int unsigned NOT NULL COMMENT 'Ref to ship (that is a tug)',
  `created` datetime DEFAULT CURRENT_TIMESTAMP,
  `modified` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  KEY `FK_SCT_SHIP` (`ship_id`),
  KEY `FK_SCT_SHIPCALL` (`shipcall_id`),
  CONSTRAINT `FK_SCT_SHIP` FOREIGN KEY (`ship_id`) REFERENCES `ship` (`id`),
  CONSTRAINT `FK_SCT_SHIPCALL` FOREIGN KEY (`shipcall_id`) REFERENCES `shipcall` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Mapping table that assigns tugs to a ship call';

-- Daten Export vom Benutzer nicht ausgewählt

-- Exportiere Struktur von Tabelle bremen_calling.times
CREATE TABLE IF NOT EXISTS `times` (
  `id` int unsigned NOT NULL AUTO_INCREMENT,
  `eta_berth` datetime DEFAULT NULL,
  `eta_berth_fixed` bit(1) DEFAULT NULL,
  `etd_berth` datetime DEFAULT NULL,
  `etd_berth_fixed` bit(1) DEFAULT NULL,
  `lock_time` datetime DEFAULT NULL,
  `lock_time_fixed` bit(1) DEFAULT NULL,
  `zone_entry` datetime DEFAULT NULL,
  `zone_entry_fixed` bit(1) DEFAULT NULL,
  `operations_start` datetime DEFAULT NULL,
  `operations_end` datetime DEFAULT NULL,
  `remarks` varchar(512) DEFAULT NULL,
  `shipcall_id` int unsigned NOT NULL,
  `participant_id` int unsigned NOT NULL,
  `created` datetime DEFAULT CURRENT_TIMESTAMP,
  `modified` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  KEY `FK_TIME_SHIPCALL` (`shipcall_id`),
  KEY `FK_TIME_PART` (`participant_id`),
  CONSTRAINT `FK_TIME_PART` FOREIGN KEY (`participant_id`) REFERENCES `participant` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='the planned time for the participants work';

-- Daten Export vom Benutzer nicht ausgewählt

-- Exportiere Struktur von Tabelle bremen_calling.user
CREATE TABLE IF NOT EXISTS `user` (
  `id` int unsigned NOT NULL AUTO_INCREMENT,
  `participant_id` int unsigned DEFAULT NULL,
  `first_name` varchar(45) DEFAULT NULL,
  `last_name` varchar(45) DEFAULT NULL,
  `user_name` varchar(45) DEFAULT NULL,
  `user_email` varchar(128) DEFAULT NULL,
  `user_phone` varchar(128) DEFAULT NULL,
  `password_hash` varchar(128) DEFAULT NULL,
  `api_key` varchar(256) DEFAULT NULL,
  `created` datetime DEFAULT CURRENT_TIMESTAMP,
  `modified` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  KEY `FK_USER_PART` (`participant_id`),
  CONSTRAINT `FK_USER_PART` FOREIGN KEY (`participant_id`) REFERENCES `participant` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=25 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='member of a participant';

-- Daten Export vom Benutzer nicht ausgewählt

-- Exportiere Struktur von Tabelle bremen_calling.user_role_map
CREATE TABLE IF NOT EXISTS `user_role_map` (
  `id` int unsigned NOT NULL AUTO_INCREMENT,
  `user_id` int unsigned NOT NULL DEFAULT '0',
  `role_id` int unsigned NOT NULL DEFAULT '0',
  `created` datetime DEFAULT CURRENT_TIMESTAMP,
  `modified` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  KEY `FK_USER_ROLE` (`user_id`),
  KEY `FK_ROLE_USER` (`role_id`),
  CONSTRAINT `FK_ROLE_USER` FOREIGN KEY (`role_id`) REFERENCES `role` (`id`),
  CONSTRAINT `FK_USER_ROLE` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Assigns a user to a role';

-- Daten Export vom Benutzer nicht ausgewählt

/*!40101 SET SQL_MODE=IFNULL(@OLD_SQL_MODE, '') */;
/*!40014 SET FOREIGN_KEY_CHECKS=IF(@OLD_FOREIGN_KEY_CHECKS IS NULL, 1, @OLD_FOREIGN_KEY_CHECKS) */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
