diff --git a/.fvmrc b/.fvmrc index 06bcdee..5913bec 100644 --- a/.fvmrc +++ b/.fvmrc @@ -1,3 +1,3 @@ { - "flutter": "3.41.0" + "flutter": "3.44.4" } \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index dfc6c48..adb3bc7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.0.3 + +- Allow file execution on postgres database + ## 0.0.2 - Prevent dynamic passing Migration instead of Migration diff --git a/melos.yaml b/melos.yaml deleted file mode 100644 index f3b9f11..0000000 --- a/melos.yaml +++ /dev/null @@ -1,5 +0,0 @@ -name: nightingale -repository: https://github.com/Iconica-Development/nightingale/ - -packages: - - packages/** diff --git a/packages/nightingale/lib/src/context.dart b/packages/nightingale/lib/src/context.dart index 9af07d0..1358f78 100644 --- a/packages/nightingale/lib/src/context.dart +++ b/packages/nightingale/lib/src/context.dart @@ -1,7 +1,7 @@ abstract class MigrationContext { - const MigrationContext(this.value); + const MigrationContext(this.context); - final T value; + final T context; Future executeCommand(String sql); Future executeFile(String file); diff --git a/packages/nightingale/lib/src/runner.dart b/packages/nightingale/lib/src/runner.dart index 8c41889..3a78eb3 100644 --- a/packages/nightingale/lib/src/runner.dart +++ b/packages/nightingale/lib/src/runner.dart @@ -44,7 +44,7 @@ class MigrationRunner { await databaseContext.runTransaction((session) async { final migration = migrations[i]; await migration.forward(session); - await history.record(session.value, i, migration.name); + await history.record(session.context, i, migration.name); }); } } @@ -64,7 +64,7 @@ class MigrationRunner { if (migration.backward != null) { await migration.backward!.call(session); } - await history.remove(session.value, i, migration.name); + await history.remove(session.context, i, migration.name); }); } } diff --git a/packages/nightingale/pubspec.yaml b/packages/nightingale/pubspec.yaml index 3c099dc..f7511b3 100644 --- a/packages/nightingale/pubspec.yaml +++ b/packages/nightingale/pubspec.yaml @@ -1,14 +1,13 @@ name: nightingale -version: 0.0.2 +version: 0.0.3 repository: https://github.com/Iconica-Development/nightingale/ description: A library for managing migrations. publish_to: https://forgejo.internal.iconica.nl/api/packages/internal/pub/ -environment: - sdk: ^3.10.0 - resolution: workspace +environment: + sdk: ^3.12.2 dependencies: args: ^2.7.0 diff --git a/packages/postgres_nightingale/CHANGELOG.md b/packages/postgres_nightingale/CHANGELOG.md index d916a4d..0a5cc14 100644 --- a/packages/postgres_nightingale/CHANGELOG.md +++ b/packages/postgres_nightingale/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.0.3 + +- Allow file execution on postgres database + ## 0.0.2 - Prevent dynamic Migrations diff --git a/packages/postgres_nightingale/lib/src/implementation.dart b/packages/postgres_nightingale/lib/src/implementation.dart index bdded63..a2263d2 100644 --- a/packages/postgres_nightingale/lib/src/implementation.dart +++ b/packages/postgres_nightingale/lib/src/implementation.dart @@ -5,14 +5,30 @@ import "package:nightingale/nightingale.dart"; import "package:postgres/postgres.dart"; class PostgresMigrationContext extends MigrationContext { - const PostgresMigrationContext(super.value); + const PostgresMigrationContext( + super.context, { + required this._endpoint, + }); + + final Endpoint _endpoint; @override - Future executeCommand(String sql) async => value.execute(sql); + Future executeCommand(String sql) async => context.execute(sql); @override Future executeFile(String file) async { - final result = await Process.run("psql", ["-f", file]); + final result = await Process.run( + "psql", + [ + "-h ${_endpoint.host}", + "-p ${_endpoint.port}", + "-U ${_endpoint.username}", + "-d ${_endpoint.database}", + "-f $file", + ], + environment: {"PGPASSWORD": "${_endpoint.password}"}, + ); + if (result.exitCode != 0) { throw Exception("PSQL execution failure\n${result.stdout}"); } @@ -21,24 +37,28 @@ class PostgresMigrationContext extends MigrationContext { @override Future runTransaction( Future Function(MigrationContext session) executor, - ) async { - final value = this.value; - return (value is Connection) - ? await value.runTx((value) async => executor(withValue(value))) - : await executor(this); - } + ) async => switch (context) { + final Connection context => await context.runTx( + (value) async => executor(withValue(value)), + ), + _ => await executor(this), + }; PostgresMigrationContext withValue(Session value) => - PostgresMigrationContext(value); + PostgresMigrationContext(value, endpoint: _endpoint); } class PostgresMigrationRunner extends MigrationRunner { factory PostgresMigrationRunner({ required Session database, + required Endpoint endpoint, required List> migrations, }) => PostgresMigrationRunner._( database: database, - contextGenerator: (database) async => PostgresMigrationContext(database), + contextGenerator: (database) async => PostgresMigrationContext( + database, + endpoint: endpoint, + ), migrations: migrations, history: const PostgresMigrationHistory(), ); diff --git a/packages/postgres_nightingale/pubspec.yaml b/packages/postgres_nightingale/pubspec.yaml index db43ca2..459c58c 100644 --- a/packages/postgres_nightingale/pubspec.yaml +++ b/packages/postgres_nightingale/pubspec.yaml @@ -1,14 +1,13 @@ name: postgres_nightingale -version: 0.0.2 +version: 0.0.3 repository: https://github.com/Iconica-Development/nightingale/ description: A package for managing migrations in postgres publish_to: https://forgejo.internal.iconica.nl/api/packages/internal/pub/ -environment: - sdk: ^3.10.0 - resolution: workspace +environment: + sdk: ^3.12.2 dependencies: meta: ^1.17.0 diff --git a/pubspec.lock b/pubspec.lock index 23d11b9..8ccb209 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -17,14 +17,6 @@ packages: url: "https://pub.dev" source: hosted version: "10.2.0" - ansi_styles: - dependency: transitive - description: - name: ansi_styles - sha256: "9c656cc12b3c27b17dd982b2cc5c0cfdfbdabd7bc8f3ae5e8542d9867b47ce8a" - url: "https://pub.dev" - source: hosted - version: "0.3.2+1" args: dependency: transitive description: @@ -65,14 +57,6 @@ packages: url: "https://pub.dev" source: hosted version: "1.4.0" - checked_yaml: - dependency: transitive - description: - name: checked_yaml - sha256: "959525d3162f249993882720d52b7e0c833978df229be20702b33d48d91de70f" - url: "https://pub.dev" - source: hosted - version: "2.0.4" cli_config: dependency: transitive description: @@ -81,22 +65,6 @@ packages: url: "https://pub.dev" source: hosted version: "0.2.0" - cli_launcher: - dependency: transitive - description: - name: cli_launcher - sha256: "17d2744fb9a254c49ec8eda582536abe714ea0131533e24389843a4256f82eac" - url: "https://pub.dev" - source: hosted - version: "0.3.2+1" - cli_util: - dependency: transitive - description: - name: cli_util - sha256: ff6785f7e9e3c38ac98b2fb035701789de90154024a75b6cb926445e83197d1c - url: "https://pub.dev" - source: hosted - version: "0.4.2" collection: dependency: transitive description: @@ -105,14 +73,6 @@ packages: url: "https://pub.dev" source: hosted version: "1.19.1" - conventional_commit: - dependency: transitive - description: - name: conventional_commit - sha256: c40b1b449ce2a63fa2ce852f35e3890b1e182f5951819934c0e4a66254bc0dc3 - url: "https://pub.dev" - source: hosted - version: "0.6.1+1" convert: dependency: transitive description: @@ -177,22 +137,6 @@ packages: url: "https://pub.dev" source: hosted version: "2.1.3" - graphs: - dependency: transitive - description: - name: graphs - sha256: "741bbf84165310a68ff28fe9e727332eef1407342fca52759cb21ad8177bb8d0" - url: "https://pub.dev" - source: hosted - version: "2.3.2" - http: - dependency: transitive - description: - name: http - sha256: "87721a4a50b19c7f1d49001e51409bddc46303966ce89a65af4f4e6004896412" - url: "https://pub.dev" - source: hosted - version: "1.6.0" http_multi_server: dependency: transitive description: @@ -217,14 +161,6 @@ packages: url: "https://pub.dev" source: hosted version: "1.0.5" - json_annotation: - dependency: transitive - description: - name: json_annotation - sha256: cb09e7dac6210041fad964ed7fbee004f14258b4eca4040f72d1234062ace4c8 - url: "https://pub.dev" - source: hosted - version: "4.11.0" lints: dependency: transitive description: @@ -249,14 +185,6 @@ packages: url: "https://pub.dev" source: hosted version: "0.12.18" - melos: - dependency: "direct dev" - description: - name: melos - sha256: "7dcc4444d79b538ab8353bb38308f97e90b032984f75e8fd516fedfe8160b35e" - url: "https://pub.dev" - source: hosted - version: "7.4.0" meta: dependency: transitive description: @@ -273,14 +201,6 @@ packages: url: "https://pub.dev" source: hosted version: "2.0.0" - mustache_template: - dependency: transitive - description: - name: mustache_template - sha256: "4326d0002ff58c74b9486990ccbdab08157fca3c996fe9e197aff9d61badf307" - url: "https://pub.dev" - source: hosted - version: "2.0.3" node_preamble: dependency: transitive description: @@ -305,22 +225,6 @@ packages: url: "https://pub.dev" source: hosted version: "1.9.1" - petitparser: - dependency: transitive - description: - name: petitparser - sha256: "91bd59303e9f769f108f8df05e371341b15d59e995e6806aefab827b58336675" - url: "https://pub.dev" - source: hosted - version: "7.0.2" - platform: - dependency: transitive - description: - name: platform - sha256: "5d6b1b0036a5f331ebc77c850ebc8506cbc1e9416c27e59b439f917a902a4984" - url: "https://pub.dev" - source: hosted - version: "3.1.6" pool: dependency: transitive description: @@ -337,22 +241,6 @@ packages: url: "https://pub.dev" source: hosted version: "3.5.9" - process: - dependency: transitive - description: - name: process - sha256: c6248e4526673988586e8c00bb22a49210c258dc91df5227d5da9748ecf79744 - url: "https://pub.dev" - source: hosted - version: "5.0.5" - prompts: - dependency: transitive - description: - name: prompts - sha256: "3773b845e85a849f01e793c4fc18a45d52d7783b4cb6c0569fad19f9d0a774a1" - url: "https://pub.dev" - source: hosted - version: "2.0.0" pub_semver: dependency: transitive description: @@ -361,22 +249,6 @@ packages: url: "https://pub.dev" source: hosted version: "2.2.0" - pub_updater: - dependency: transitive - description: - name: pub_updater - sha256: "739a0161d73a6974c0675b864fb0cf5147305f7b077b7f03a58fa7a9ab3e7e7d" - url: "https://pub.dev" - source: hosted - version: "0.5.0" - pubspec_parse: - dependency: transitive - description: - name: pubspec_parse - sha256: "0560ba233314abbed0a48a2956f7f022cce7c3e1e73df540277da7544cad4082" - url: "https://pub.dev" - source: hosted - version: "1.5.0" shelf: dependency: transitive description: @@ -553,14 +425,6 @@ packages: url: "https://pub.dev" source: hosted version: "1.2.1" - xml: - dependency: transitive - description: - name: xml - sha256: "971043b3a0d3da28727e40ed3e0b5d18b742fa5a68665cca88e74b7876d5e025" - url: "https://pub.dev" - source: hosted - version: "6.6.1" yaml: dependency: transitive description: @@ -569,13 +433,5 @@ packages: url: "https://pub.dev" source: hosted version: "3.1.3" - yaml_edit: - dependency: transitive - description: - name: yaml_edit - sha256: "07c9e63ba42519745182b88ca12264a7ba2484d8239958778dfe4d44fe760488" - url: "https://pub.dev" - source: hosted - version: "2.2.4" sdks: - dart: ">=3.10.0 <4.0.0" + dart: ">=3.12.2 <4.0.0" diff --git a/pubspec.yaml b/pubspec.yaml index d72a6a8..e7b72bd 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,19 +1,18 @@ name: nightingale_workspace -version: 0.0.2 +version: 0.0.3 repository: https://github.com/Iconica-Development/nightingale/ description: A library for managing migrations. publish_to: https://forgejo.internal.iconica.nl/api/packages/internal/pub/ environment: - sdk: ">=3.10.0 <4.0.0" + sdk: ^3.12.2 workspace: - packages/nightingale - packages/postgres_nightingale dev_dependencies: - melos: ^7.4.0 flutter_iconica_analysis: hosted: https://forgejo.internal.iconica.nl/api/packages/internal/pub/ version: ^8.0.0