From 142fe06df16f5fd138ea3ef012cb9098bdb1cb64 Mon Sep 17 00:00:00 2001 From: Brice Bauer Date: Mon, 22 Jul 2024 08:37:35 -0400 Subject: [PATCH] Move powered_on_hours_unit to a new migration id --- .../scrutiny_repository_migrations.go | 26 ++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/webapp/backend/pkg/database/scrutiny_repository_migrations.go b/webapp/backend/pkg/database/scrutiny_repository_migrations.go index e083712..9a02574 100644 --- a/webapp/backend/pkg/database/scrutiny_repository_migrations.go +++ b/webapp/backend/pkg/database/scrutiny_repository_migrations.go @@ -332,13 +332,6 @@ func (sr *scrutinyRepository) Migrate(ctx context.Context) error { SettingDataType: "string", SettingValueString: "smooth", }, - { - SettingKeyName: "powered_on_hours_unit", - SettingKeyDescription: "Presentation format for device powered on time ('humanize' | 'device_hours')", - SettingDataType: "string", - SettingValueString: "humanize", - }, - { SettingKeyName: "metrics.notify_level", SettingKeyDescription: "Determines which device status will cause a notification (fail or warn)", @@ -391,6 +384,21 @@ func (sr *scrutinyRepository) Migrate(ctx context.Context) error { return tx.Create(&defaultSettings).Error }, }, + { + ID: "m20240722082740", // add powered_on_hours_unit setting. + Migrate: func(tx *gorm.DB) error { + //add powered_on_hours_unit setting default. + var defaultSettings = []m20220716214900.Setting{ + { + SettingKeyName: "powered_on_hours_unit", + SettingKeyDescription: "Presentation format for device powered on time ('humanize' | 'device_hours')", + SettingDataType: "string", + SettingValueString: "humanize", + }, + } + return tx.Create(&defaultSettings).Error + }, + }, }) if err := m.Migrate(); err != nil { @@ -427,8 +435,8 @@ func (sr *scrutinyRepository) Migrate(ctx context.Context) error { // helpers -//When adding data to influxdb, an error may be returned if the data point is outside the range of the retention policy. -//This function will ignore retention policy errors, and allow the migration to continue. +// When adding data to influxdb, an error may be returned if the data point is outside the range of the retention policy. +// This function will ignore retention policy errors, and allow the migration to continue. func ignorePastRetentionPolicyError(err error) error { var influxDbWriteError *http.Error if errors.As(err, &influxDbWriteError) {