Skip to content

Commit

Permalink
add migration
Browse files Browse the repository at this point in the history
  • Loading branch information
huss committed Aug 20, 2023
1 parent 33230ee commit df9cfc8
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/server/migrations/1.0.0-1.1.0/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,7 @@ module.exports = {
toVersion: '1.1.0',
up: async db => {
await db.none(sqlFile('../migrations/1.0.0-1.1.0/sql/readings/create_reading_views.sql'));
await db.none(sqlFile('../migrations/1.0.0-1.1.0/sql/meter/add_meter_pipeline_checks.sql'));
await db.none(sqlFile('../migrations/1.0.0-1.1.0/sql/preferences/add_preferences_pipeline_checks.sql'));
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
* 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/. */

-- Add meter pipeline check columns to the meters table.
ALTER TABLE meters
ADD COLUMN IF NOT EXISTS min_val DOUBLE PRECISION NOT NULL DEFAULT -9007199254740991 CHECK (min_val::DOUBLE PRECISION >= -9007199254740991),
ADD COLUMN IF NOT EXISTS max_val DOUBLE PRECISION NOT NULL DEFAULT 9007199254740991 CHECK (max_val::DOUBLE PRECISION <= 9007199254740991),
ADD COLUMN IF NOT EXISTS min_date TIMESTAMP NOT NULL DEFAULT '1970-01-01 00:00:00+00:00',
ADD COLUMN IF NOT EXISTS max_date TIMESTAMP NOT NULL DEFAULT '6970-01-01 00:00:00+00:00',
ADD COLUMN IF NOT EXISTS max_error INTEGER NOT NULL DEFAULT 75,
ADD COLUMN IF NOT EXISTS disable_checks BOOLEAN DEFAULT false
;
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
* 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/. */

-- Add PREFERENCES pipeline check columns to the meters table.

-- You need to set default so any existing rows get that value since NOT NULL.
ALTER TABLE preferences
ADD COLUMN IF NOT EXISTS default_meter_minimum_value DOUBLE PRECISION NOT NULL DEFAULT -9007199254740991,
ADD COLUMN IF NOT EXISTS default_meter_maximum_value DOUBLE PRECISION NOT NULL DEFAULT 9007199254740991,
ADD COLUMN IF NOT EXISTS default_meter_minimum_date TIMESTAMP NOT NULL DEFAULT '1970-01-01 00:00:00+00:00',
ADD COLUMN IF NOT EXISTS default_meter_maximum_date TIMESTAMP NOT NULL DEFAULT '6970-01-01 00:00:00+00:00',
ADD COLUMN IF NOT EXISTS default_meter_reading_gap REAL NOT NULL DEFAULT 0,
ADD COLUMN IF NOT EXISTS default_meter_maximum_errors INTEGER NOT NULL DEFAULT 75
;
-- Now remove default since not desired.
ALTER TABLE preferences
ALTER COLUMN default_meter_minimum_value DROP DEFAULT,
ALTER COLUMN default_meter_maximum_value DROP DEFAULT,
ALTER COLUMN default_meter_minimum_date DROP DEFAULT,
ALTER COLUMN default_meter_maximum_date DROP DEFAULT,
ALTER COLUMN default_meter_reading_gap DROP DEFAULT,
ALTER COLUMN default_meter_maximum_errors DROP DEFAULT
;

0 comments on commit df9cfc8

Please sign in to comment.