-
Notifications
You must be signed in to change notification settings - Fork 154
Add integration for Flyway #1077
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| <Project Sdk="Aspire.AppHost.Sdk/13.0.0"> | ||
|
|
||
| <PropertyGroup> | ||
| <OutputType>Exe</OutputType> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <ProjectReference Include="..\..\..\src\CommunityToolkit.Aspire.Hosting.PostgreSQL.Extensions\CommunityToolkit.Aspire.Hosting.PostgreSQL.Extensions.csproj" IsAspireProjectResource="false" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| var builder = DistributedApplication.CreateBuilder(args); | ||
|
|
||
| // 1. Add Flyway resource | ||
| var flywayMigration = builder | ||
| .AddFlyway("flywayMigration", "../database/migrations"); | ||
|
|
||
| // 2. Add Postgres resource with a database, and call `WithFlywayMigration` | ||
| // Adminer is added here for convenience to inspect the database after migration | ||
| var postgresDb = builder | ||
| .AddPostgres("postgres") | ||
| .WithImageTag("17") | ||
| .WithAdminer() | ||
| .AddDatabase("postgresDb", "space") | ||
| .WithFlywayMigration(flywayMigration); | ||
|
|
||
| // 3. Let Flyway wait for Postgres database to be ready | ||
| flywayMigration.WaitFor(postgresDb); | ||
|
|
||
| builder.Build().Run(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| { | ||
| "$schema": "https://json.schemastore.org/launchsettings.json", | ||
| "profiles": { | ||
| "https": { | ||
| "commandName": "Project", | ||
| "dotnetRunMessages": true, | ||
| "launchBrowser": true, | ||
| "applicationUrl": "https://localhost:17202;http://localhost:15211", | ||
| "environmentVariables": { | ||
| "ASPNETCORE_ENVIRONMENT": "Development", | ||
| "DOTNET_ENVIRONMENT": "Development", | ||
| "DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "https://localhost:21182", | ||
| "DOTNET_RESOURCE_SERVICE_ENDPOINT_URL": "https://localhost:22097" | ||
| } | ||
| }, | ||
| "http": { | ||
| "commandName": "Project", | ||
| "dotnetRunMessages": true, | ||
| "launchBrowser": true, | ||
| "applicationUrl": "http://localhost:15211", | ||
| "environmentVariables": { | ||
| "ASPNETCORE_ENVIRONMENT": "Development", | ||
| "DOTNET_ENVIRONMENT": "Development", | ||
| "DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "http://localhost:19298", | ||
| "DOTNET_RESOURCE_SERVICE_ENDPOINT_URL": "http://localhost:20141" | ||
| } | ||
| } | ||
| } | ||
| } |
11 changes: 11 additions & 0 deletions
11
examples/flyway/02.ContainerConfiguration/02.ContainerConfiguration.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| <Project Sdk="Aspire.AppHost.Sdk/13.0.0"> | ||
|
|
||
| <PropertyGroup> | ||
| <OutputType>Exe</OutputType> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <ProjectReference Include="..\..\..\src\CommunityToolkit.Aspire.Hosting.PostgreSQL.Extensions\CommunityToolkit.Aspire.Hosting.PostgreSQL.Extensions.csproj" IsAspireProjectResource="false" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| var builder = DistributedApplication.CreateBuilder(args); | ||
|
|
||
| // 1. Add Flyway resource | ||
| // Flyway resource is a container resource, so you can configure it further if needed | ||
| // However, avoid setting container arguments, by calling `WithArgs`, as they may conflict with the ones set by the Flyway integration | ||
| var flywayMigration = builder | ||
| .AddFlyway("flywayMigration", "../database/migrations") | ||
| .WithImageTag("11"); | ||
|
|
||
| // 2. Add Postgres resource with a database, and call `WithFlywayMigration` | ||
| // Adminer is added here for convenience to inspect the database after migration | ||
| var postgresDb = builder | ||
| .AddPostgres("postgres") | ||
| .WithImageTag("17") | ||
| .WithAdminer() | ||
| .AddDatabase("postgresDb", "space") | ||
| .WithFlywayMigration(flywayMigration); | ||
|
|
||
| // 3. Let Flyway wait for Postgres database to be ready | ||
| flywayMigration.WaitFor(postgresDb); | ||
|
|
||
| builder.Build().Run(); |
29 changes: 29 additions & 0 deletions
29
examples/flyway/02.ContainerConfiguration/Properties/launchSettings.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| { | ||
| "$schema": "https://json.schemastore.org/launchsettings.json", | ||
| "profiles": { | ||
| "https": { | ||
| "commandName": "Project", | ||
| "dotnetRunMessages": true, | ||
| "launchBrowser": true, | ||
| "applicationUrl": "https://localhost:17202;http://localhost:15211", | ||
| "environmentVariables": { | ||
| "ASPNETCORE_ENVIRONMENT": "Development", | ||
| "DOTNET_ENVIRONMENT": "Development", | ||
| "DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "https://localhost:21182", | ||
| "DOTNET_RESOURCE_SERVICE_ENDPOINT_URL": "https://localhost:22097" | ||
| } | ||
| }, | ||
| "http": { | ||
| "commandName": "Project", | ||
| "dotnetRunMessages": true, | ||
| "launchBrowser": true, | ||
| "applicationUrl": "http://localhost:15211", | ||
| "environmentVariables": { | ||
| "ASPNETCORE_ENVIRONMENT": "Development", | ||
| "DOTNET_ENVIRONMENT": "Development", | ||
| "DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "http://localhost:19298", | ||
| "DOTNET_RESOURCE_SERVICE_ENDPOINT_URL": "http://localhost:20141" | ||
| } | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| <Project Sdk="Aspire.AppHost.Sdk/13.0.0"> | ||
|
|
||
| <PropertyGroup> | ||
| <OutputType>Exe</OutputType> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <ProjectReference Include="..\..\..\src\CommunityToolkit.Aspire.Hosting.PostgreSQL.Extensions\CommunityToolkit.Aspire.Hosting.PostgreSQL.Extensions.csproj" IsAspireProjectResource="false" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| var builder = DistributedApplication.CreateBuilder(args); | ||
|
|
||
| // 1. Set path to migration scripts for both Flyway resources | ||
| const string migrationScriptsPath = "../database/migrations"; | ||
|
|
||
| // 2. Add Flyway resource for database migration | ||
| var flywayMigration = builder | ||
| .AddFlyway("flywayMigration", migrationScriptsPath); | ||
|
|
||
| // 3. Add Flyway resource for database repair | ||
| // Repair is run on demand, so we call `WithExplicitStart` | ||
| var flywayRepair = builder | ||
| .AddFlyway("flywayRepair", migrationScriptsPath) | ||
| .WithExplicitStart(); | ||
|
|
||
| // 4. Add Postgres resource with a database, and call `WithFlywayMigration` and `WithFlywayRepair` | ||
| // Adminer is added here for convenience to inspect the database after migration | ||
| var postgresDb = builder | ||
| .AddPostgres("postgres") | ||
| .WithImageTag("17") | ||
| .WithAdminer() | ||
| .AddDatabase("postgresDb", "space") | ||
| .WithFlywayMigration(flywayMigration) | ||
| .WithFlywayRepair(flywayRepair); | ||
|
|
||
| // 5. Let Flyway resources wait for Postgres database to be ready | ||
| flywayMigration.WaitFor(postgresDb); | ||
| flywayRepair.WaitFor(postgresDb); | ||
|
|
||
| builder.Build().Run(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| { | ||
| "$schema": "https://json.schemastore.org/launchsettings.json", | ||
| "profiles": { | ||
| "https": { | ||
| "commandName": "Project", | ||
| "dotnetRunMessages": true, | ||
| "launchBrowser": true, | ||
| "applicationUrl": "https://localhost:17202;http://localhost:15211", | ||
| "environmentVariables": { | ||
| "ASPNETCORE_ENVIRONMENT": "Development", | ||
| "DOTNET_ENVIRONMENT": "Development", | ||
| "DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "https://localhost:21182", | ||
| "DOTNET_RESOURCE_SERVICE_ENDPOINT_URL": "https://localhost:22097" | ||
| } | ||
| }, | ||
| "http": { | ||
| "commandName": "Project", | ||
| "dotnetRunMessages": true, | ||
| "launchBrowser": true, | ||
| "applicationUrl": "http://localhost:15211", | ||
| "environmentVariables": { | ||
| "ASPNETCORE_ENVIRONMENT": "Development", | ||
| "DOTNET_ENVIRONMENT": "Development", | ||
| "DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "http://localhost:19298", | ||
| "DOTNET_RESOURCE_SERVICE_ENDPOINT_URL": "http://localhost:20141" | ||
| } | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| # Flyway Integration Samples | ||
|
|
||
| ## Samples | ||
|
|
||
| ### 01.Basic | ||
|
|
||
| Demonstrates the basic usage of Flyway integration, including execution of database migrations. | ||
|
|
||
| ### 02.ContainerConfiguration | ||
|
|
||
| Demonstrates how to configure Flyway integration as a container resource. | ||
|
|
||
| ### 03.Repair | ||
|
|
||
| Demonstrates the use of the Flyway repair command. | ||
|
|
||
| ## Run | ||
|
|
||
| To run any of the samples, navigate to the corresponding directory and run the following command: | ||
|
|
||
| ```bash | ||
| aspire run --project ProjectName.csproj | ||
| ``` | ||
|
|
||
| Replace `ProjectName.csproj` with the actual project file name of the sample you want to run. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| CREATE TABLE planets ( | ||
| name VARCHAR(100) NOT NULL | ||
| ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| INSERT INTO planets (name) | ||
| VALUES ('Earth'); |
16 changes: 16 additions & 0 deletions
16
src/CommunityToolkit.Aspire.Hosting.Flyway/CommunityToolkit.Aspire.Hosting.Flyway.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <AdditionalPackageTags>hosting flyway migration</AdditionalPackageTags> | ||
| <Description>An Aspire integration for Flyway database migration tool.</Description> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="Aspire.Hosting" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <InternalsVisibleTo Include="CommunityToolkit.Aspire.Hosting.Flyway.Tests" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> |
52 changes: 52 additions & 0 deletions
52
src/CommunityToolkit.Aspire.Hosting.Flyway/DistributedApplicationBuilderExtensions.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| using Aspire.Hosting.ApplicationModel; | ||
|
|
||
| namespace Aspire.Hosting; | ||
|
|
||
| /// <summary> | ||
| /// Extension methods to support adding Flyway to the <see cref="IDistributedApplicationBuilder"/>. | ||
| /// </summary> | ||
| public static class DistributedApplicationBuilderExtensions | ||
| { | ||
| extension(IDistributedApplicationBuilder builder) | ||
| { | ||
| /// <summary> | ||
| /// Adds a Flyway resource to the application with default configuration. | ||
| /// </summary> | ||
| /// <param name="name">The name of the Flyway resource.</param> | ||
| /// <param name="migrationScriptsPath">The path to the directory containing Flyway migration scripts.</param> | ||
| /// <returns>A reference to the <see cref="IResourceBuilder{T}"/>.</returns> | ||
| /// <remarks> | ||
| /// <para> | ||
| /// <paramref name="migrationScriptsPath"/> is an absolute or relative path on the host machine, and must be accessible by Docker. | ||
| /// </para> | ||
| /// <para> | ||
| /// This method is meant to be used in conjunction with a database resource added to the application and the Flyway extension built for that database resource. | ||
| /// For example, if adding a PostgreSQL database resource, the Flyway PostgreSQL extension can be used to configure the Flyway resource to perform migrations against that database. | ||
| /// </para> | ||
| /// <example> | ||
| /// This example shows how to add a Flyway resource with migration scripts located in the "./migrations" directory. | ||
| /// <code lang="csharp"> | ||
| /// var flywayMigration = builder.AddFlyway("flywayMigration", "./migrations"); | ||
| /// </code> | ||
| /// </example> | ||
| /// </remarks> | ||
| public IResourceBuilder<FlywayResource> AddFlyway([ResourceName] string name, string migrationScriptsPath) | ||
| { | ||
| ArgumentNullException.ThrowIfNull(name); | ||
TheBlueSky marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ArgumentException.ThrowIfNullOrWhiteSpace(migrationScriptsPath); | ||
|
|
||
| var resource = new FlywayResource(name); | ||
|
|
||
| var flywayResourceBuilder = builder | ||
| .AddResource(resource) | ||
| .WithImage(FlywayContainerImageTags.Image) | ||
| .WithImageTag(FlywayContainerImageTags.Tag) | ||
| .WithImageRegistry(FlywayContainerImageTags.Registry) | ||
| .WithEnvironment("FLYWAY_LOCATIONS", $"filesystem:{FlywayResource.MigrationScriptsDirectory}") | ||
| .WithEnvironment("REDGATE_DISABLE_TELEMETRY", "true") | ||
| .WithBindMount(Path.GetFullPath(migrationScriptsPath), FlywayResource.MigrationScriptsDirectory, isReadOnly: true); | ||
|
|
||
| return flywayResourceBuilder; | ||
| } | ||
| } | ||
| } | ||
19 changes: 19 additions & 0 deletions
19
src/CommunityToolkit.Aspire.Hosting.Flyway/FlywayContainerImageTags.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| namespace Aspire.Hosting.ApplicationModel; | ||
|
|
||
| internal static class FlywayContainerImageTags | ||
| { | ||
| /// <summary> | ||
| /// Docker image registry. | ||
| /// </summary> | ||
| public const string Registry = "docker.io"; | ||
|
|
||
| /// <summary> | ||
| /// Docker image name. | ||
| /// </summary> | ||
| public const string Image = "flyway/flyway"; | ||
|
|
||
| /// <summary> | ||
| /// Docker image tag. | ||
| /// </summary> | ||
| public const string Tag = "11"; | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.