Skip to content

Commit

Permalink
Add initial pass of Couchbase Migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
MattEdwardsWaggleBee committed Apr 29, 2024
1 parent c558eac commit 6221538
Show file tree
Hide file tree
Showing 15 changed files with 575 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ public static IServiceCollection AddProvider( this IServiceCollection services,
services.AddCouchbase( c =>
{
c.EnableTls = false;
c.WithBuckets( bucket );
// c.WithBuckets( bucket );
c.WithConnectionString( connectionString );
c.WithCredentials( userName, password );
c.MaxHttpConnections = maxHttpConnections;
//c.MaxHttpConnections = maxHttpConnections;
} );

return services;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"ConnectionString": "__DO_NOT_ADD_ENVIRONMENT_VALUE_HERE__",
"UserName": "__DO_NOT_ADD_SECRET_HERE__",
"Password": "__DO_NOT_ADD_SECRET_HERE__",
"MaxConnectionLimit": 20
"MaxConnectionLimit": 10
},
"Migrations": {
// Couchbase
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
<EmbeddedResource Include="Resources\1000-CreateInitialBuckets\migrationbucket\_default\cc0c81e0a030c64b8c80cbd05adf25e522f90bcd5525b442dda8a5ee83e0987ec3.json" />
<EmbeddedResource Include="Resources\1000-CreateInitialBuckets\migrationbucket\statements.json" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Couchbase.Extensions.DependencyInjection" Version="3.5.1" />
<PackageReference Include="CouchbaseNetClient" Version="3.5.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\Hyperbee.Migrations.Providers.Couchbase\Hyperbee.Migrations.Providers.Couchbase.csproj" />
<ProjectReference Include="..\..\src\Hyperbee.Migrations\Hyperbee.Migrations.csproj" />
Expand Down
38 changes: 0 additions & 38 deletions samples/Hyperbee.Migrations.MongoDB.Samples/Dockerfile

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
using System;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Couchbase.Core.Exceptions;
using Couchbase.Core.Exceptions;
using Couchbase.Diagnostics;
using Couchbase.Extensions.DependencyInjection;
using Hyperbee.Migrations.Providers.Couchbase.Services;
Expand Down Expand Up @@ -194,8 +190,6 @@ private async Task WaitForBucketsAsync( TimeSpan notifyInterval, CancellationTok

foreach ( var (bucketName, _) in await cluster.Buckets.GetAllBucketsAsync() )
{
_logger?.LogInformation( "Waiting for bucket {bucketName} ...", bucketName );

var bucket = await cluster.BucketAsync( bucketName );

while ( true )
Expand Down
6 changes: 1 addition & 5 deletions src/Hyperbee.Migrations/Wait/WaitHelper.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
using System;
using System.Threading;
using System.Threading.Tasks;

namespace Hyperbee.Migrations.Wait;
namespace Hyperbee.Migrations.Wait;

public static class WaitHelper
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
using DotNet.Testcontainers.Builders;
using DotNet.Testcontainers.Configurations;
using DotNet.Testcontainers.Containers;
using DotNet.Testcontainers.Images;
using DotNet.Testcontainers.Networks;
using Testcontainers.Couchbase;

namespace Hyperbee.Migrations.Integration.Tests.Container.Couchbase;

public class CouchbaseMigrationContainer
{
public static async Task<IFutureDockerImage> BuildMigrationImageAsync()
{
var location = CommonDirectoryPath.GetSolutionDirectory( "../../" );
var image = new ImageFromDockerfileBuilder()
.WithDeleteIfExists( true )
.WithCleanUp( true )
.WithName( "couchbase-db-migrations" )
.WithDockerfile( "samples/Hyperbee.MigrationRunner.Couchbase/Dockerfile" )
.WithDockerfileDirectory( location.DirectoryPath )
.Build();

await image.CreateAsync( CancellationToken.None )
.ConfigureAwait( false );

return image;
}

public static async Task<IContainer> BuildMigrationsAsync( string connectionString, INetwork network, IFutureDockerImage image = null )
{
image ??= await BuildMigrationImageAsync();

return new ContainerBuilder()
.WithCleanUp( true )
.WithNetwork( network )
.WithImage( image )
.WithEnvironment( "Couchbase__ConnectionString", connectionString )
.WithEnvironment( "Couchbase__UserName", CouchbaseBuilder.DefaultUsername )
.WithEnvironment( "Couchbase__Password", CouchbaseBuilder.DefaultPassword )
.WithEnvironment( "Migrations__FromPaths__0", "./Hyperbee.Migrations.Couchbase.Samples.dll" )
.WithEnvironment( "Migrations__Lock__Enabled", "true" )
.WithWaitStrategy( Wait.ForUnixContainer().AddCustomWaitStrategy( new WaitUntilExited() ) )
.Build();
}

public static async Task RunMigrationsAsync( string connectionString,INetwork network )
{
var migrationContainer = await BuildMigrationsAsync( connectionString, network );

await migrationContainer.StartAsync( CancellationToken.None )
.ConfigureAwait( false );
}

public class WaitUntilExited : IWaitUntil
{
public async Task<bool> UntilAsync( IContainer container )
{
await Task.CompletedTask;
return container.State == TestcontainersStates.Exited;
}
}
}
Loading

0 comments on commit 6221538

Please sign in to comment.