go - How to do database migration with Beego framework? -


i need add new field existing table, correct process beego?

i familiar django's south: first generate migration script manage.py schema_migration, execute migration script manage.py migrate.

beego has command bee generate migration generate migration script in database/migrations/xxx.go. don't understand how use generated script, doesn't seem connected anything.

and don't see documentation mentioning migration.

came across same issue, i'm using mysql. here how i've done it-

created migration file using bee generate:

$ bee generate migration user 2016/06/26 13:36:31 [info] using 'user' migration name 2016/06/26 13:36:32 [info] migration file generated: /path/to/project/database/migrations/20160626_140247_user.go 2016/06/26 13:36:32 [succ] generate created! 

now file generated , below content of file:

package main  import (     "github.com/astaxie/beego/migration" )  // not modify type user_20160626_140247 struct {     migration.migration }  // not modify func init() {     m := &user_20160626_140247{}     m.created = "20160626_140247"     migration.register("user_20160626_140247", m) }  // run migrations func (m *user_20160626_140247) up() {     // use m.sql("create table ...") make schema update  }  // reverse migrations func (m *user_20160626_140247) down() {     // use m.sql("drop table ...") reverse schema update  } 

updated up , down methods. in comment of these methods can see m.sql can invoked run raw sql queries. here can use alter commands update structure.

once done changes, can run bee migrate apply these migration. below example-

$bee migrate -conn="username:password@tcp(127.0.0.1:3306)/mydb" 

hope helps.


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -