Commit 0a695ba1 by Torkel Ödegaard

Final work on migration, now there is no usage of xorm table sync

parent afb847ac
...@@ -8,6 +8,7 @@ func addMigrations(mg *Migrator) { ...@@ -8,6 +8,7 @@ func addMigrations(mg *Migrator) {
addAccountMigrations(mg) addAccountMigrations(mg)
addDashboardMigration(mg) addDashboardMigration(mg)
addDataSourceMigration(mg) addDataSourceMigration(mg)
addTokenMigrations(mg)
} }
func addMigrationLogMigrations(mg *Migrator) { func addMigrationLogMigrations(mg *Migrator) {
...@@ -129,3 +130,20 @@ func addDataSourceMigration(mg *Migrator) { ...@@ -129,3 +130,20 @@ func addDataSourceMigration(mg *Migrator) {
mg.AddMigration("add unique index data_source.account_id_name", new(AddIndexMigration). mg.AddMigration("add unique index data_source.account_id_name", new(AddIndexMigration).
Table("data_source").Columns("account_id", "name").Unique()) Table("data_source").Columns("account_id", "name").Unique())
} }
func addTokenMigrations(mg *Migrator) {
mg.AddMigration("create token table", new(AddTableMigration).
Name("token").WithColumns(
&Column{Name: "id", Type: DB_BigInt, IsPrimaryKey: true, IsAutoIncrement: true},
&Column{Name: "account_id", Type: DB_BigInt, Nullable: false},
&Column{Name: "name", Type: DB_NVarchar, Length: 255, Nullable: false},
&Column{Name: "token", Type: DB_NVarchar, Length: 255, Nullable: false},
&Column{Name: "role", Type: DB_NVarchar, Length: 255, Nullable: false},
&Column{Name: "created", Type: DB_DateTime, Nullable: false},
&Column{Name: "updated", Type: DB_DateTime, Nullable: false},
))
//------- indexes ------------------
mg.AddMigration("add index token.account_id", new(AddIndexMigration).
Table("token").Columns("account_id"))
}
...@@ -15,7 +15,7 @@ import ( ...@@ -15,7 +15,7 @@ import (
var indexTypes = []string{"Unknown", "INDEX", "UNIQUE INDEX"} var indexTypes = []string{"Unknown", "INDEX", "UNIQUE INDEX"}
func ATestMigrations(t *testing.T) { func TestMigrations(t *testing.T) {
log.NewLogger(0, "console", `{"level": 0}`) log.NewLogger(0, "console", `{"level": 0}`)
testDBs := []sqlutil.TestDB{ testDBs := []sqlutil.TestDB{
......
...@@ -15,6 +15,7 @@ type Dialect interface { ...@@ -15,6 +15,7 @@ type Dialect interface {
EqStr() string EqStr() string
ShowCreateNull() bool ShowCreateNull() bool
SqlType(col *Column) string SqlType(col *Column) string
SupportEngine() bool
CreateIndexSql(tableName string, index *Index) string CreateIndexSql(tableName string, index *Index) string
CreateTableSql(table *Table) string CreateTableSql(table *Table) string
...@@ -85,6 +86,10 @@ func (b *BaseDialect) CreateTableSql(table *Table) string { ...@@ -85,6 +86,10 @@ func (b *BaseDialect) CreateTableSql(table *Table) string {
} }
sql = sql[:len(sql)-2] + ")" sql = sql[:len(sql)-2] + ")"
if b.dialect.SupportEngine() {
sql += " ENGINE=InnoDB DEFAULT CHARSET UTF8 "
}
sql += ";" sql += ";"
return sql return sql
} }
......
...@@ -13,6 +13,10 @@ func NewMysqlDialect() *Mysql { ...@@ -13,6 +13,10 @@ func NewMysqlDialect() *Mysql {
return &d return &d
} }
func (db *Mysql) SupportEngine() bool {
return true
}
func (db *Mysql) Quote(name string) string { func (db *Mysql) Quote(name string) string {
return "`" + name + "`" return "`" + name + "`"
} }
......
...@@ -13,6 +13,10 @@ func NewPostgresDialect() *Postgres { ...@@ -13,6 +13,10 @@ func NewPostgresDialect() *Postgres {
return &d return &d
} }
func (db *Postgres) SupportEngine() bool {
return false
}
func (db *Postgres) Quote(name string) string { func (db *Postgres) Quote(name string) string {
return "\"" + name + "\"" return "\"" + name + "\""
} }
......
...@@ -11,6 +11,10 @@ func NewSqlite3Dialect() *Sqlite3 { ...@@ -11,6 +11,10 @@ func NewSqlite3Dialect() *Sqlite3 {
return &d return &d
} }
func (db *Sqlite3) SupportEngine() bool {
return false
}
func (db *Sqlite3) Quote(name string) string { func (db *Sqlite3) Quote(name string) string {
return "`" + name + "`" return "`" + name + "`"
} }
......
...@@ -33,11 +33,6 @@ var ( ...@@ -33,11 +33,6 @@ var (
UseSQLite3 bool UseSQLite3 bool
) )
func init() {
tables = make([]interface{}, 0)
tables = append(tables, new(m.Token))
}
func EnsureAdminUser() { func EnsureAdminUser() {
adminQuery := m.GetUserByLoginQuery{LoginOrEmail: setting.AdminUser} adminQuery := m.GetUserByLoginQuery{LoginOrEmail: setting.AdminUser}
...@@ -78,6 +73,7 @@ func SetEngine(engine *xorm.Engine, enableLog bool) (err error) { ...@@ -78,6 +73,7 @@ func SetEngine(engine *xorm.Engine, enableLog bool) (err error) {
dialect = migrator.NewDialect(x.DriverName()) dialect = migrator.NewDialect(x.DriverName())
migrator := migrator.NewMigrator(x) migrator := migrator.NewMigrator(x)
migrator.LogLevel = log.INFO
addMigrations(migrator) addMigrations(migrator)
if err := migrator.Start(); err != nil { if err := migrator.Start(); err != nil {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment