Skip to content

Commit

Permalink
bug: allow empty scripts array closes #2
Browse files Browse the repository at this point in the history
  • Loading branch information
esarbanis committed Aug 23, 2019
1 parent e33cb1a commit 5d22773
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 46 deletions.
6 changes: 1 addition & 5 deletions lib/src/migration_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,5 @@ class MigrationConfig {
: assert(initializationScript != null,
'The initializationScript cannot be null.'),
assert(
migrationScripts != null, 'The migrationScripts cannot be null.'),
assert(initializationScript.isNotEmpty,
'The initializationScript cannot be empty.'),
assert(migrationScripts.isNotEmpty,
'The migrationScripts cannot be empty.');
migrationScripts != null, 'The migrationScripts cannot be null.');
}
16 changes: 8 additions & 8 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ packages:
name: async
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.8"
version: "2.1.0"
boolean_selector:
dependency: transitive
description:
Expand Down Expand Up @@ -45,7 +45,7 @@ packages:
name: matcher
url: "https://pub.dartlang.org"
source: hosted
version: "0.12.3+1"
version: "0.12.5"
meta:
dependency: transitive
description:
Expand Down Expand Up @@ -73,14 +73,14 @@ packages:
name: pedantic
url: "https://pub.dartlang.org"
source: hosted
version: "1.4.0"
version: "1.5.0"
quiver:
dependency: transitive
description:
name: quiver
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.1"
version: "2.0.2"
sky_engine:
dependency: transitive
description: flutter
Expand All @@ -92,7 +92,7 @@ packages:
name: source_span
url: "https://pub.dartlang.org"
source: hosted
version: "1.5.4"
version: "1.5.5"
sqflite:
dependency: "direct main"
description:
Expand All @@ -113,7 +113,7 @@ packages:
name: stream_channel
url: "https://pub.dartlang.org"
source: hosted
version: "1.6.8"
version: "2.0.0"
string_scanner:
dependency: transitive
description:
Expand Down Expand Up @@ -141,7 +141,7 @@ packages:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
version: "0.2.2"
version: "0.2.4"
typed_data:
dependency: transitive
description:
Expand All @@ -157,4 +157,4 @@ packages:
source: hosted
version: "2.0.8"
sdks:
dart: ">=2.1.0 <3.0.0"
dart: ">=2.2.0 <3.0.0"
77 changes: 44 additions & 33 deletions test/src/migrator_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ import 'package:sqflite/sqflite.dart';
import 'package:sqflite_migration/sqflite_migration.dart';
import 'package:sqflite_migration/src/migrator.dart';

class MockConfig extends Mock implements MigrationConfig {}
class MockDatabase extends Mock implements Database {}

void main() {
test('should not run any executions on an empty initialiazationScript list',
() async {
var db = MockDatabase();

var config = MockConfig();
when(config.initializationScript).thenReturn([]);
when(config.migrationScripts).thenReturn([]);
var config = MigrationConfig(
initializationScript: [],
migrationScripts: [],
);

await Migrator(config).executeInitialization(db, 1);

Expand All @@ -26,9 +26,10 @@ void main() {
test('should run executions on an initialiazationScript list of 1', () async {
var db = MockDatabase();

var config = MockConfig();
when(config.initializationScript).thenReturn(['script line 1']);
when(config.migrationScripts).thenReturn([]);
var config = MigrationConfig(
initializationScript: ['script line 1'],
migrationScripts: [],
);

await Migrator(config).executeInitialization(db, 1);

Expand All @@ -38,10 +39,10 @@ void main() {
test('should run all executions on an initialiazationScript list', () async {
var db = MockDatabase();

var config = MockConfig();
when(config.initializationScript)
.thenReturn(['script line 1', 'script line 2']);
when(config.migrationScripts).thenReturn([]);
var config = MigrationConfig(
initializationScript: ['script line 1', 'script line 2'],
migrationScripts: [],
);

await Migrator(config).executeInitialization(db, 1);

Expand All @@ -52,11 +53,10 @@ void main() {
test('should run any migrations when initializing', () async {
var db = MockDatabase();

var config = MockConfig();
when(config.initializationScript)
.thenReturn(['init script line 1', 'init script line 2']);
when(config.migrationScripts)
.thenReturn(['migration script line 1', 'migration script line 2']);
var config = MigrationConfig(
initializationScript: ['init script line 1', 'init script line 2'],
migrationScripts: ['migration script line 1', 'migration script line 2'],
);

await Migrator(config).executeInitialization(db, 1);

Expand All @@ -70,7 +70,10 @@ void main() {
test('should throw error if the new version is not greater than the old',
() async {
var db = MockDatabase();
var config = MockConfig();
var config = MigrationConfig(
initializationScript: [],
migrationScripts: [],
);

expect(
() async => await Migrator(config).executeMigration(db, 1, 1),
Expand All @@ -85,8 +88,10 @@ void main() {
'should throw error if the new version is greater than the migration scripts',
() async {
var db = MockDatabase();
var config = MockConfig();
when(config.migrationScripts).thenReturn([]);
var config = MigrationConfig(
initializationScript: ['init script line 1', 'init script line 2'],
migrationScripts: [],
);

expect(
() async => await Migrator(config).executeMigration(db, 1, 2),
Expand All @@ -101,8 +106,10 @@ void main() {
'should throw error if the new version is greater than the migration scripts',
() async {
var db = MockDatabase();
var config = MockConfig();
when(config.migrationScripts).thenReturn([]);
var config = MigrationConfig(
initializationScript: [],
migrationScripts: [],
);

expect(
() async => await Migrator(config).executeMigration(db, 1, 2),
Expand All @@ -115,12 +122,14 @@ void main() {

test('should not execute migrations older than the oldVersion', () async {
var db = MockDatabase();
var config = MockConfig();
when(config.migrationScripts).thenReturn([
'migration line 1',
'migration line 2',
'migration line 3',
]);
var config = MigrationConfig(
initializationScript: [],
migrationScripts: [
'migration line 1',
'migration line 2',
'migration line 3',
],
);

await Migrator(config).executeMigration(db, 2, 3);

Expand All @@ -130,12 +139,14 @@ void main() {

test('should not execute migrations newer than the newVersion', () async {
var db = MockDatabase();
var config = MockConfig();
when(config.migrationScripts).thenReturn([
'migration line 1',
'migration line 2',
'migration line 3',
]);
var config = MigrationConfig(
initializationScript: [],
migrationScripts: [
'migration line 1',
'migration line 2',
'migration line 3',
],
);

await Migrator(config).executeMigration(db, 1, 2);

Expand Down

0 comments on commit 5d22773

Please sign in to comment.