From bc1f3474988af8612ca1b88b19cecd9ae84d9378 Mon Sep 17 00:00:00 2001 From: Simon Binder Date: Sun, 15 Mar 2020 15:16:22 +0100 Subject: [PATCH] Test transactions in migrations (#430) --- extras/integration_tests/tests/lib/database/database.dart | 7 +++++-- moor/lib/src/runtime/api/db_base.dart | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/extras/integration_tests/tests/lib/database/database.dart b/extras/integration_tests/tests/lib/database/database.dart index a51ebd0a..9818dc23 100644 --- a/extras/integration_tests/tests/lib/database/database.dart +++ b/extras/integration_tests/tests/lib/database/database.dart @@ -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 { diff --git a/moor/lib/src/runtime/api/db_base.dart b/moor/lib/src/runtime/api/db_base.dart index f9888e77..b64a4441 100644 --- a/moor/lib/src/runtime/api/db_base.dart +++ b/moor/lib/src/runtime/api/db_base.dart @@ -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