# Database Bremen Calling ## Server mariadb v 10 ## Getting started - Execute 'create_schema.sql' and import 'sample_data.sql' If the database is updated or changed, please update these files. To avoid errors, it is best to drop the entire database, edit the create script and re-import the sample data. ## Creating the dump file ```bash mysqldump -u [username] -p --no-create-info --complete-insert bremen_calling > sample_data.sql ``` ## Removing existing tables We want only to remove the tables in order to preserve user privileges ```sql SELECT concat('DROP TABLE IF EXISTS `', table_name, '`;') FROM information_schema.tables WHERE table_schema = 'bremen_calling'; ``` outputs complete drop statements ```sql SET FOREIGN_KEY_CHECKS = 0; -- Your semicolon separated list of DROP statements here DROP TABLE IF EXISTS `notification`; DROP TABLE IF EXISTS `role`; DROP TABLE IF EXISTS `ship`; DROP TABLE IF EXISTS `participant`; DROP TABLE IF EXISTS `times`; DROP TABLE IF EXISTS `role_securable_map`; DROP TABLE IF EXISTS `user_role_map`; DROP TABLE IF EXISTS `user`; DROP TABLE IF EXISTS `securable`; DROP TABLE IF EXISTS `shipcall_participant_map`; DROP TABLE IF EXISTS `berth`; DROP TABLE IF EXISTS `shipcall`; SET FOREIGN_KEY_CHECKS = 1; ``` ## Schema ```mermaid erDiagram participant { INT id PK VARCHAR name VARCHAR street VARCHAR postal_code VARCHAR city INT type INT flags } port { INT id PK VARCHAR name CHAR locode } berth { INT id PK VARCHAR name BIT lock INT owner_id FK INT authority_id FK INT port_id FK BIT deleted } ship { INT id PK VARCHAR name INT imo VARCHAR callsign INT participant_id FK FLOAT length FLOAT width BIT is_tug INT bollard_pull INT eni BIT deleted } shipcall { INT id PK INT ship_id FK TINYINT type DATETIME eta DATETIME etd INT arrival_berth_id FK INT departure_berth_id FK INT port_id FK INT flags BIT tug_required BIT pilot_required } times { INT id PK INT shipcall_id FK INT participant_id FK INT berth_id FK INT participant_type DATETIME eta_berth DATETIME etd_berth DATETIME lock_time DATETIME zone_entry } notification { INT id PK INT shipcall_id FK INT participant_id FK TINYINT level TINYINT type } history { INT id PK INT participant_id FK INT user_id FK INT shipcall_id FK DATETIME timestamp DATETIME eta INT type INT operation } shipcall_participant_map { INT id PK INT shipcall_id FK INT participant_id FK INT type } shipcall_tug_map { INT id PK INT shipcall_id FK INT ship_id FK } participant_port_map { INT id PK INT participant_id FK INT port_id FK } user { INT id PK INT participant_id FK VARCHAR first_name VARCHAR last_name VARCHAR user_name VARCHAR user_email } role { INT id PK VARCHAR name VARCHAR description } securable { INT id PK VARCHAR name } role_securable_map { INT id PK INT role_id FK INT securable_id FK } user_role_map { INT id PK INT user_id FK INT role_id FK } participant ||--o{ berth : owner_id participant ||--o{ berth : authority_id port ||--o{ berth : port_id participant ||--o{ ship : participant_id ship ||--o{ shipcall : ship_id berth ||--o{ shipcall : arrival_berth_id berth ||--o{ shipcall : departure_berth_id port ||--o{ shipcall : port_id shipcall ||--|| times : shipcall_id participant ||--|| times : participant_id berth ||--o{ times : berth_id shipcall ||--o{ notification : shipcall_id participant ||--o{ notification : participant_id participant ||--o{ history : participant_id user ||--o{ history : user_id shipcall ||--o{ history : shipcall_id shipcall ||--o{ shipcall_participant_map : shipcall_id participant ||--o{ shipcall_participant_map : participant_id shipcall ||--o{ shipcall_tug_map : shipcall_id ship ||--o{ shipcall_tug_map : ship_id participant ||--o{ participant_port_map : participant_id port ||--o{ participant_port_map : port_id participant ||--o{ user : participant_id user ||--o{ user_role_map : user_id role ||--o{ user_role_map : role_id role ||--o{ role_securable_map : role_id securable ||--o{ role_securable_map : securable_id ```