3

I haven't found in documentation anything except "syncdb" command which create database tables from scratch. Is there any command to create and run migrations based on ORM model? Like in django? Add field, change type, etc.

Hepri
  • 217
  • 5
  • 15

3 Answers3

1

No, orm.RunSyncdb(name, force, verbose) and it's command line equivalent only do a small subset of what tools like django's south can do.

Beego's orm can:

  • Create new tables from scratch
  • Drop all tables (force = true)
  • Add new columns as you extend your model

You need to handle dropping columns and any changes to the column parameters used to initially create the table.

Will Krause
  • 626
  • 6
  • 12
  • So, how do you handle db migrations with beego? – Hepri Feb 05 '15 at 14:13
  • The old fashioned way, by backing up the [sql schema](http://www.electrictoolbox.com/mysqldump-schema-only/), and using sql statements to drop or change columns. If you're using git, just keep the schema backup in the repo along with an .sql file containing any schema changing statements you made. Between those two, you should be able to figure out a way back to a previous state. – Will Krause Feb 05 '15 at 14:53
1

Sadly beego doesn't include this feature, but no framework in go (as of today) does. Instead they all relay that to other libraries to handle.

What you can do however is use goose for migrations:

or any other migration library as discussed in the following thread:

Remember that due to the modularity of beego you can also use any another orm (like gorm).

Feel free to look for : avelino/awesome-go in google if you want a list of tools/libs around the go ecosystem.

Yvan
  • 11
  • 1
0

Yes, you can create migrations in beego now. Example, If you need to create a new table, you can start by creating a new migration file using the bee tool:

bee generate migration create_user_table

This command will create a file inside database/migrations folder. The file name contains the date, time and name of the migration.

For further details you can check this article https://ncona.com/2017/10/database-migrations-in-beego