forked from constanxe/portnet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy.sql
176 lines (149 loc) · 5.13 KB
/
deploy.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
-- Server version: 5.7.26
-- PHP Version: 7.2.18
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET AUTOCOMMIT = 0;
START TRANSACTION;
SET time_zone = "+00:00";
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;
--
-- Database: `vsta`
--
DROP DATABASE IF EXISTS `vsta`;
CREATE DATABASE IF NOT EXISTS `vsta`;
USE `vsta`;
-- --------------------------------------------------------
--
-- Table structure for table `user`
--
DROP TABLE IF EXISTS `user`;
CREATE TABLE IF NOT EXISTS `user` (
`id` int(11) AUTO_INCREMENT,
`name` varchar(32) NOT NULL,
`email` varchar(32) NOT NULL,
`password` varchar(60) NOT NULL,
`token` varchar(60),
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
--
-- Dumping data for table `user`
--
-- --------------------------------------------------------
--
-- Table structure for table `vessel`
--
DROP TABLE IF EXISTS `vessel`;
CREATE TABLE IF NOT EXISTS `vessel` (
`uniqueId` varchar(60) NOT NULL,
`imoN` varchar(12) DEFAULT NULL,
`fullVslM` varchar(48) NOT NULL,
`abbrVslM` varchar(32) NOT NULL,
`fullInVoyN` varchar(500) DEFAULT NULL,
`inVoyN` varchar(8) NOT NULL,
`fullOutVoyN` varchar(500) DEFAULT NULL,
`outVoyN` varchar(8) NOT NULL,
`shiftSeqN` varchar(5) NOT NULL,
`bthgDt` varchar(21) NOT NULL,
`unbthgDt` varchar(21) NOT NULL,
`berthN` varchar(10) DEFAULT NULL,
`status` varchar(12) NOT NULL,
`abbrTerminalM` varchar(8) DEFAULT NULL,
PRIMARY KEY (`uniqueId`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
--
-- Dumping data for table `vessel`
--
--
-- Triggers `vessel`
--
DROP TRIGGER IF EXISTS `before_insert_set_history`;
DELIMITER $$
CREATE TRIGGER `before_insert_set_history` BEFORE INSERT ON `vessel` FOR EACH ROW BEGIN
SET FOREIGN_KEY_CHECKS=0;
INSERT INTO vessel_history(uniqueId, last_bthgDt, last_unbthgDt, bthgDt_change_count, unbthgDt_change_count, first_arrival)
VALUES(new.uniqueId, new.`bthgDt`, new.`unbthgDt`, 0, 0, new.`bthgDt`);
END
$$
DELIMITER ;
DROP TRIGGER IF EXISTS `if_berth_changed_update_history`;
DELIMITER $$
CREATE TRIGGER `if_berth_changed_update_history` BEFORE UPDATE ON `vessel` FOR EACH ROW BEGIN
IF (NEW.unbthgDt <> OLD.unbthgDt AND NEW.bthgDt <> OLD.bthgDt) THEN
UPDATE vessel_history SET
last_bthgDt = OLD.`bthgDt`,
bthgDt_change_count = bthgDt_change_count + 1,
last_unbthgDt = OLD.`unbthgDt`,
unbthgDt_change_count = unbthgDt_change_count + 1
where `uniqueId` = NEW.`uniqueId`;
ELSEIF (NEW.`bthgDt` <> OLD.`bthgDt`) THEN
UPDATE vessel_history SET
last_bthgDt = OLD.`bthgDt`,
bthgDt_change_count = bthgDt_change_count + 1
where `uniqueId` = NEW.`uniqueId`;
ELSEIF (NEW.`unbthgDt` <> OLD.`unbthgDt`) THEN
UPDATE vessel_history SET
last_unbthgDt = OLD.`unbthgDt`,
unbthgDt_change_count = unbthgDt_change_count + 1
where `uniqueId` = NEW.`uniqueId`;
END IF;
END
$$
DELIMITER ;
-- --------------------------------------------------------
--
-- Table structure for table `vessel_history`
--
DROP TABLE IF EXISTS `vessel_history`;
CREATE TABLE IF NOT EXISTS `vessel_history` (
`uniqueId` varchar(60) NOT NULL,
`last_bthgDt` varchar(21) NOT NULL,
`last_unbthgDt` varchar(21) NOT NULL,
`bthgDt_change_count` int(2) NOT NULL DEFAULT '0',
`unbthgDt_change_count` int(2) NOT NULL DEFAULT '0',
`first_arrival` varchar(21) NOT NULL,
PRIMARY KEY (`uniqueId`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
--
-- Dumping data for table `vessel_history`
--
-- --------------------------------------------------------
--
-- Table structure for table `subscription`
--
DROP TABLE IF EXISTS `subscription`;
CREATE TABLE IF NOT EXISTS `subscription` (
`id` int(11) AUTO_INCREMENT,
`user_id` int(11) NOT NULL,
`voyage_id` varchar(60) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- --------------------------------------------------------
--
-- Table structure for table `favourite`
--
DROP TABLE IF EXISTS `favourite`;
CREATE TABLE IF NOT EXISTS `favourite` (
`id` int(11) AUTO_INCREMENT,
`user_id` int(11) NOT NULL,
`voyage_id` varchar(60) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
--
-- Constraints for table `vessel_history`
--
ALTER TABLE `vessel`
ADD CONSTRAINT `vessel_ibfk_1` FOREIGN KEY (`uniqueId`) REFERENCES `vessel_history` (`uniqueId`);
COMMIT;
ALTER TABLE `subscription`
ADD CONSTRAINT `subscription_ibfk_1` FOREIGN KEY (`voyage_id`) REFERENCES `vessel` (`uniqueId`),
ADD CONSTRAINT `subscription_ibfk_2` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`);
COMMIT;
ALTER TABLE `favourite`
ADD CONSTRAINT `favourite_ibfk_1` FOREIGN KEY (`voyage_id`) REFERENCES `vessel` (`uniqueId`),
ADD CONSTRAINT `favourite_ibfk_2` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`);
COMMIT;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;