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) {
addAccountMigrations(mg)
addDashboardMigration(mg)
addDataSourceMigration(mg)
addTokenMigrations(mg)
}
func addMigrationLogMigrations(mg *Migrator) {
......@@ -129,3 +130,20 @@ func addDataSourceMigration(mg *Migrator) {
mg.AddMigration("add unique index data_source.account_id_name", new(AddIndexMigration).
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 (
var indexTypes = []string{"Unknown", "INDEX", "UNIQUE INDEX"}
func ATestMigrations(t *testing.T) {
func TestMigrations(t *testing.T) {
log.NewLogger(0, "console", `{"level": 0}`)
testDBs := []sqlutil.TestDB{
......
......@@ -15,6 +15,7 @@ type Dialect interface {
EqStr() string
ShowCreateNull() bool
SqlType(col *Column) string
SupportEngine() bool
CreateIndexSql(tableName string, index *Index) string
CreateTableSql(table *Table) string
......@@ -85,6 +86,10 @@ func (b *BaseDialect) CreateTableSql(table *Table) string {
}
sql = sql[:len(sql)-2] + ")"
if b.dialect.SupportEngine() {
sql += " ENGINE=InnoDB DEFAULT CHARSET UTF8 "
}
sql += ";"
return sql
}
......
......@@ -13,6 +13,10 @@ func NewMysqlDialect() *Mysql {
return &d
}
func (db *Mysql) SupportEngine() bool {
return true
}
func (db *Mysql) Quote(name string) string {
return "`" + name + "`"
}
......
......@@ -13,6 +13,10 @@ func NewPostgresDialect() *Postgres {
return &d
}
func (db *Postgres) SupportEngine() bool {
return false
}
func (db *Postgres) Quote(name string) string {
return "\"" + name + "\""
}
......
......@@ -11,6 +11,10 @@ func NewSqlite3Dialect() *Sqlite3 {
return &d
}
func (db *Sqlite3) SupportEngine() bool {
return false
}
func (db *Sqlite3) Quote(name string) string {
return "`" + name + "`"
}
......
......@@ -33,11 +33,6 @@ var (
UseSQLite3 bool
)
func init() {
tables = make([]interface{}, 0)
tables = append(tables, new(m.Token))
}
func EnsureAdminUser() {
adminQuery := m.GetUserByLoginQuery{LoginOrEmail: setting.AdminUser}
......@@ -78,6 +73,7 @@ func SetEngine(engine *xorm.Engine, enableLog bool) (err error) {
dialect = migrator.NewDialect(x.DriverName())
migrator := migrator.NewMigrator(x)
migrator.LogLevel = log.INFO
addMigrations(migrator)
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