summaryrefslogtreecommitdiffstats
path: root/store/sqlstore/supplier.go
diff options
context:
space:
mode:
Diffstat (limited to 'store/sqlstore/supplier.go')
-rw-r--r--store/sqlstore/supplier.go40
1 files changed, 40 insertions, 0 deletions
diff --git a/store/sqlstore/supplier.go b/store/sqlstore/supplier.go
index 0b02d9d47..02a3cef7f 100644
--- a/store/sqlstore/supplier.go
+++ b/store/sqlstore/supplier.go
@@ -91,6 +91,7 @@ type SqlSupplierOldStores struct {
plugin store.PluginStore
channelMemberHistory store.ChannelMemberHistoryStore
role store.RoleStore
+ scheme store.SchemeStore
}
type SqlSupplier struct {
@@ -141,6 +142,7 @@ func NewSqlSupplier(settings model.SqlSettings, metrics einterfaces.MetricsInter
initSqlSupplierReactions(supplier)
initSqlSupplierRoles(supplier)
+ initSqlSupplierSchemes(supplier)
err := supplier.GetMaster().CreateTablesIfNotExists()
if err != nil {
@@ -493,6 +495,40 @@ func (ss *SqlSupplier) CreateColumnIfNotExists(tableName string, columnName stri
}
}
+func (ss *SqlSupplier) CreateColumnIfNotExistsNoDefault(tableName string, columnName string, mySqlColType string, postgresColType string) bool {
+
+ if ss.DoesColumnExist(tableName, columnName) {
+ return false
+ }
+
+ if ss.DriverName() == model.DATABASE_DRIVER_POSTGRES {
+ _, err := ss.GetMaster().ExecNoTimeout("ALTER TABLE " + tableName + " ADD " + columnName + " " + postgresColType)
+ if err != nil {
+ mlog.Critical(fmt.Sprintf("Failed to create column %v", err))
+ time.Sleep(time.Second)
+ os.Exit(EXIT_CREATE_COLUMN_POSTGRES)
+ }
+
+ return true
+
+ } else if ss.DriverName() == model.DATABASE_DRIVER_MYSQL {
+ _, err := ss.GetMaster().ExecNoTimeout("ALTER TABLE " + tableName + " ADD " + columnName + " " + mySqlColType)
+ if err != nil {
+ mlog.Critical(fmt.Sprintf("Failed to create column %v", err))
+ time.Sleep(time.Second)
+ os.Exit(EXIT_CREATE_COLUMN_MYSQL)
+ }
+
+ return true
+
+ } else {
+ mlog.Critical("Failed to create column because of missing driver")
+ time.Sleep(time.Second)
+ os.Exit(EXIT_CREATE_COLUMN_MISSING)
+ return false
+ }
+}
+
func (ss *SqlSupplier) RemoveColumnIfExists(tableName string, columnName string) bool {
if !ss.DoesColumnExist(tableName, columnName) {
@@ -865,6 +901,10 @@ func (ss *SqlSupplier) Role() store.RoleStore {
return ss.oldStores.role
}
+func (ss *SqlSupplier) Scheme() store.SchemeStore {
+ return ss.oldStores.scheme
+}
+
func (ss *SqlSupplier) DropAllTables() {
ss.master.TruncateTables()
}