Test transactions in migrations (#430)

This commit is contained in:
Simon Binder 2020-03-15 15:16:22 +01:00
parent 97127782b2
commit bc1f347498
No known key found for this signature in database
GPG Key ID: 7891917E4147B8C0
2 changed files with 6 additions and 3 deletions

View File

@ -89,7 +89,7 @@ class Database extends _$Database {
/// It will be set in the onUpgrade callback. Null if no migration ocurred
int schemaVersionChangedFrom;
/// It will be set in the onUpgrade callback. Null if no migration ocurred
int schemaVersionChangedTo;
@ -99,7 +99,10 @@ class Database extends _$Database {
onCreate: (m) async {
await m.createTable(users);
if (schemaVersion >= 2) {
await m.createTable(friendships);
// ensure that transactions can be used in a migration callback.
await transaction(() async {
await m.createTable(friendships);
});
}
},
onUpgrade: (m, from, to) async {

View File

@ -100,7 +100,7 @@ abstract class GeneratedDatabase extends DatabaseConnectionUser
///
/// This api is mainly used internally in moor, especially to implement the
/// [beforeOpen] callback from the database site.
/// However, it can also be used if yuo need to create tables manually and
/// However, it can also be used if you need to create tables manually and
/// outside of a [MigrationStrategy]. For almost all use cases, overriding
/// [migration] should suffice.
@protected