summaryrefslogtreecommitdiffstats
path: root/store/sql_system_store.go
diff options
context:
space:
mode:
author=Corey Hulen <corey@hulen.com>2015-09-16 19:59:57 -0700
committer=Corey Hulen <corey@hulen.com>2015-09-16 19:59:57 -0700
commitabda39b6523f2563d4663036f13ad1c24dac161e (patch)
tree3573d568f220c8e778f872c0fb501a280bb87468 /store/sql_system_store.go
parent1e7f7852ad09d97c8d33012192bd1ff418881b8f (diff)
downloadchat-abda39b6523f2563d4663036f13ad1c24dac161e.tar.gz
chat-abda39b6523f2563d4663036f13ad1c24dac161e.tar.bz2
chat-abda39b6523f2563d4663036f13ad1c24dac161e.zip
Adding database schema version
Diffstat (limited to 'store/sql_system_store.go')
-rw-r--r--store/sql_system_store.go92
1 files changed, 92 insertions, 0 deletions
diff --git a/store/sql_system_store.go b/store/sql_system_store.go
new file mode 100644
index 000000000..ca22de2a6
--- /dev/null
+++ b/store/sql_system_store.go
@@ -0,0 +1,92 @@
+// Copyright (c) 2015 Spinpunch, Inc. All Rights Reserved.
+// See License.txt for license information.
+
+package store
+
+import (
+ "github.com/mattermost/platform/model"
+)
+
+type SqlSystemStore struct {
+ *SqlStore
+}
+
+func NewSqlSystemStore(sqlStore *SqlStore) SystemStore {
+ s := &SqlSystemStore{sqlStore}
+
+ for _, db := range sqlStore.GetAllConns() {
+ table := db.AddTableWithName(model.System{}, "Systems").SetKeys(false, "Name")
+ table.ColMap("Name").SetMaxSize(64)
+ table.ColMap("Value").SetMaxSize(1024)
+ }
+
+ return s
+}
+
+func (s SqlSystemStore) UpgradeSchemaIfNeeded() {
+}
+
+func (s SqlSystemStore) CreateIndexesIfNotExists() {
+}
+
+func (s SqlSystemStore) Save(system *model.System) StoreChannel {
+
+ storeChannel := make(StoreChannel)
+
+ go func() {
+ result := StoreResult{}
+
+ if err := s.GetMaster().Insert(system); err != nil {
+ result.Err = model.NewAppError("SqlSystemStore.Save", "We encounted an error saving the system property", "")
+ }
+
+ storeChannel <- result
+ close(storeChannel)
+ }()
+
+ return storeChannel
+}
+
+func (s SqlSystemStore) Update(system *model.System) StoreChannel {
+
+ storeChannel := make(StoreChannel)
+
+ go func() {
+ result := StoreResult{}
+
+ if _, err := s.GetMaster().Update(system); err != nil {
+ result.Err = model.NewAppError("SqlSystemStore.Save", "We encounted an error updating the system property", "")
+ }
+
+ storeChannel <- result
+ close(storeChannel)
+ }()
+
+ return storeChannel
+}
+
+func (s SqlSystemStore) Get() StoreChannel {
+
+ storeChannel := make(StoreChannel)
+
+ go func() {
+ result := StoreResult{}
+
+ var systems []model.System
+ props := make(model.StringMap)
+ if _, err := s.GetReplica().Select(&systems, "SELECT * FROM Systems"); err != nil {
+ result.Err = model.NewAppError("SqlSystemStore.Get", "We encounted an error finding the system properties", "")
+ } else {
+ for _, prop := range systems {
+ props[prop.Name] = prop.Value
+ }
+
+ result.Data = props
+ }
+
+ storeChannel <- result
+ close(storeChannel)
+ }()
+
+ return storeChannel
+}