فهرست منبع

fix(postgres): fixes db migration issue with_credentials column for postgres, fixes #3505

Torkel Ödegaard 10 سال پیش
والد
کامیت
c7e3ed096f

+ 1 - 1
pkg/services/sqlstore/migrator/column.go

@@ -55,7 +55,7 @@ func (col *Column) StringNoPk(d Dialect) string {
 	}
 
 	if col.Default != "" {
-		sql += "DEFAULT " + col.Default + " "
+		sql += "DEFAULT " + d.Default(col) + " "
 	}
 
 	return sql

+ 6 - 1
pkg/services/sqlstore/migrator/dialect.go

@@ -17,10 +17,11 @@ type Dialect interface {
 	SqlType(col *Column) string
 	SupportEngine() bool
 	LikeStr() string
+	Default(col *Column) string
 
 	CreateIndexSql(tableName string, index *Index) string
 	CreateTableSql(table *Table) string
-	AddColumnSql(tableName string, Col *Column) string
+	AddColumnSql(tableName string, col *Column) string
 	CopyTableData(sourceTable string, targetTable string, sourceCols []string, targetCols []string) string
 	DropTable(tableName string) string
 	DropIndexSql(tableName string, index *Index) string
@@ -71,6 +72,10 @@ func (b *BaseDialect) EqStr() string {
 	return "="
 }
 
+func (b *BaseDialect) Default(col *Column) string {
+	return col.Default
+}
+
 func (b *BaseDialect) CreateTableSql(table *Table) string {
 	var sql string
 	sql = "CREATE TABLE IF NOT EXISTS "

+ 11 - 0
pkg/services/sqlstore/migrator/postgres_dialect.go

@@ -36,6 +36,17 @@ func (db *Postgres) AutoIncrStr() string {
 	return ""
 }
 
+func (b *Postgres) Default(col *Column) string {
+	if col.Type == DB_Bool {
+		if col.Default == "0" {
+			return "FALSE"
+		} else {
+			return "TRUE"
+		}
+	}
+	return col.Default
+}
+
 func (db *Postgres) SqlType(c *Column) string {
 	var res string
 	switch t := c.Type; t {