From 9e423044e70fcfc7316491137d5f9b799de72bec Mon Sep 17 00:00:00 2001 From: jina2k <jina26p@gmail.com> Date: Mon, 8 Nov 2021 01:07:48 -0500 Subject: [PATCH 1/5] added map to available default chart types --- .../app/components/admin/PreferencesComponent.tsx | 13 +++++++++++++ .../sql/preferences/create_graph_types_enum.sql | 4 +++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/client/app/components/admin/PreferencesComponent.tsx b/src/client/app/components/admin/PreferencesComponent.tsx index 6bbbe7c05..29a68ba5e 100644 --- a/src/client/app/components/admin/PreferencesComponent.tsx +++ b/src/client/app/components/admin/PreferencesComponent.tsx @@ -117,6 +117,19 @@ class PreferencesComponent extends React.Component<PreferencesPropsWithIntl, {}> <FormattedMessage id='compare'/> </label> </div> + <div className='radio'> + <label> + <input + type='radio' + name='chartTypes' + style={{marginRight: '10px'}} + value={ChartTypes.map} + onChange={this.handleDefaultChartToRenderChange} + checked={this.props.defaultChartToRender === ChartTypes.map} + /> + <FormattedMessage id='map'/> + </label> + </div> </div> <div className='checkbox'> <p style={labelStyle}> diff --git a/src/server/sql/preferences/create_graph_types_enum.sql b/src/server/sql/preferences/create_graph_types_enum.sql index d63641477..8ff804bf0 100644 --- a/src/server/sql/preferences/create_graph_types_enum.sql +++ b/src/server/sql/preferences/create_graph_types_enum.sql @@ -5,7 +5,9 @@ -- This should avoid an error when the type already exists. This is an issue since -- the OED install stops the creation of database items after this. DO $$ BEGIN - CREATE TYPE graph_type AS ENUM('line', 'bar', 'compare'); + CREATE TYPE graph_type AS ENUM('line', 'bar', 'compare', 'map'); + ALTER TABLE preferences ALTER COLUMN default_chart_to_render SET DATA TYPE graph_type + USING default_chart_to_render::text::graph_type; EXCEPTION WHEN duplicate_object THEN null; END $$; From 000076c9ce235d5d447da45d440d587632612156 Mon Sep 17 00:00:00 2001 From: jina2k <jina26p@gmail.com> Date: Mon, 8 Nov 2021 17:59:36 -0500 Subject: [PATCH 2/5] changed sql query to separate altering and create graph_type, now in migrations instead --- .../sql/preferences/alter_preferences_type.sql | 9 +++++++++ src/server/sql/preferences/create_graph_types_enum.sql | 2 -- 2 files changed, 9 insertions(+), 2 deletions(-) create mode 100644 src/server/migrations/0.7.0-0.7.1/sql/preferences/alter_preferences_type.sql diff --git a/src/server/migrations/0.7.0-0.7.1/sql/preferences/alter_preferences_type.sql b/src/server/migrations/0.7.0-0.7.1/sql/preferences/alter_preferences_type.sql new file mode 100644 index 000000000..61e50dac9 --- /dev/null +++ b/src/server/migrations/0.7.0-0.7.1/sql/preferences/alter_preferences_type.sql @@ -0,0 +1,9 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +DO $$ BEGIN + ALTER TYPE graph_type ADD VALUE 'map' AFTER 'compare'; +EXCEPTION + WHEN duplicate_object THEN null; +END $$; \ No newline at end of file diff --git a/src/server/sql/preferences/create_graph_types_enum.sql b/src/server/sql/preferences/create_graph_types_enum.sql index 8ff804bf0..52a2d25e8 100644 --- a/src/server/sql/preferences/create_graph_types_enum.sql +++ b/src/server/sql/preferences/create_graph_types_enum.sql @@ -6,8 +6,6 @@ -- the OED install stops the creation of database items after this. DO $$ BEGIN CREATE TYPE graph_type AS ENUM('line', 'bar', 'compare', 'map'); - ALTER TABLE preferences ALTER COLUMN default_chart_to_render SET DATA TYPE graph_type - USING default_chart_to_render::text::graph_type; EXCEPTION WHEN duplicate_object THEN null; END $$; From 8fa71ed11647212dea7f8222db010cb10f629f72 Mon Sep 17 00:00:00 2001 From: jina2k <jina26p@gmail.com> Date: Mon, 8 Nov 2021 18:35:20 -0500 Subject: [PATCH 3/5] migrations files --- src/server/migrations/0.5.0-0.6.0/index.js | 19 +++++++++++++++++++ .../0.5.0-0.6.0/sql/map/create_maps_table.sql | 15 +++++++++++++++ .../0.5.0-0.6.0/sql/meter/add_gps_column.sql | 6 ++++++ .../sql/meter/add_identifier_column.sql | 8 ++++++++ .../sql/meter/add_meters_default_timezone.sql | 9 +++++++++ .../preferences/add_language_types_enum.sql | 9 +++++++++ .../add_preferences_default_timezone.sql | 9 +++++++++ .../migrations/0.7.0-0.7.1/sql/index.js | 14 ++++++++++++++ src/server/migrations/registerMigration.js | 4 +++- 9 files changed, 92 insertions(+), 1 deletion(-) create mode 100644 src/server/migrations/0.5.0-0.6.0/index.js create mode 100644 src/server/migrations/0.5.0-0.6.0/sql/map/create_maps_table.sql create mode 100644 src/server/migrations/0.5.0-0.6.0/sql/meter/add_gps_column.sql create mode 100644 src/server/migrations/0.5.0-0.6.0/sql/meter/add_identifier_column.sql create mode 100644 src/server/migrations/0.5.0-0.6.0/sql/meter/add_meters_default_timezone.sql create mode 100644 src/server/migrations/0.5.0-0.6.0/sql/preferences/add_language_types_enum.sql create mode 100644 src/server/migrations/0.5.0-0.6.0/sql/preferences/add_preferences_default_timezone.sql create mode 100644 src/server/migrations/0.7.0-0.7.1/sql/index.js diff --git a/src/server/migrations/0.5.0-0.6.0/index.js b/src/server/migrations/0.5.0-0.6.0/index.js new file mode 100644 index 000000000..bbf36aec5 --- /dev/null +++ b/src/server/migrations/0.5.0-0.6.0/index.js @@ -0,0 +1,19 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +const database = require('../../models/database'); +const sqlFile = database.sqlFile; + +module.exports = { + fromVersion: '0.5.0', + toVersion: '0.6.0', + up: async db => { + await db.none(sqlFile('../migrations/0.5.0-0.6.0/sql/map/create_maps_table.sql')); + await db.none(sqlFile('../migrations/0.5.0-0.6.0/sql/meter/add_gps_column.sql')); + await db.none(sqlFile('../migrations/0.5.0-0.6.0/sql/meter/add_identifier_column.sql')); + await db.none(sqlFile('../migrations/0.5.0-0.6.0/sql/meter/add_meters_default_timezone.sql')); + await db.none(sqlFile('../migrations/0.5.0-0.6.0/sql/preferences/add_language_types_enum.sql')); + await db.none(sqlFile('../migrations/0.5.0-0.6.0/sql/preferences/add_preferences_default_timezone.sql')); + } +}; diff --git a/src/server/migrations/0.5.0-0.6.0/sql/map/create_maps_table.sql b/src/server/migrations/0.5.0-0.6.0/sql/map/create_maps_table.sql new file mode 100644 index 000000000..28a04e570 --- /dev/null +++ b/src/server/migrations/0.5.0-0.6.0/sql/map/create_maps_table.sql @@ -0,0 +1,15 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +CREATE TABLE IF NOT EXISTS maps ( + id SERIAL PRIMARY KEY, + name VARCHAR(50) UNIQUE NOT NULL, + displayable boolean NOT NULL, + note VARCHAR(500), + filename VARCHAR(200) NOT NULL, + modified_date TIMESTAMP NOT NULL, + origin POINT DEFAULT NULL, + opposite POINT DEFAULT NULL, + map_source TEXT NOT NULL +); diff --git a/src/server/migrations/0.5.0-0.6.0/sql/meter/add_gps_column.sql b/src/server/migrations/0.5.0-0.6.0/sql/meter/add_gps_column.sql new file mode 100644 index 000000000..9092a682e --- /dev/null +++ b/src/server/migrations/0.5.0-0.6.0/sql/meter/add_gps_column.sql @@ -0,0 +1,6 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +ALTER TABLE meters + ADD COLUMN IF NOT EXISTS gps POINT DEFAULT NULL; \ No newline at end of file diff --git a/src/server/migrations/0.5.0-0.6.0/sql/meter/add_identifier_column.sql b/src/server/migrations/0.5.0-0.6.0/sql/meter/add_identifier_column.sql new file mode 100644 index 000000000..1029b0d03 --- /dev/null +++ b/src/server/migrations/0.5.0-0.6.0/sql/meter/add_identifier_column.sql @@ -0,0 +1,8 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +ALTER TABLE meters + ADD COLUMN IF NOT EXISTS identifier TEXT; + +UPDATE meters SET identifier=name WHERE identifier IS NULL or identifier=''; \ No newline at end of file diff --git a/src/server/migrations/0.5.0-0.6.0/sql/meter/add_meters_default_timezone.sql b/src/server/migrations/0.5.0-0.6.0/sql/meter/add_meters_default_timezone.sql new file mode 100644 index 000000000..b65904b27 --- /dev/null +++ b/src/server/migrations/0.5.0-0.6.0/sql/meter/add_meters_default_timezone.sql @@ -0,0 +1,9 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +DO $$ BEGIN + ALTER TABLE meters ADD COLUMN default_timezone_meter TEXT DEFAULT NULL ; +EXCEPTION + WHEN duplicate_column THEN NULL; +END $$; \ No newline at end of file diff --git a/src/server/migrations/0.5.0-0.6.0/sql/preferences/add_language_types_enum.sql b/src/server/migrations/0.5.0-0.6.0/sql/preferences/add_language_types_enum.sql new file mode 100644 index 000000000..4b6c5f063 --- /dev/null +++ b/src/server/migrations/0.5.0-0.6.0/sql/preferences/add_language_types_enum.sql @@ -0,0 +1,9 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +DO $$ BEGIN + alter TYPE language_type ADD VALUE 'es' AFTER 'fr'; +EXCEPTION + WHEN duplicate_object THEN null; +END $$; \ No newline at end of file diff --git a/src/server/migrations/0.5.0-0.6.0/sql/preferences/add_preferences_default_timezone.sql b/src/server/migrations/0.5.0-0.6.0/sql/preferences/add_preferences_default_timezone.sql new file mode 100644 index 000000000..a782f929e --- /dev/null +++ b/src/server/migrations/0.5.0-0.6.0/sql/preferences/add_preferences_default_timezone.sql @@ -0,0 +1,9 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +DO $$ BEGIN + ALTER TABLE preferences ADD COLUMN default_timezone TEXT DEFAULT NULL ; +EXCEPTION + WHEN duplicate_column THEN NULL; +END $$; \ No newline at end of file diff --git a/src/server/migrations/0.7.0-0.7.1/sql/index.js b/src/server/migrations/0.7.0-0.7.1/sql/index.js new file mode 100644 index 000000000..fbc7be27d --- /dev/null +++ b/src/server/migrations/0.7.0-0.7.1/sql/index.js @@ -0,0 +1,14 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +const database = require('../../models/database'); +const sqlFile = database.sqlFile; + +module.exports = { + fromVersion: '0.7.0', + toVersion: '0.7.1', + up: async db => { + await db.none(sqlFile('../migrations/0.7.0-0.7.1/sql/preferences/alter_preferences_type.sql')); + } +}; \ No newline at end of file diff --git a/src/server/migrations/registerMigration.js b/src/server/migrations/registerMigration.js index 150867fa9..81fd45c56 100644 --- a/src/server/migrations/registerMigration.js +++ b/src/server/migrations/registerMigration.js @@ -9,7 +9,9 @@ const migrations = [ /* eslint-disable global-require */ //require('./0.2.0-0.3.0-Template/indexTemplate'), require('./0.3.0-0.5.0'), - require('./0.5.0-0.6.0') + require('./0.5.0-0.6.0'), + require('./0.6.0-0.7.0'), + require('./0.7.0-0.7.1') /* eslint-disable global-require */ ]; From 531930baec66e605fcf5c67b61badf8c38f06814 Mon Sep 17 00:00:00 2001 From: jina2k <jina26p@gmail.com> Date: Sat, 13 Nov 2021 18:41:33 -0500 Subject: [PATCH 4/5] preferences --- .../0.7.0-0.7.1/sql/preferences/alter_preferences_type.sql | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/server/migrations/0.7.0-0.7.1/sql/preferences/alter_preferences_type.sql b/src/server/migrations/0.7.0-0.7.1/sql/preferences/alter_preferences_type.sql index 61e50dac9..1448ee284 100644 --- a/src/server/migrations/0.7.0-0.7.1/sql/preferences/alter_preferences_type.sql +++ b/src/server/migrations/0.7.0-0.7.1/sql/preferences/alter_preferences_type.sql @@ -2,8 +2,4 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -DO $$ BEGIN - ALTER TYPE graph_type ADD VALUE 'map' AFTER 'compare'; -EXCEPTION - WHEN duplicate_object THEN null; -END $$; \ No newline at end of file +ALTER TYPE graph_type ADD VALUE 'map' AFTER 'compare'; \ No newline at end of file From 5fb59ea2857440e4e3eca4de36098146b54b4fb5 Mon Sep 17 00:00:00 2001 From: Steven Huss-Lederman <huss@beloit.edu> Date: Sun, 14 Nov 2021 20:19:24 -0600 Subject: [PATCH 5/5] fix up 0.7.1 migration - This makes the alter of graph_type work with migration transactions. - Moves index.js into proper directory. --- src/server/migrations/0.7.0-0.7.1/{sql => }/index.js | 0 .../sql/preferences/alter_preferences_type.sql | 11 ++++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) rename src/server/migrations/0.7.0-0.7.1/{sql => }/index.js (100%) diff --git a/src/server/migrations/0.7.0-0.7.1/sql/index.js b/src/server/migrations/0.7.0-0.7.1/index.js similarity index 100% rename from src/server/migrations/0.7.0-0.7.1/sql/index.js rename to src/server/migrations/0.7.0-0.7.1/index.js diff --git a/src/server/migrations/0.7.0-0.7.1/sql/preferences/alter_preferences_type.sql b/src/server/migrations/0.7.0-0.7.1/sql/preferences/alter_preferences_type.sql index 1448ee284..234c080f4 100644 --- a/src/server/migrations/0.7.0-0.7.1/sql/preferences/alter_preferences_type.sql +++ b/src/server/migrations/0.7.0-0.7.1/sql/preferences/alter_preferences_type.sql @@ -2,4 +2,13 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -ALTER TYPE graph_type ADD VALUE 'map' AFTER 'compare'; \ No newline at end of file +-- See 0.6.0-0.7.0/add_meter_type.sql for more information on this migration. + +-- Move the currently named type to a temporary name. +ALTER TYPE graph_type RENAME TO graph_type_temp; +-- Create the type desired with new value, 'other' in this case but need to include old ones. +CREATE TYPE graph_type as enum ('line', 'bar', 'compare', 'map'); +-- Change the column in meters to use the new type with the current rows. +ALTER TABLE preferences ALTER COLUMN default_chart_to_render TYPE graph_type USING default_chart_to_render::text::graph_type; +-- Get rid of the old, temporary type that no longer needed. +DROP TYPE graph_type_temp;