mirror of https://github.com/go-gorm/gorm.git
Fix check has column, index for sqlite
This commit is contained in:
parent
e1bcca6b33
commit
a992c1ea38
|
@ -30,8 +30,8 @@ func (m Migrator) HasColumn(value interface{}, field string) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
return m.DB.Raw(
|
return m.DB.Raw(
|
||||||
"SELECT count(*) FROM sqlite_master WHERE tbl_name = ? AND (sql LIKE ? OR sql LIKE ? OR sql LIKE ?)",
|
"SELECT count(*) FROM sqlite_master WHERE type = ? AND tbl_name = ? AND (sql LIKE ? OR sql LIKE ? OR sql LIKE ?)",
|
||||||
stmt.Table, `%"`+name+`" %`, `%`+name+` %`, "%`"+name+"`%",
|
"table", stmt.Table, `%"`+name+`" %`, `%`+name+` %`, "%`"+name+"`%",
|
||||||
).Row().Scan(&count)
|
).Row().Scan(&count)
|
||||||
})
|
})
|
||||||
return count > 0
|
return count > 0
|
||||||
|
@ -41,8 +41,8 @@ func (m Migrator) HasIndex(value interface{}, name string) bool {
|
||||||
var count int
|
var count int
|
||||||
m.RunWithValue(value, func(stmt *gorm.Statement) error {
|
m.RunWithValue(value, func(stmt *gorm.Statement) error {
|
||||||
return m.DB.Raw(
|
return m.DB.Raw(
|
||||||
"SELECT count(*) FROM sqlite_master WHERE tbl_name = ? AND sql LIKE ?",
|
"SELECT count(*) FROM sqlite_master WHERE type = ? AND tbl_name = ? AND sql LIKE ?",
|
||||||
stmt.Table, "%INDEX "+name+" ON%",
|
"index", stmt.Table, "%INDEX "+name+" ON%",
|
||||||
).Row().Scan(&count)
|
).Row().Scan(&count)
|
||||||
})
|
})
|
||||||
return count > 0
|
return count > 0
|
||||||
|
|
Loading…
Reference in New Issue