CREATE DATABASE `bremen_calling` /*!40100 DEFAULT CHARACTER SET utf8mb4 */;

CREATE TABLE `participant` (
  `id` int(10) 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,
  `flags` int(10) unsigned DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='An organization taking part';


CREATE TABLE `ship` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(45) DEFAULT NULL,
  `imo` int(11) DEFAULT NULL,
  `callsign` varchar(8) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;


CREATE TABLE `shipcall` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `ship_id` int(11) DEFAULT NULL,
  `arrival_berth_id` int(11) DEFAULT NULL,
  `departure_berth_id` int(11) DEFAULT NULL,
  `type` tinyint(4) DEFAULT NULL,
  `eta` datetime DEFAULT NULL,
  `voyage` varchar(16) DEFAULT NULL,
  `etd` datetime DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='Incoming, outgoing or moving to another berth	';


CREATE TABLE `times` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `start_planned` datetime DEFAULT NULL,
  `end_planned` datetime DEFAULT NULL,
  `duration_planned` int(11) DEFAULT NULL,
  `start_actual` datetime DEFAULT NULL,
  `end_actual` datetime DEFAULT NULL,
  `duration_actual` int(11) DEFAULT NULL,
  `shipcall_id` int(11) DEFAULT NULL,
  `participant_id` int(11) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='the planned time for the participants work';


CREATE TABLE `user` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `participant_id` int(11) DEFAULT NULL,
  `first_name` varchar(45) DEFAULT NULL,
  `last_name` varchar(45) DEFAULT NULL,
  `user_name` varchar(45) DEFAULT NULL,
  `password_hash` varchar(128) DEFAULT NULL,
  `api_key` varchar(256) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='member of a participant';


CREATE TABLE `participant` (
  `id` int(10) 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,
  `flags` int(10) unsigned DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='An organization taking part';

CREATE TABLE `berth` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `name1` varchar(128) DEFAULT NULL,
  `name2` varchar(128) DEFAULT NULL,
  PRIMARY KEY(`id`) 
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='Place of ship for a ship call';
