From e5838736ab7b8e91896fd75f58f2a8caeb34d93f Mon Sep 17 00:00:00 2001 From: Chris Veilleux Date: Tue, 19 Mar 2019 16:46:15 -0500 Subject: [PATCH] changed device.geography table and device.preferences table to have references to geography schema tables --- .../tables/account_preferences.sql | 33 ++++++++++++++----- db/mycroft/device_schema/tables/geography.sql | 24 ++++++++------ db/scripts/bootstrap_mycroft_db.py | 12 +++---- 3 files changed, 44 insertions(+), 25 deletions(-) diff --git a/db/mycroft/device_schema/tables/account_preferences.sql b/db/mycroft/device_schema/tables/account_preferences.sql index 7ed206e8..fdf2ba4f 100644 --- a/db/mycroft/device_schema/tables/account_preferences.sql +++ b/db/mycroft/device_schema/tables/account_preferences.sql @@ -1,13 +1,28 @@ -- Account level preferences that pertain to device function. CREATE TABLE device.account_preferences ( - id uuid PRIMARY KEY DEFAULT gen_random_uuid(), - account_id uuid REFERENCES account.account ON DELETE CASCADE, - date_format date_format_enum NOT NULL DEFAULT 'MM/DD/YYYY', - time_format time_format_enum NOT NULL DEFAULT '12 Hour', - measurement_system measurement_system_enum NOT NULL DEFAULT 'Imperial', - wake_word_id uuid NOT NULL REFERENCES device.wake_word, - text_to_speech_id uuid NOT NULL REFERENCES device.text_to_speech, - geography_id uuid REFERENCES device.geography, - insert_ts TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP + id uuid PRIMARY KEY + DEFAULT gen_random_uuid(), + account_id uuid NOT NULL + REFERENCES account.account ON DELETE CASCADE, + date_format date_format_enum NOT NULL + DEFAULT 'MM/DD/YYYY', + time_format time_format_enum NOT NULL + DEFAULT '12 Hour', + measurement_system measurement_system_enum NOT NULL + DEFAULT 'Imperial', + wake_word_id uuid + REFERENCES device.wake_word, + text_to_speech_id uuid + REFERENCES device.text_to_speech, + country_id uuid + REFERENCES geography.country, + region_id uuid + REFERENCES geography.region, + city_id uuid + REFERENCES geography.city, + timezone_id uuid + REFERENCES geography.timezone, + insert_ts TIMESTAMP NOT NULL + DEFAULT CURRENT_TIMESTAMP ); diff --git a/db/mycroft/device_schema/tables/geography.sql b/db/mycroft/device_schema/tables/geography.sql index 0e336d49..4bcec3b9 100644 --- a/db/mycroft/device_schema/tables/geography.sql +++ b/db/mycroft/device_schema/tables/geography.sql @@ -1,12 +1,16 @@ CREATE TABLE device.geography ( - id uuid PRIMARY KEY DEFAULT gen_random_uuid(), - account_id uuid NOT NULL REFERENCES account.account ON DELETE CASCADE, - country text NOT NULL, - state text NOT NULL, - city text NOT NULL, - time_zone text, - latitude NUMERIC NOT NULL, - longitude NUMERIC NOT NULL, - insert_ts TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, - UNIQUE (account_id, latitude, longitude) + id uuid PRIMARY KEY DEFAULT gen_random_uuid(), + account_id uuid NOT NULL + REFERENCES account.account ON DELETE CASCADE, + country_id uuid NOT NULL + REFERENCES geography.country, + region_id uuid NOT NULL + REFERENCES geography.region, + city_id uuid NOT NULL + REFERENCES geography.city, + timezone_id uuid NOT NULL + REFERENCES geography.timezone, + insert_ts TIMESTAMP NOT NULL + DEFAULT CURRENT_TIMESTAMP, + UNIQUE (account_id, country_id, region_id, city_id, timezone_id) ); diff --git a/db/scripts/bootstrap_mycroft_db.py b/db/scripts/bootstrap_mycroft_db.py index 7d0a82c9..9cf92ab6 100644 --- a/db/scripts/bootstrap_mycroft_db.py +++ b/db/scripts/bootstrap_mycroft_db.py @@ -127,10 +127,10 @@ for table in SKILL_TABLE_ORDER: get_sql_from_file(create_table_file) ) -print('Creating the device schema tables') -for table in DEVICE_TABLE_ORDER: +print('Creating the geography schema tables') +for table in GEOGRAPHY_TABLE_ORDER: create_table_file = path.join( - 'device_schema', + 'geography_schema', 'tables', table + '.sql' ) @@ -138,10 +138,10 @@ for table in DEVICE_TABLE_ORDER: get_sql_from_file(create_table_file) ) -print('Creating the geography schema tables') -for table in GEOGRAPHY_TABLE_ORDER: +print('Creating the device schema tables') +for table in DEVICE_TABLE_ORDER: create_table_file = path.join( - 'geography_schema', + 'device_schema', 'tables', table + '.sql' )