From 2924bacd3a59016c60469b8a01c7dbca80c8ccaf Mon Sep 17 00:00:00 2001 From: Kamil Samigullin Date: Fri, 28 Aug 2020 12:51:19 +0300 Subject: [PATCH] issue #32: add postgresql support --- internal/model/merge.go | 31 ++++++++++++++++++- internal/model/specification.go | 9 ++++++ internal/model/testdata/app.toml | 7 +++++ .../components/storages/postgresql.toml | 7 +++++ 4 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 internal/model/testdata/components/storages/postgresql.toml diff --git a/internal/model/merge.go b/internal/model/merge.go index 462fdea..85cb800 100644 --- a/internal/model/merge.go +++ b/internal/model/merge.go @@ -1,6 +1,8 @@ package model -import "sort" +import ( + "sort" +) func (app *Application) Merge(apps ...Application) { if app == nil { @@ -132,6 +134,28 @@ func (logger *Logger) Merge(src *Logger) { } } +func (postgres *PostgreSQL) Merge(src *PostgreSQL) { + if postgres == nil || src == nil { + return + } + + if src.Version != "" { + postgres.Version = src.Version + } + if src.Size != "" { + postgres.Size = src.Size + } + if src.Enabled != nil { + postgres.Enabled = src.Enabled + } + if src.OwnName != nil { + postgres.OwnName = src.OwnName + } + if src.Fixtures != nil { + postgres.Fixtures = src.Fixtures + } +} + func (proxies *Proxies) Merge(src Proxies) { if proxies == nil || len(src) == 0 { return @@ -248,6 +272,11 @@ func (spec *Specification) Merge(src *Specification) { } spec.Balancing.Merge(src.Balancing) + if src.PostgreSQL != nil && spec.PostgreSQL == nil { + spec.PostgreSQL = new(PostgreSQL) + } + spec.PostgreSQL.Merge(src.PostgreSQL) + if src.SFTP != nil && spec.SFTP == nil { spec.SFTP = new(SFTP) } diff --git a/internal/model/specification.go b/internal/model/specification.go index b04dd1c..ba1e301 100644 --- a/internal/model/specification.go +++ b/internal/model/specification.go @@ -78,6 +78,14 @@ type Logger struct { Level string `toml:"level,omitempty"` } +type PostgreSQL struct { + Version string `toml:"version,omitempty"` + Size string `toml:"size,omitempty"` + Enabled *bool `toml:"enabled,omitempty"` + OwnName *bool `toml:"use_own_maintenance_table_name,omitempty"` + Fixtures *bool `toml:"fixtures_enabled,omitempty"` +} + type Proxy struct { Name string `toml:"name,omitempty"` Enabled *bool `toml:"enabled,omitempty"` @@ -126,6 +134,7 @@ type Specification struct { Engine *Engine `toml:"engine,omitempty"` Logger *Logger `toml:"logger,omitempty"` Balancing *Balancing `toml:"balancing,omitempty"` + PostgreSQL *PostgreSQL `toml:"postgresql,omitempty"` SFTP *SFTP `toml:"sftp,omitempty"` Crons Crons `toml:"crons,omitepmty"` Dependencies Dependencies `toml:"dependencies,omitempty"` diff --git a/internal/model/testdata/app.toml b/internal/model/testdata/app.toml index 4dea494..c771246 100644 --- a/internal/model/testdata/app.toml +++ b/internal/model/testdata/app.toml @@ -138,6 +138,13 @@ replicas = 1 [logger] level = "info" +[postgresql] + enabled = true + fixtures_enabled = false + size = "medium" + use_own_maintenance_table_name = false + version = "9.6" + [[proxy]] enabled = true name = "s3" diff --git a/internal/model/testdata/components/storages/postgresql.toml b/internal/model/testdata/components/storages/postgresql.toml new file mode 100644 index 0000000..a05c7f2 --- /dev/null +++ b/internal/model/testdata/components/storages/postgresql.toml @@ -0,0 +1,7 @@ +[postgresql] +enabled = true +size = "medium" +version = "9.6" + +use_own_maintenance_table_name = false +fixtures_enabled = false