From 5b2746f389ed2bc5edd626baa439099256e5f1bb Mon Sep 17 00:00:00 2001 From: Jason Kulatunga Date: Sun, 26 Jun 2022 15:30:52 -0700 Subject: [PATCH] initial settings table. --- .../migrations/m20220625184300/setting.go | 16 ++++++++++++++++ .../database/scrutiny_repository_migrations.go | 9 +++++++++ webapp/backend/pkg/models/setting.go | 17 ++++++++++++++--- 3 files changed, 39 insertions(+), 3 deletions(-) create mode 100644 webapp/backend/pkg/database/migrations/m20220625184300/setting.go diff --git a/webapp/backend/pkg/database/migrations/m20220625184300/setting.go b/webapp/backend/pkg/database/migrations/m20220625184300/setting.go new file mode 100644 index 0000000..443c56b --- /dev/null +++ b/webapp/backend/pkg/database/migrations/m20220625184300/setting.go @@ -0,0 +1,16 @@ +package m20220625184300 + +import ( + "gorm.io/gorm" +) + +type Setting struct { + //GORM attributes, see: http://gorm.io/docs/conventions.html + gorm.Model + + SettingKeyName string `json:"setting_key_name"` + SettingDataType string `json:"setting_data_type"` + + SettingValueNumeric int64 `json:"setting_value_numeric"` + SettingValueString string `json:"setting_value_string"` +} diff --git a/webapp/backend/pkg/database/scrutiny_repository_migrations.go b/webapp/backend/pkg/database/scrutiny_repository_migrations.go index bb40add..33fd835 100644 --- a/webapp/backend/pkg/database/scrutiny_repository_migrations.go +++ b/webapp/backend/pkg/database/scrutiny_repository_migrations.go @@ -7,6 +7,7 @@ import ( "github.com/analogj/scrutiny/webapp/backend/pkg/database/migrations/m20201107210306" "github.com/analogj/scrutiny/webapp/backend/pkg/database/migrations/m20220503120000" "github.com/analogj/scrutiny/webapp/backend/pkg/database/migrations/m20220509170100" + "github.com/analogj/scrutiny/webapp/backend/pkg/database/migrations/m20220625184300" "github.com/analogj/scrutiny/webapp/backend/pkg/models" "github.com/analogj/scrutiny/webapp/backend/pkg/models/collector" "github.com/analogj/scrutiny/webapp/backend/pkg/models/measurements" @@ -275,6 +276,14 @@ func (sr *scrutinyRepository) Migrate(ctx context.Context) error { return tx.Where("wwn = ?", "").Delete(&models.Device{}).Error }, }, + { + ID: "m20220716214900", // settings table. + Migrate: func(tx *gorm.DB) error { + + // adding the settings table. + return tx.AutoMigrate(m20220625184300.Setting{}) + }, + }, }) if err := m.Migrate(); err != nil { diff --git a/webapp/backend/pkg/models/setting.go b/webapp/backend/pkg/models/setting.go index d9a1d6b..15238f6 100644 --- a/webapp/backend/pkg/models/setting.go +++ b/webapp/backend/pkg/models/setting.go @@ -1,5 +1,16 @@ package models -// Temperature Format -// Date Format -// Device History window +import ( + "gorm.io/gorm" +) + +type Setting struct { + //GORM attributes, see: http://gorm.io/docs/conventions.html + gorm.Model + + SettingKeyName string `json:"setting_key_name"` + SettingDataType string `json:"setting_data_type"` + + SettingValueNumeric int64 `json:"setting_value_numeric"` + SettingValueString string `json:"setting_value_string"` +}