diff --git a/packages/orm/angel_migration_runner/example/main.dart b/packages/orm/angel_migration_runner/example/main.dart index 7f8f2aa8..e7a4926c 100755 --- a/packages/orm/angel_migration_runner/example/main.dart +++ b/packages/orm/angel_migration_runner/example/main.dart @@ -9,9 +9,15 @@ import 'package:mysql_client/mysql_client.dart'; import 'todo.dart'; void main(List args) async { + Connection conn = await Connection.open(Endpoint( + host: 'localhost', + port: 5432, + database: 'demo', + username: 'demouser', + password: 'demo123')); + var postgresqlMigrationRunner = PostgresMigrationRunner( - PostgreSQLConnection('localhost', 5432, 'demo', - username: 'demouser', password: 'demo123'), + conn, migrations: [ UserMigration(), TodoMigration(), diff --git a/packages/orm/angel_migration_runner/lib/src/postgres/runner.dart b/packages/orm/angel_migration_runner/lib/src/postgres/runner.dart index 90715061..8f1b33bc 100755 --- a/packages/orm/angel_migration_runner/lib/src/postgres/runner.dart +++ b/packages/orm/angel_migration_runner/lib/src/postgres/runner.dart @@ -11,7 +11,7 @@ class PostgresMigrationRunner implements MigrationRunner { final _log = Logger('PostgresMigrationRunner'); final Map migrations = {}; - final PostgreSQLConnection connection; + final Connection connection; final Queue _migrationQueue = Queue(); bool _connected = false; @@ -34,7 +34,8 @@ class PostgresMigrationRunner implements MigrationRunner { } if (!_connected) { - await connection.open(); + //await connection.open(); + //Connection.open(_endpoint!, settings: _settings); _connected = true; } @@ -55,7 +56,7 @@ class PostgresMigrationRunner implements MigrationRunner { @override Future up() async { await _init(); - var r = await connection.query('SELECT path from migrations;'); + var r = await connection.execute('SELECT path from migrations;'); var existing = r.expand((x) => x).cast(); var toRun = []; @@ -64,7 +65,7 @@ class PostgresMigrationRunner implements MigrationRunner { }); if (toRun.isNotEmpty) { - var r = await connection.query('SELECT MAX(batch) from migrations;'); + var r = await connection.execute('SELECT MAX(batch) from migrations;'); var curBatch = (r[0][0] ?? 0) as int; var batch = curBatch + 1; @@ -74,16 +75,15 @@ class PostgresMigrationRunner implements MigrationRunner { migration.up(schema); _log.info('Added "$k" into "migrations" table.'); await schema.run(connection).then((_) { - return connection.transaction((ctx) async { - var result = await ctx.query( + return connection.runTx((ctx) async { + var result = await ctx.execute( "INSERT INTO MIGRATIONS (batch, path) VALUES ($batch, '$k')"); - return result.affectedRowCount; + return result.affectedRows; }); - //return connection.execute( - // 'INSERT INTO MIGRATIONS (batch, path) VALUES ($batch, \'$k\');'); }).catchError((e) { _log.severe('Failed to insert into "migrations" table.'); + return -1; }); } } else { @@ -95,11 +95,10 @@ class PostgresMigrationRunner implements MigrationRunner { Future rollback() async { await _init(); - PostgreSQLResult r = - await connection.query('SELECT MAX(batch) from migrations;'); + Result r = await connection.execute('SELECT MAX(batch) from migrations;'); var curBatch = (r[0][0] ?? 0) as int; r = await connection - .query('SELECT path from migrations WHERE batch = $curBatch;'); + .execute('SELECT path from migrations WHERE batch = $curBatch;'); var existing = r.expand((x) => x).cast(); var toRun = []; @@ -127,7 +126,7 @@ class PostgresMigrationRunner implements MigrationRunner { Future reset() async { await _init(); var r = await connection - .query('SELECT path from migrations ORDER BY batch DESC;'); + .execute('SELECT path from migrations ORDER BY batch DESC;'); var existing = r.expand((x) => x).cast(); var toRun = existing.where(migrations.containsKey).toList(); diff --git a/packages/orm/angel_migration_runner/lib/src/postgres/schema.dart b/packages/orm/angel_migration_runner/lib/src/postgres/schema.dart index 2a1d4aa0..d287a983 100755 --- a/packages/orm/angel_migration_runner/lib/src/postgres/schema.dart +++ b/packages/orm/angel_migration_runner/lib/src/postgres/schema.dart @@ -14,18 +14,18 @@ class PostgresSchema extends Schema { factory PostgresSchema() => PostgresSchema._(StringBuffer(), 0); - Future run(PostgreSQLConnection connection) async { + Future run(Connection connection) async { //return connection.execute(compile()); - var result = await connection.transaction((ctx) async { + var result = await connection.runTx((ctx) async { var sql = compile(); - var result = await ctx.query(sql).catchError((e) { + var result = await ctx.execute(sql).catchError((e) { _log.severe('Failed to run query: [ $sql ]', e); throw Exception(e); }); - return result.affectedRowCount; + return result.affectedRows; }); - return (result is int) ? result : 0; + return result; } String compile() => _buf.toString(); diff --git a/packages/orm/angel_migration_runner/pubspec.yaml b/packages/orm/angel_migration_runner/pubspec.yaml index e230d76a..1df937db 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.1.1 +version: 8.2.0 description: Command-line based database migration runner for Angel3's ORM. homepage: https://angel3-framework.web.app/ repository: https://github.com/dart-backend/angel/tree/master/packages/orm/angel_migration_runner @@ -11,7 +11,7 @@ dependencies: angel3_orm: ^8.0.0 args: ^2.4.0 charcode: ^1.3.0 - postgres: ^2.6.0 + postgres: ^3.0.0 mysql_client: ^0.0.27 mysql1: ^0.20.0 logging: ^1.2.0 diff --git a/packages/orm/angel_orm_postgres/test/common.dart b/packages/orm/angel_orm_postgres/test/common.dart index c8135533..daac0d2e 100644 --- a/packages/orm/angel_orm_postgres/test/common.dart +++ b/packages/orm/angel_orm_postgres/test/common.dart @@ -20,6 +20,7 @@ Future closePg(QueryExecutor executor) async { } Future connectToPostgres(Iterable schemas) async { + // postgres://kfayrlbi:OAaEE39zOMLEPfH4DDgHbGNVsQtNdHu7@heffalump.db.elephantsql.com/kfayrlbi var conn = await Connection.open(Endpoint( host: 'localhost', port: 5432,