2019-02-14 17:15:34 +00:00
|
|
|
/// These are straightforward migrations.
|
|
|
|
///
|
|
|
|
/// You will likely never have to actually write these yourself.
|
2021-05-17 15:34:19 +00:00
|
|
|
library angel3_migration.example.todo;
|
2019-02-14 17:15:34 +00:00
|
|
|
|
2021-05-17 15:34:19 +00:00
|
|
|
import 'package:angel3_migration/angel3_migration.dart';
|
2019-02-14 17:15:34 +00:00
|
|
|
|
|
|
|
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');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class TodoMigration implements Migration {
|
|
|
|
@override
|
|
|
|
void up(Schema schema) {
|
|
|
|
schema.create('todos', (table) {
|
|
|
|
table
|
|
|
|
..serial('id').primaryKey()
|
|
|
|
..integer('user_id').references('users', 'id').onDeleteCascade()
|
|
|
|
..varChar('text')
|
|
|
|
..boolean('completed').defaultsTo(false);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void down(Schema schema) {
|
|
|
|
schema.drop('todos');
|
|
|
|
}
|
|
|
|
}
|