Skip to content

Commit

Permalink
updated to .net 9, added doc pages, update workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
varndellwagglebee committed Nov 18, 2024
1 parent 9cd22d2 commit c4a1b53
Show file tree
Hide file tree
Showing 31 changed files with 1,062 additions and 29 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ on:
- develop

env:
DOTNET_VERSION: '8.0.x'
DOTNET_VERSION: '9.0.x'

jobs:
format:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
env:
BRANCH_NAME: ${{ github.event.release.target_commitish }}
SOLUTION_NAME: ${{ vars.SOLUTION_NAME }}
DOTNET_VERSION: '8.0.x'
DOTNET_VERSION: '9.0.x'
NUGET_SOURCE: 'https://api.nuget.org/v3/index.json'
BUILD_CONFIGURATION: ''
VERSION_SUFFIX: ''
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ on:
env:
BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
SOLUTION_NAME: ${{ vars.SOLUTION_NAME }}
DOTNET_VERSION: '8.0.x'
DOTNET_VERSION: '9.0.x'

jobs:
test:
Expand Down
Empty file added Deploy GitHub Pages.yml
Empty file.
12 changes: 7 additions & 5 deletions Hyperbee.Migrations.sln
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,11 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "workflows", "workflows", "{
.github\workflows\publish.yml = .github\workflows\publish.yml
.github\workflows\test-report.yml = .github\workflows\test-report.yml
.github\workflows\test.yml = .github\workflows\test.yml
unlist-nuget.yml = unlist-nuget.yml
update-version.yml = update-version.yml
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "docs", "docs", "{FAE7F244-124F-4BCB-8EA6-049BEE4991B9}"
ProjectSection(SolutionItems) = preProject
todo.md = todo.md
EndProjectSection
Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "docs", "docs\docs.shproj", "{5A1580F9-6806-401E-9CAB-AC876DB070FD}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -130,9 +129,12 @@ Global
{C4B50B74-3FCA-453E-AF19-D9EA9233F8FC} = {17F0B438-3EBD-4566-9A22-7A5EC4AEAF3D}
{004E4E55-FA1C-49D0-865F-4FF238C7A1F3} = {5A09B7FE-D694-45B5-BCBC-256A8E06CFC5}
{A192B3D2-E452-4A85-BBA4-1A8499F1A056} = {004E4E55-FA1C-49D0-865F-4FF238C7A1F3}
{FAE7F244-124F-4BCB-8EA6-049BEE4991B9} = {5A09B7FE-D694-45B5-BCBC-256A8E06CFC5}
{5A1580F9-6806-401E-9CAB-AC876DB070FD} = {5A09B7FE-D694-45B5-BCBC-256A8E06CFC5}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {97071D77-035B-4126-AD4E-DE150E318714}
EndGlobalSection
GlobalSection(SharedMSBuildProjectFiles) = preSolution
docs\docs.projitems*{5a1580f9-6806-401e-9cab-ac876db070fd}*SharedItemsImports = 13
EndGlobalSection
EndGlobal
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ public class PeopleHaveFullNames : Migration // #2 inherit from Migration

# Build Requirements

* To build and run this project, **.NET 8 SDK** is required.
* Ensure your development tools are compatible with .NET 8.
* To build and run this project, **.NET 9 SDK** is required.
* Ensure your development tools are compatible with .NET 9.

## Building the Solution

* With .NET 8 SDK installed, you can build the solution using the standard `dotnet build` command.
* With .NET 9 SDK installed, you can build the solution using the standard `dotnet build` command.


# Status
Expand Down
14 changes: 14 additions & 0 deletions docs/.todo.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Things TODO

* Dynamic provider loading
* Option to specify provider through configuration and/or command line
* Providers should have own startup/registration
* Add Hyperbee.Migration.Providers.Mongodb
* Mongo bootstrapper
* Mongo distributed lock
* Mongo resource runner and basic statements.json parser
* Relocate shared functionality for providers
* WaitHelper
* Provider samples
* Rename Hyperbee.Migrations.Samples to Hyperbee.Migrations.Samples.Couchbase
* Create Hyperbee.Migrations.Samples.Mongodb
26 changes: 26 additions & 0 deletions docs/_config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
title: Hyperbee Migrations
description: Documentation for Hyperbee Migrations.
remote_theme: pmarsceill/just-the-docs
baseurl: "/hyperbee.migrations/"
url: "https://stillpoint-software.github.io"

aux_links:
"GitHub Repository":
- "//github.com/Stillpoint-Software/hyperbee.migrations"

footer_content: |
<div>
<span>&copy; <span id="copyright-year"></span> <a href='https://www.stillpointsoftware.net/'>Stillpoint Software</a>.</span>
<script>
document.getElementById("copyright-year").textContent = new Date().getFullYear();
</script>
</div>
# logo: "/assets/icon.png"
search_enabled: true # Enable search

# External navigation links
nav_external_links:
- title: Stillpoint Software
url: https://www.stillpointsoftware.net/
opens_in_new_tab: true
3 changes: 3 additions & 0 deletions docs/_includes/nav_footer_custom.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<footer class="site-footer">
Hyperbee Migration Docs
</footer>
228 changes: 228 additions & 0 deletions docs/couchbase.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,228 @@
---
layout: default
title: Migrations Couchbase Provider
nav_order: 2
---

# Hyperbee Migrations Couchbase Provider

Welcome to `Hyperbee.Migrations.Providers.Couchbase`, an extension to the foundational `Hyperbee.Migrations` library. This extension is specifically designed to incorporate support for Couchbase.

## Introduction

The `Hyperbee.Migrations.Providers.Couchbase` library is an tool for developers seeking to perform database migrations in a Couchbase environment using the `Hyperbee.Migrations` library. This library furnishes a comprehensive suite of tools and functionalities that integrate effortlessly with `Hyperbee.Migrations`, thereby enabling developers to harness the robust capabilities of Couchbase in their applications.

The `Hyperbee.Migrations.Providers.Couchbase` library is equipped to assist developers in creating, updating, and managing their Couchbase databases. With the aid of this library, developers can concentrate their efforts on the development of their application, while the library handles the intricacies of database management.

We are committed to continuous improvement and feature enhancement. We appreciate your interest and look forward to your valuable feedback.

Please see [Hyperbee Migrations' Read Me](index.md) for non-database specific usage.


## Concepts

Every migration has several elements you need to be aware of.

* You can create a StartMethod method that resolves to **Task \<bool>**, in order to tell the runner when to start.
* You can create a StopMethod method that resolves to **Task \<bool>**, in order to tell the runner when to stop.
* You can set whether or not you want to journal the migration.

## Configuration

### Add Couchbase Services
```c#
// In Startup.cs
public void ConfigureServices(IServiceCollection services)
{
// Configure MongoDB
services.AddCouchbase();

// Add the MigrationRunner
services.AddCouchbaseMigrations(...);
}

public void Configure(IApplicationBuilder app, ...)
{
// Run pending migrations.
var migrationService = app.ApplicationServices.GetRequiredService<MigrationRunner>();
migrationService.Run();
}
```
### Preventing simultaneous migrations

By default, Hyperbee Migrations prevents parallel migration runner execution. If you have 2 instances of your
app running, and both try to run migrations, Hyperbee Migrations will prevent the second instance from running
migrations and will log a warning.

Hyperbee Migrations accomplishes this by using a distributed lock at the database layer. The default
implementation is based on the provider and uses a timeout and an auto-renewal interval to prevent orphaned locks.

If you want to change this behavior you can override the default options:

```c#
services.AddCouchbaseMigrations( options =>
{
// Locking is on by default. Set to false to allow simultaneous runners - but don't be that guy.
options.LockingEnabled = false;

// You can change locking behavior. Defaults shown.
options.LockMaxLifetime = TimeSpan.FromHours( 1 ); // max time-to-live
options.LockExpireInterval = TimeSpan.FromMinutes( 5 ); // expire heartbeat
options.LockRenewInterval = TimeSpan.FromMinutes( 2 ); // renewal heartbeat
});
```

### Migrations
Hyperbee Migrations relies on dependency injection to pass services to your migration.

```c#
[Migration(1)]
public class MyMigration : Migration
{
private IClusterProvider _clusterProvider;
private ILogger _logger;

// Injected services registered with the container
public MyMigration( IClusterProvider clusterProvider, ILogger<MyMigration> logger )
{
_clusterProvider = clusterProvider;
_logger = logger;
}

public async override Task UpAsync( CancellationToken cancellationToken = default )
{
// do something with clusterProvider
}
}
```

### Dependency Injection

The MongoDB provider also provides a `MongoDBResourceRunner<MyMigration>` that adds helpful functionality when using embedded resources.
- `StatementsFromAsync` run SQL++ (N1QL) statements for different bucket/scope/collections within Couchbase.
- `DocumentsFromAsync` Upserts documents into Couchbase. This is normally use for pre-seeding.
- `StartMethod` determines when the migration should start (optional)
- `StopMethod` determines when the migration should stop (optional)
- `false` determines if you want to journal (default = true)

```c#
[Migration(1, "StartMethod", "StopMethod", false)]
public class MyMigration : Migration
{
private readonly CouchbaseResourceRunner<MyMigration> _resourceRunner;

public CreateInitialBuckets( CouchbaseResourceRunner<MyMigration> resourceRunner )
{
_resourceRunner = resourceRunner;
}

public override async Task UpAsync( CancellationToken cancellationToken = default )
{
// run a `resource` migration to create initial buckets and state.
// resource migrations are atypical; prefer `n1ql` migrations.
await _resourceRunner.StatementsFromAsync( new[]
{
"statements.json",
"migrationbucket/statements.json"
},
cancellationToken
);

await _resourceRunner.DocumentsFromAsync( new[]
{
"migrationbucket/_default"
},
cancellationToken
);
}

public Task<bool> StartMethod()
{
//create process here
}

public Task<bool> StopMethod()
{
//create process here
}
}
```

### Profiles

There are times when you may want to scope migrations to specific environments. To allow this Hyperbee Migrations
supports profiles. For instance, some migrations might only run during development. By decorating your migration
with the profile of _"development"_ and setting **options** to include only that profile, you can control which
migrations run in which environments.

```c#
[Migration(3, "development")]
public class DevelopmentOnlyMigration : Migration
{
public async override Task UpAsync( CancellationToken cancellationToken = default )
{
// do something nice for local developers
}
}

...

// In Startup.cs
public void ConfigureServices( IServiceCollection services )
{
services.AddCouchbaseMigrations( options =>
{
// Configure to only run development migrations
options.Profiles = new[] { "development" } };
});
}
```

A migration may belong to multiple profiles.

```c#
[Migration(3, "development", "staging")]
public class TargetedMigration : Migration
{
// ...
}
```

### Cron Settings
```c#
[Migration(3, "StartMethod", "StopMethod")]
public class DevelopmentOnlyMigration : Migration
{
public async override Task UpAsync( CancellationToken cancellationToken = default )
{
// do something nice for local developers
}

public async Task<bool> StartMethod()
{
var helper = new MigrationCronHelper();
var results = await helper.CronDelayAsync( "* * * * *" );
return results;
}

public Task<bool> StopMethod()
{
var helper = new MigrationCronHelper();
var results = await helper.CronDelayAsync( "4 * * * *" );
return results;
}
}
```

### Journaling
Journaling is a bool indicator. Null indicates there are no start or stop methods.
```c#
[Migration(3, null, null, false)]
public class DevelopmentOnlyMigration : Migration
{
public async override Task UpAsync( CancellationToken cancellationToken = default )
{
// do something nice for local developers
}
}
23 changes: 23 additions & 0 deletions docs/docs.projitems
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<MSBuildAllProjects Condition="'$(MSBuildVersion)' == '' Or '$(MSBuildVersion)' &lt; '16.0'">$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
<HasSharedItems>true</HasSharedItems>
<SharedGUID>5a1580f9-6806-401e-9cab-ac876db070fd</SharedGUID>
</PropertyGroup>
<PropertyGroup Label="Configuration">
<Import_RootNamespace>docs</Import_RootNamespace>
</PropertyGroup>
<ItemGroup>
<None Include="$(MSBuildThisFileDirectory).todo.md" />
<None Include="$(MSBuildThisFileDirectory)couchbase.md" />
<None Include="$(MSBuildThisFileDirectory)index.md" />
<None Include="$(MSBuildThisFileDirectory)migration-runner.md" />
<None Include="$(MSBuildThisFileDirectory)postgresql.md" />
<None Include="$(MSBuildThisFileDirectory)mongodb.md" />
<None Include="$(MSBuildThisFileDirectory)_config.yml" />
</ItemGroup>
<ItemGroup>
<Content Include="$(MSBuildThisFileDirectory)_includes\nav_footer_custom.html" />
</ItemGroup>
</Project>
13 changes: 13 additions & 0 deletions docs/docs.shproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Label="Globals">
<ProjectGuid>5a1580f9-6806-401e-9cab-ac876db070fd</ProjectGuid>
<MinimumVisualStudioVersion>14.0</MinimumVisualStudioVersion>
</PropertyGroup>
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.Default.props" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.props" />
<PropertyGroup />
<Import Project="docs.projitems" Label="Shared" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.CSharp.targets" />
</Project>
Loading

0 comments on commit c4a1b53

Please sign in to comment.