This repository has been archived by the owner on Jan 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 26
Improvements in RDS Schema #25
Merged
Merged
Changes from 8 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
b41d639
preliminary changes to schema
GabrielBogo 4dd4841
schema being created successfully
GabrielBogo cd58679
changes in gitignore to avoid uploading npm logs and terraform config…
GabrielBogo 6671a49
schema being created sucessfully, data_file being stored successfully
GabrielBogo e097f6d
bug corrections on the schema.
GabrielBogo 15aab7e
next pull request on sql schema
GabrielBogo 83570c9
change from JSON to JSONB
GabrielBogo ab5a3b7
Added confidence integer to alerts
schnuerle feab55b
removed irregularity ID from Alert
schnuerle 7924855
Update schema to support hashes
jrstill 5239452
Add IF NOT EXISTS on schema creation
jrstill 2ac1a29
correction of syntax error.
GabrielBogo aba3917
added unique index to data_files json hash
GabrielBogo 253b171
Update SQL schema
jrstill 9eea5b2
Update SQL schema
jrstill d2af87d
Update SQL schema
jrstill 8ac50bf
Update Schema
jrstill File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,5 @@ | |
\.vscode/ | ||
|
||
node_modules/ | ||
*.log | ||
*.terraform |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,96 +1,121 @@ | ||
CREATE SCHEMA waze; | ||
|
||
CREATE TABLE waze.data_files | ||
( | ||
"id" SERIAL PRIMARY KEY NOT NULL, | ||
"start_time_millis" BIGINT NOT NULL, | ||
"end_time_millis" BIGINT NOT NULL, | ||
"start_time" TIMESTAMP, | ||
"end_time" TIMESTAMP, | ||
"date_created" TIMESTAMP, | ||
"date_updated" TIMESTAMP, | ||
"file_name" TEXT NOT NULL, | ||
"json_hash" uuid NOT NULL, | ||
UNIQUE ("start_time_millis", "json_hash") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My plan is to actually embed the start_time_millis into the hash, so we won't need a separate unique constraint There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes agreed. |
||
); | ||
|
||
CREATE TABLE waze.jams | ||
( | ||
"id" BIGINT PRIMARY KEY NOT NULL, | ||
"uuid" VARCHAR[500] NOT NULL, | ||
"pub_millis" BIGINT NOT NULL, | ||
"start_node" VARCHAR[500], | ||
"end_node" VARCHAR[500], | ||
"road_type" INTEGER, | ||
"street" VARCHAR[500], | ||
"city" VARCHAR[500], | ||
"country" VARCHAR[500], | ||
"delay" INTEGER, | ||
"speed" float4, | ||
"length" INTEGER, | ||
"turn_type" VARCHAR[500], | ||
"level" INTEGER, | ||
"blocking_alert_id" VARCHAR[500] | ||
"id" SERIAL PRIMARY KEY NOT NULL, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Part of the hashing proposal was to have the primary key on each of alerts/jams/irregularities be the actual hash. So rather than having a serial id primary key we would have something like |
||
"uuid" TEXT NOT NULL, | ||
"pub_millis" BIGINT NOT NULL, | ||
"pub_utc_date" TIMESTAMP, | ||
"start_node" TEXT, | ||
"end_node" TEXT, | ||
"road_type" INTEGER, | ||
"street" TEXT, | ||
"city" TEXT, | ||
"country" TEXT, | ||
"delay" INTEGER, | ||
"speed" float4, | ||
"speed_kmh" float4, | ||
"length" INTEGER, | ||
"turn_type" TEXT, | ||
"level" INTEGER, | ||
"blocking_alert_id" TEXT, | ||
"line" JSONB, | ||
"datafile_id" BIGINT NOT NULL REFERENCES waze.data_files (id) | ||
); | ||
|
||
CREATE TABLE waze.alerts | ||
CREATE TABLE waze.alerts | ||
( | ||
"id" BIGINT PRIMARY KEY NOT NULL, | ||
"uuid" VARCHAR[500] NOT NULL, | ||
"pub_millis" BIGINT NOT NULL, | ||
"road_type" INTEGER, | ||
"street" VARCHAR[500], | ||
"city" VARCHAR[500], | ||
"country" VARCHAR[500], | ||
"magvar" INTEGER, | ||
"reliability" INTEGER, | ||
"report_description" VARCHAR[500], | ||
"report_rating" INTEGER, | ||
"type" VARCHAR[500], | ||
"subtype" VARCHAR[500], | ||
"report_by_municipality_user" BOOLEAN, | ||
"thumbs_up" INTEGER, | ||
"jam_id" VARCHAR[500] REFERENCES waze.jams (uuid), | ||
"irregularity_id" VARCHAR[500] REFERENCES waze.irregularities (uuid) | ||
"id" SERIAL PRIMARY KEY NOT NULL, | ||
"uuid" TEXT NOT NULL, | ||
"pub_millis" BIGINT NOT NULL, | ||
"pub_utc_date" TIMESTAMP, | ||
"road_type" INTEGER, | ||
"location" JSONB, | ||
"street" TEXT, | ||
"city" TEXT, | ||
"country" TEXT, | ||
"magvar" INTEGER, | ||
"reliability" INTEGER, | ||
"report_description" TEXT, | ||
"report_rating" INTEGER, | ||
"confidence" INTEGER, | ||
"type" TEXT, | ||
"subtype" TEXT, | ||
"report_by_municipality_user" BOOLEAN, | ||
"thumbs_up" INTEGER, | ||
"jam_uuid" TEXT, | ||
"irregularity_uuid" TEXT, | ||
"datafile_id" BIGINT NOT NULL REFERENCES waze.data_files (id) | ||
); | ||
|
||
CREATE TABLE waze.irregularities | ||
CREATE TABLE waze.irregularities | ||
( | ||
"id" BIGINT PRIMARY KEY NOT NULL, | ||
"uuid" VARCHAR[500] NOT NULL, | ||
"detection_date_millis" BIGINT NOT NULL, | ||
"detection_date" TIMESTAMP, | ||
"update_date_millis" BIGINT NOT NULL, | ||
"update_date" TIMESTAMP, | ||
"street" VARCHAR[500], | ||
"city" VARCHAR[500], | ||
"country" VARCHAR[500], | ||
"is_highway" BOOLEAN, | ||
"speed" float4, | ||
"regular_speed" float4, | ||
"delay_seconds" INTEGER, | ||
"seconds" INTEGER, | ||
"length" INTEGER, | ||
"trend" INTEGER, | ||
"type" VARCHAR[500], | ||
"severity" float4, | ||
"jam_level" INTEGER, | ||
"drivers_count" INTEGER, | ||
"alerts_count" INTEGER, | ||
"n_thumbs_up" INTEGER, | ||
"n_comments" INTEGER, | ||
"n_images" INTEGER | ||
"id" SERIAL PRIMARY KEY NOT NULL, | ||
"uuid" TEXT NOT NULL, | ||
"detection_date_millis" BIGINT NOT NULL, | ||
"detection_date" TEXT, | ||
"detection_utc_date" TIMESTAMP, | ||
"update_date_millis" BIGINT NOT NULL, | ||
"update_date" TEXT, | ||
"update_utc_date" TIMESTAMP, | ||
"street" TEXT, | ||
"city" TEXT, | ||
"country" TEXT, | ||
"is_highway" BOOLEAN, | ||
"speed" float4, | ||
"regular_speed" float4, | ||
"delay_seconds" INTEGER, | ||
"seconds" INTEGER, | ||
"length" INTEGER, | ||
"trend" INTEGER, | ||
"type" TEXT, | ||
"severity" float4, | ||
"jam_level" INTEGER, | ||
"drivers_count" INTEGER, | ||
"alerts_count" INTEGER, | ||
"n_thumbs_up" INTEGER, | ||
"n_comments" INTEGER, | ||
"n_images" INTEGER, | ||
"line" JSONB, | ||
"datafile_id" BIGINT NOT NULL REFERENCES waze.data_files (id) | ||
); | ||
|
||
|
||
CREATE TABLE waze.coordinates | ||
( | ||
"id" BIGINT PRIMARY KEY NOT NULL, | ||
"latitude" float8 NOT NULL, | ||
"longitude" float8 NOT NULL, | ||
"order" INTEGER NOT NULL, | ||
"jam_id" BIGINT REFERENCES waze.jams (id), | ||
"irregularity_id" BIGINT REFERENCES waze.irregularities (id), | ||
"alert_id" BIGINT REFERENCES waze.alerts (id) | ||
"id" SERIAL PRIMARY KEY NOT NULL, | ||
"latitude" float8 NOT NULL, | ||
"longitude" float8 NOT NULL, | ||
"order" INTEGER NOT NULL, | ||
"jam_id" BIGINT REFERENCES waze.jams (id), | ||
"irregularity_id" BIGINT REFERENCES waze.irregularities (id), | ||
"alert_id" BIGINT REFERENCES waze.alerts (id) | ||
); | ||
|
||
CREATE TABLE waze.roads | ||
( | ||
"id" INTEGER PRIMARY KEY NOT NULL, | ||
"value" INTEGER NOT NULL, | ||
"name" VARCHAR[100] NOT NULL | ||
"id" SERIAL PRIMARY KEY NOT NULL, | ||
"value" INTEGER NOT NULL, | ||
"name" VARCHAR[100] NOT NULL | ||
); | ||
|
||
CREATE TABLE waze.alert_types | ||
( | ||
"id" BIGINT PRIMARY KEY NOT NULL, | ||
"type" VARCHAR[500] NOT NULL, | ||
"subtype" VARCHAR[500] | ||
"id" SERIAL PRIMARY KEY NOT NULL, | ||
"type" TEXT NOT NULL, | ||
"subtype" TEXT | ||
); | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The hash we create will be SHA1 , so this probably needs to be a varchar(40)