-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDatabase.sql
70 lines (57 loc) · 2.62 KB
/
Database.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
CREATE SCHEMA "Tide";
---
CREATE TABLE "Tide"."Country"
(
"Code" CHAR(2) PRIMARY KEY NOT NULL,
"Name" VARCHAR(32) NOT NULL,
"Active" BOOLEAN DEFAULT TRUE NOT NULL
);
CREATE TABLE "Tide"."Organization"
(
"Id" SERIAL PRIMARY KEY NOT NULL,
"Name" VARCHAR(128) NOT NULL,
"CountryCode" CHAR(2) NOT NULL,
"Active" BOOLEAN DEFAULT TRUE NOT NULL,
CONSTRAINT FK_Organization FOREIGN KEY ("CountryCode") REFERENCES "Tide"."Country" ("Code")
);
CREATE INDEX idx1 ON "Tide"."Organization" ("CountryCode");
CREATE TABLE "Tide"."Station"
(
"Code" CHAR(4) PRIMARY KEY NOT NULL,
"Name" VARCHAR(128) NOT NULL,
"Location" VARCHAR(512) NOT NULL,
"IpAddress" VARCHAR(15) NOT NULL,
"Latitude" FLOAT NOT NULL,
"Longitude" FLOAT NOT NULL,
"Depth" FLOAT NOT NULL,
"OrganizationId" INTEGER NOT NULL,
"Active" BOOLEAN DEFAULT TRUE NOT NULL,
CONSTRAINT FK_Station FOREIGN KEY ("OrganizationId") REFERENCES "Tide"."Organization" ("Id")
);
CREATE INDEX idx2 ON "Tide"."Station" ("OrganizationId");
CREATE TABLE "Tide"."Data"
(
"Id" SERIAL PRIMARY KEY NOT NULL,
"StationCode" CHAR(4) NOT NULL,
"Time" TIMESTAMP NOT NULL,
"Value" FLOAT NOT NULL,
CONSTRAINT FK_Data FOREIGN KEY ("StationCode") REFERENCES "Tide"."Station" ("Code")
);
CREATE INDEX idx3 ON "Tide"."Data" ("StationCode");
CREATE INDEX idx4 ON "Tide"."Data" ("Time");
CREATE INDEX idx5 ON "Tide"."Data" ("StationCode", "Time");
---
INSERT INTO "Tide"."Country" ("Code", "Name")
VALUES ('NI', 'Nicaragua');
INSERT INTO "Tide"."Organization" ("Name", "CountryCode")
VALUES ('Central American Tsunami Advisory Center', 'NI');
INSERT INTO "Tide"."Station" ("Code", "Name", "Location", "IpAddress", "Latitude", "Longitude", "Depth",
"OrganizationId")
VALUES ('pblu', 'Puerto El Bluff', 'Puerto El Bluff', '', 0, 0, 0, 1),
('asro', 'Aserraderos', 'Aserraderos', '', 0, 0, 0, 1),
('pbil', 'Puerto Bilwi', 'Puerto Bilwi', '', 0, 0, 0, 1),
('pots', 'Puerto Potosi', 'Puerto Potosi', '186.77.179.158', 0, 0, 0, 1),
('pcoi', 'Muelle de Corn Island', 'Muelle de Corn Island', '', 0, 0, 0, 1),
('psan', 'Puerto Sandino', 'Puerto Sandino', '', 0, 0, 0, 1),
('pcrt', 'Puerto Corinto', 'Puerto Corinto', '186.77.179.147', 0, 0, 0, 1),
('psjs', 'Puerto San Juan del Sur', 'Puerto San Juan del Sur', '186.77.179.154', 0, 0, 0, 1);