Migrations

Angel's ORM ships with support for running database migrations, using a system modeled over that of Laravel.

An example is shown below:

class UserMigration implements Migration {
  @override
  void up(Schema schema) {
    schema.create('users', (table) {
      table
        ..serial('id').primaryKey()
        ..varChar('username', length: 32).unique()
        ..varChar('password')
        ..boolean('account_confirmed').defaultsTo(false);
    });
  }

  @override
  void down(Schema schema) {
    schema.drop('users');
  }
}

Migrations can be used to either create, alter, or drop database tables.

For more in-depth documentation, consult the angel_migration documentation:

https://github.com/angel-dart/migration

If you use angel_orm_generator, then a migration will be generated by default for each class annotated with @orm.

To disable this:

Running Migrations

Using package:angel_migration_runner, we can create executables that run our database migrations:

Running this file will produce output like the following:

The migration runner keeps track of a migrations table, in order to be able to keep track of which migrations it has run.

Last updated