diff --git a/packages/orm/angel_migration_runner/CHANGELOG.md b/packages/orm/angel_migration_runner/CHANGELOG.md index 0ddc92d3..96883a10 100755 --- a/packages/orm/angel_migration_runner/CHANGELOG.md +++ b/packages/orm/angel_migration_runner/CHANGELOG.md @@ -1,5 +1,9 @@ # Change Log +## 8.2.2 + +Fixed `MariaDbMigrationRunner` migration issues + ## 8.2.1 * Updated README diff --git a/packages/orm/angel_migration_runner/README.md b/packages/orm/angel_migration_runner/README.md index 8c7fe159..e910fa8e 100755 --- a/packages/orm/angel_migration_runner/README.md +++ b/packages/orm/angel_migration_runner/README.md @@ -14,18 +14,15 @@ This package contains the implementation of the database migration for the follo ## Usage * Use `PostgresMigrationRunner` to perform database migration for PostgreSQL. - * Use `MySqlMigrationRunner` to perform database migration for MySQL and MariaDB. This runner is using [`mysql_client`](https://pub.dev/packages?q=mysql_client) driver. - * Use `MariaDbMigrationRunner` to perform database migration for MariaDB. This runner is using [`mysql1`](https://pub.dev/packages?q=mysql1) driver. ## Supported Operations -* reset - Clear out all records in the `migrations` table and drop all the ORM related tables. * up - Generate all the tables based on the ORM models. +* reset - Clear out all records in the `migrations` table and drop all the ORM related tables. * refresh - Run `reset` follow by `up` -## To do +## Limitation -* Update existing tables -* Reverse engineer tables into models +* Update schema changes is not supported diff --git a/packages/orm/angel_migration_runner/lib/src/mariadb/runner.dart b/packages/orm/angel_migration_runner/lib/src/mariadb/runner.dart index a4a344eb..ce8a255b 100644 --- a/packages/orm/angel_migration_runner/lib/src/mariadb/runner.dart +++ b/packages/orm/angel_migration_runner/lib/src/mariadb/runner.dart @@ -14,12 +14,12 @@ class MariaDbMigrationRunner implements MigrationRunner { final Map migrations = {}; final Queue _migrationQueue = Queue(); final MySqlConnection connection; - bool _connected = false; + //bool _connected = false; MariaDbMigrationRunner(this.connection, - {Iterable migrations = const [], bool connected = false}) { + {Iterable migrations = const [], bool connected = true}) { if (migrations.isNotEmpty) migrations.forEach(addMigration); - _connected = connected; + //_connected = connected; } @override @@ -34,20 +34,18 @@ class MariaDbMigrationRunner implements MigrationRunner { migrations.putIfAbsent(path.replaceAll('\\', '\\\\'), () => migration); } - if (!_connected) { - _connected = true; - } - await connection.query(''' CREATE TABLE IF NOT EXISTS migrations ( id integer NOT NULL AUTO_INCREMENT, batch integer, - path varchar(255), + path varchar(500), PRIMARY KEY(id) ); ''').then((result) { + //print(result.affectedRows); _log.fine('Check and create "migrations" table'); }).catchError((e) { + //print(e); _log.severe('Failed to create "migrations" table.', e); }); } @@ -59,7 +57,10 @@ class MariaDbMigrationRunner implements MigrationRunner { var existing = []; if (result.isNotEmpty) { - existing = result.expand((x) => x).cast().toList(); + var pathList = result.expand((x) => x).cast().toList(); + for (var path in pathList) { + existing.add(path.replaceAll("\\", "\\\\")); + } } var toRun = []; @@ -121,7 +122,10 @@ class MariaDbMigrationRunner implements MigrationRunner { .query('SELECT path from migrations WHERE batch = $curBatch;'); var existing = []; if (result.isNotEmpty) { - existing = result.expand((x) => x).cast().toList(); + var pathList = result.expand((x) => x).cast().toList(); + for (var path in pathList) { + existing.add(path.replaceAll("\\", "\\\\")); + } } var toRun = []; @@ -153,7 +157,10 @@ class MariaDbMigrationRunner implements MigrationRunner { .query('SELECT path from migrations ORDER BY batch DESC;'); var existing = []; if (r.isNotEmpty) { - existing = r.expand((x) => x).cast().toList(); + var pathList = r.expand((x) => x).cast().toList(); + for (var path in pathList) { + existing.add(path.replaceAll("\\", "\\\\")); + } } var toRun = existing.where(migrations.containsKey).toList(); diff --git a/packages/orm/angel_migration_runner/pubspec.yaml b/packages/orm/angel_migration_runner/pubspec.yaml index a54efa61..a2112a23 100755 --- a/packages/orm/angel_migration_runner/pubspec.yaml +++ b/packages/orm/angel_migration_runner/pubspec.yaml @@ -1,5 +1,5 @@ name: angel3_migration_runner -version: 8.2.1 +version: 8.2.2 description: The implementation of database migration for Angel3 framework. Designed to work with Angel3 ORM. homepage: https://angel3-framework.web.app/ repository: https://github.com/dart-backend/angel/tree/master/packages/orm/angel_migration_runner diff --git a/packages/orm/angel_migration_runner/test/mariadb_test.dart b/packages/orm/angel_migration_runner/test/mariadb_test.dart index 19edc8dd..9e6330f0 100644 --- a/packages/orm/angel_migration_runner/test/mariadb_test.dart +++ b/packages/orm/angel_migration_runner/test/mariadb_test.dart @@ -37,10 +37,15 @@ void main() async { ); }); - group('MariaDB', () { - test('migrate tables', () async { + group('MariaDB migrate tables', () { + test('up', () async { print("Test migration up"); - runner.up(); + await runner.up(); + }); + + test('reset', () async { + print("Test migration reset"); + await runner.reset(); }); });