postgres needs another query to get table information...

Этот коммит содержится в:
Florian Orben
2015-11-05 23:55:31 +01:00
родитель b085bc2d56
Коммит e00836f8df
2 изменённых файлов: 8 добавлений и 17 удалений

Просмотреть файл

@@ -40,8 +40,8 @@ func NewSqlPostStore(sqlStore *SqlStore) PostStore {
} }
func (s SqlPostStore) UpgradeSchemaIfNeeded() { func (s SqlPostStore) UpgradeSchemaIfNeeded() {
col := s.GetColumnInformation("Posts", "Props") colType := s.GetColumnDataType("Posts", "Props")
if col.Type != "text" { if colType != "text" {
_, err := s.GetMaster().Exec("ALTER TABLE Posts MODIFY COLUMN Props TEXT") _, err := s.GetMaster().Exec("ALTER TABLE Posts MODIFY COLUMN Props TEXT")
if err != nil { if err != nil {
l4g.Critical("Failed to alter column Posts.Props to TEXT: " + err.Error()) l4g.Critical("Failed to alter column Posts.Props to TEXT: " + err.Error())

Просмотреть файл

@@ -50,15 +50,6 @@ type SqlStore struct {
preference PreferenceStore preference PreferenceStore
} }
type Column struct {
Field string
Type string
Null string
Key interface{}
Default interface{}
Extra interface{}
}
func NewSqlStore() Store { func NewSqlStore() Store {
sqlStore := &SqlStore{} sqlStore := &SqlStore{}
@@ -464,18 +455,18 @@ func IsUniqueConstraintError(err string, mysql string, postgres string) bool {
return unique && field return unique && field
} }
func (ss SqlStore) GetColumnInformation(tableName, columnName string) Column { func (ss SqlStore) GetColumnDataType(tableName, columnName string) string {
var col Column dataType, err := ss.GetMaster().SelectStr("SELECT data_type FROM INFORMATION_SCHEMA.COLUMNS where table_name = :Tablename AND column_name = :Columnname", map[string]interface{}{
err := ss.GetMaster().SelectOne(&col, "SHOW COLUMNS FROM "+tableName+" WHERE Field = :Columnname", map[string]interface{}{ "Tablename": tableName,
"Columnname": columnName, "Columnname": columnName,
}) })
if err != nil { if err != nil {
l4g.Critical("Failed to get information for column %s from table %s: %v", tableName, columnName, err.Error()) l4g.Critical("Failed to get data type for column %s from table %s: %v", tableName, columnName, err.Error())
time.Sleep(time.Second) time.Sleep(time.Second)
panic("Failed to get information for column " + tableName + " from table " + columnName + ": " + err.Error()) panic("Failed to get get data type for column " + tableName + " from table " + columnName + ": " + err.Error())
} }
return col return dataType
} }
func (ss SqlStore) GetMaster() *gorp.DbMap { func (ss SqlStore) GetMaster() *gorp.DbMap {