account -> org table migration is starting to work, need to test mysql and postgres

This commit is contained in:
Torkel Ödegaard
2015-02-24 18:32:29 +01:00
parent ed68a4bb9a
commit f3f79792ab
7 changed files with 40 additions and 90 deletions
+26 -17
View File
@@ -18,25 +18,34 @@ func AddMigrations(mg *Migrator) {
}
func addMigrationLogMigrations(mg *Migrator) {
mg.AddMigration("create migration_log table", new(AddTableMigration).
Name("migration_log").WithColumns(
&Column{Name: "id", Type: DB_BigInt, IsPrimaryKey: true, IsAutoIncrement: true},
&Column{Name: "migration_id", Type: DB_NVarchar, Length: 255},
&Column{Name: "sql", Type: DB_Text},
&Column{Name: "success", Type: DB_Bool},
&Column{Name: "error", Type: DB_Text},
&Column{Name: "timestamp", Type: DB_DateTime},
))
migrationLogV1 := Table{
Name: "migration_log",
Columns: []*Column{
&Column{Name: "id", Type: DB_BigInt, IsPrimaryKey: true, IsAutoIncrement: true},
&Column{Name: "migration_id", Type: DB_NVarchar, Length: 255},
&Column{Name: "sql", Type: DB_Text},
&Column{Name: "success", Type: DB_Bool},
&Column{Name: "error", Type: DB_Text},
&Column{Name: "timestamp", Type: DB_DateTime},
},
}
mg.AddMigration("create migration_log table", NewAddTableMigration(migrationLogV1))
}
func addStarMigrations(mg *Migrator) {
mg.AddMigration("create star table", new(AddTableMigration).
Name("star").WithColumns(
&Column{Name: "id", Type: DB_BigInt, IsPrimaryKey: true, IsAutoIncrement: true},
&Column{Name: "user_id", Type: DB_BigInt, Nullable: false},
&Column{Name: "dashboard_id", Type: DB_BigInt, Nullable: false},
))
starV1 := Table{
Name: "star",
Columns: []*Column{
&Column{Name: "id", Type: DB_BigInt, IsPrimaryKey: true, IsAutoIncrement: true},
&Column{Name: "user_id", Type: DB_BigInt, Nullable: false},
&Column{Name: "dashboard_id", Type: DB_BigInt, Nullable: false},
},
Indices: []*Index{
&Index{Cols: []string{"user_id", "dashboard_id"}, Type: UniqueIndex},
},
}
mg.AddMigration("add unique index star.user_id_dashboard_id", new(AddIndexMigration).
Table("star").Columns("user_id", "dashboard_id").Unique())
mg.AddMigration("create star table", NewAddTableMigration(starV1))
mg.AddMigration("add unique index star.user_id_dashboard_id", NewAddIndexMigration(starV1, starV1.Indices[0]))
}
@@ -32,7 +32,7 @@ func TestMigrations(t *testing.T) {
mg := NewMigrator(x)
mg.LogLevel = log.DEBUG
addMigrations(mg)
AddMigrations(mg)
err = mg.Start()
So(err, ShouldBeNil)
+2 -2
View File
@@ -55,7 +55,7 @@ func addOrgMigrations(mg *Migrator) {
"name": "name",
"created": "created",
"updated": "updated",
}))
}).IfTableExists("account"))
mg.AddMigration("copy data account_user to org_user", NewCopyTableDataMigration("org_user", "account_user", map[string]string{
"id": "id",
@@ -64,7 +64,7 @@ func addOrgMigrations(mg *Migrator) {
"role": "role",
"created": "created",
"updated": "updated",
}))
}).IfTableExists("account_user"))
mg.AddMigration("Drop old table account", NewDropTableMigration("account"))
mg.AddMigration("Drop old table account_user", NewDropTableMigration("account_user"))
+4 -13
View File
@@ -26,20 +26,11 @@ func addUserMigrations(mg *Migrator) {
},
}
// create table
mg.AddMigration("create user table", NewAddTableMigration(userV1))
mg.AddMigration("Add email_verified flag", new(AddColumnMigration).
Table("user").Column(&Column{Name: "email_verified", Type: DB_Bool, Nullable: true}))
mg.AddMigration("Add user.theme column", new(AddColumnMigration).
Table("user").Column(&Column{Name: "theme", Type: DB_Varchar, Nullable: true, Length: 20}))
//------- user table indexes ------------------
mg.AddMigration("add unique index user.login", new(AddIndexMigration).
Table("user").Columns("login").Unique())
mg.AddMigration("add unique index user.email", new(AddIndexMigration).
Table("user").Columns("email").Unique())
// add indices
mg.AddMigration("add unique index user.login", NewAddIndexMigration(userV1, userV1.Indices[0]))
mg.AddMigration("add unique index user.email", NewAddIndexMigration(userV1, userV1.Indices[1]))
// ---------------------
// account -> org changes