Skip to content

Commit c4a1b53

Browse files
updated to .net 9, added doc pages, update workflows
1 parent 9cd22d2 commit c4a1b53

File tree

31 files changed

+1062
-29
lines changed

31 files changed

+1062
-29
lines changed

.github/workflows/format.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ on:
1515
- develop
1616

1717
env:
18-
DOTNET_VERSION: '8.0.x'
18+
DOTNET_VERSION: '9.0.x'
1919

2020
jobs:
2121
format:

.github/workflows/publish.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ on:
88
env:
99
BRANCH_NAME: ${{ github.event.release.target_commitish }}
1010
SOLUTION_NAME: ${{ vars.SOLUTION_NAME }}
11-
DOTNET_VERSION: '8.0.x'
11+
DOTNET_VERSION: '9.0.x'
1212
NUGET_SOURCE: 'https://api.nuget.org/v3/index.json'
1313
BUILD_CONFIGURATION: ''
1414
VERSION_SUFFIX: ''

.github/workflows/test.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ on:
1717
env:
1818
BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
1919
SOLUTION_NAME: ${{ vars.SOLUTION_NAME }}
20-
DOTNET_VERSION: '8.0.x'
20+
DOTNET_VERSION: '9.0.x'
2121

2222
jobs:
2323
test:

Deploy GitHub Pages.yml

Whitespace-only changes.

Hyperbee.Migrations.sln

+7-5
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,11 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "workflows", "workflows", "{
5454
.github\workflows\publish.yml = .github\workflows\publish.yml
5555
.github\workflows\test-report.yml = .github\workflows\test-report.yml
5656
.github\workflows\test.yml = .github\workflows\test.yml
57+
unlist-nuget.yml = unlist-nuget.yml
58+
update-version.yml = update-version.yml
5759
EndProjectSection
5860
EndProject
59-
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "docs", "docs", "{FAE7F244-124F-4BCB-8EA6-049BEE4991B9}"
60-
ProjectSection(SolutionItems) = preProject
61-
todo.md = todo.md
62-
EndProjectSection
61+
Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "docs", "docs\docs.shproj", "{5A1580F9-6806-401E-9CAB-AC876DB070FD}"
6362
EndProject
6463
Global
6564
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -130,9 +129,12 @@ Global
130129
{C4B50B74-3FCA-453E-AF19-D9EA9233F8FC} = {17F0B438-3EBD-4566-9A22-7A5EC4AEAF3D}
131130
{004E4E55-FA1C-49D0-865F-4FF238C7A1F3} = {5A09B7FE-D694-45B5-BCBC-256A8E06CFC5}
132131
{A192B3D2-E452-4A85-BBA4-1A8499F1A056} = {004E4E55-FA1C-49D0-865F-4FF238C7A1F3}
133-
{FAE7F244-124F-4BCB-8EA6-049BEE4991B9} = {5A09B7FE-D694-45B5-BCBC-256A8E06CFC5}
132+
{5A1580F9-6806-401E-9CAB-AC876DB070FD} = {5A09B7FE-D694-45B5-BCBC-256A8E06CFC5}
134133
EndGlobalSection
135134
GlobalSection(ExtensibilityGlobals) = postSolution
136135
SolutionGuid = {97071D77-035B-4126-AD4E-DE150E318714}
137136
EndGlobalSection
137+
GlobalSection(SharedMSBuildProjectFiles) = preSolution
138+
docs\docs.projitems*{5a1580f9-6806-401e-9cab-ac876db070fd}*SharedItemsImports = 13
139+
EndGlobalSection
138140
EndGlobal

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,12 @@ public class PeopleHaveFullNames : Migration // #2 inherit from Migration
5555

5656
# Build Requirements
5757

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

6161
## Building the Solution
6262

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

6565

6666
# Status

docs/.todo.md

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Things TODO
2+
3+
* Dynamic provider loading
4+
* Option to specify provider through configuration and/or command line
5+
* Providers should have own startup/registration
6+
* Add Hyperbee.Migration.Providers.Mongodb
7+
* Mongo bootstrapper
8+
* Mongo distributed lock
9+
* Mongo resource runner and basic statements.json parser
10+
* Relocate shared functionality for providers
11+
* WaitHelper
12+
* Provider samples
13+
* Rename Hyperbee.Migrations.Samples to Hyperbee.Migrations.Samples.Couchbase
14+
* Create Hyperbee.Migrations.Samples.Mongodb

docs/_config.yml

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
title: Hyperbee Migrations
2+
description: Documentation for Hyperbee Migrations.
3+
remote_theme: pmarsceill/just-the-docs
4+
baseurl: "/hyperbee.migrations/"
5+
url: "https://stillpoint-software.github.io"
6+
7+
aux_links:
8+
"GitHub Repository":
9+
- "//github.com/Stillpoint-Software/hyperbee.migrations"
10+
11+
footer_content: |
12+
<div>
13+
<span>&copy; <span id="copyright-year"></span> <a href='https://www.stillpointsoftware.net/'>Stillpoint Software</a>.</span>
14+
<script>
15+
document.getElementById("copyright-year").textContent = new Date().getFullYear();
16+
</script>
17+
</div>
18+
19+
# logo: "/assets/icon.png"
20+
search_enabled: true # Enable search
21+
22+
# External navigation links
23+
nav_external_links:
24+
- title: Stillpoint Software
25+
url: https://www.stillpointsoftware.net/
26+
opens_in_new_tab: true

docs/_includes/nav_footer_custom.html

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<footer class="site-footer">
2+
Hyperbee Migration Docs
3+
</footer>

docs/couchbase.md

+228
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,228 @@
1+
---
2+
layout: default
3+
title: Migrations Couchbase Provider
4+
nav_order: 2
5+
---
6+
7+
# Hyperbee Migrations Couchbase Provider
8+
9+
Welcome to `Hyperbee.Migrations.Providers.Couchbase`, an extension to the foundational `Hyperbee.Migrations` library. This extension is specifically designed to incorporate support for Couchbase.
10+
11+
## Introduction
12+
13+
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.
14+
15+
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.
16+
17+
We are committed to continuous improvement and feature enhancement. We appreciate your interest and look forward to your valuable feedback.
18+
19+
Please see [Hyperbee Migrations' Read Me](index.md) for non-database specific usage.
20+
21+
22+
## Concepts
23+
24+
Every migration has several elements you need to be aware of.
25+
26+
* You can create a StartMethod method that resolves to **Task \<bool>**, in order to tell the runner when to start.
27+
* You can create a StopMethod method that resolves to **Task \<bool>**, in order to tell the runner when to stop.
28+
* You can set whether or not you want to journal the migration.
29+
30+
## Configuration
31+
32+
### Add Couchbase Services
33+
```c#
34+
// In Startup.cs
35+
public void ConfigureServices(IServiceCollection services)
36+
{
37+
// Configure MongoDB
38+
services.AddCouchbase();
39+
40+
// Add the MigrationRunner
41+
services.AddCouchbaseMigrations(...);
42+
}
43+
44+
public void Configure(IApplicationBuilder app, ...)
45+
{
46+
// Run pending migrations.
47+
var migrationService = app.ApplicationServices.GetRequiredService<MigrationRunner>();
48+
migrationService.Run();
49+
}
50+
```
51+
### Preventing simultaneous migrations
52+
53+
By default, Hyperbee Migrations prevents parallel migration runner execution. If you have 2 instances of your
54+
app running, and both try to run migrations, Hyperbee Migrations will prevent the second instance from running
55+
migrations and will log a warning.
56+
57+
Hyperbee Migrations accomplishes this by using a distributed lock at the database layer. The default
58+
implementation is based on the provider and uses a timeout and an auto-renewal interval to prevent orphaned locks.
59+
60+
If you want to change this behavior you can override the default options:
61+
62+
```c#
63+
services.AddCouchbaseMigrations( options =>
64+
{
65+
// Locking is on by default. Set to false to allow simultaneous runners - but don't be that guy.
66+
options.LockingEnabled = false;
67+
68+
// You can change locking behavior. Defaults shown.
69+
options.LockMaxLifetime = TimeSpan.FromHours( 1 ); // max time-to-live
70+
options.LockExpireInterval = TimeSpan.FromMinutes( 5 ); // expire heartbeat
71+
options.LockRenewInterval = TimeSpan.FromMinutes( 2 ); // renewal heartbeat
72+
});
73+
```
74+
75+
### Migrations
76+
Hyperbee Migrations relies on dependency injection to pass services to your migration.
77+
78+
```c#
79+
[Migration(1)]
80+
public class MyMigration : Migration
81+
{
82+
private IClusterProvider _clusterProvider;
83+
private ILogger _logger;
84+
85+
// Injected services registered with the container
86+
public MyMigration( IClusterProvider clusterProvider, ILogger<MyMigration> logger )
87+
{
88+
_clusterProvider = clusterProvider;
89+
_logger = logger;
90+
}
91+
92+
public async override Task UpAsync( CancellationToken cancellationToken = default )
93+
{
94+
// do something with clusterProvider
95+
}
96+
}
97+
```
98+
99+
### Dependency Injection
100+
101+
The MongoDB provider also provides a `MongoDBResourceRunner<MyMigration>` that adds helpful functionality when using embedded resources.
102+
- `StatementsFromAsync` run SQL++ (N1QL) statements for different bucket/scope/collections within Couchbase.
103+
- `DocumentsFromAsync` Upserts documents into Couchbase. This is normally use for pre-seeding.
104+
- `StartMethod` determines when the migration should start (optional)
105+
- `StopMethod` determines when the migration should stop (optional)
106+
- `false` determines if you want to journal (default = true)
107+
108+
```c#
109+
[Migration(1, "StartMethod", "StopMethod", false)]
110+
public class MyMigration : Migration
111+
{
112+
private readonly CouchbaseResourceRunner<MyMigration> _resourceRunner;
113+
114+
public CreateInitialBuckets( CouchbaseResourceRunner<MyMigration> resourceRunner )
115+
{
116+
_resourceRunner = resourceRunner;
117+
}
118+
119+
public override async Task UpAsync( CancellationToken cancellationToken = default )
120+
{
121+
// run a `resource` migration to create initial buckets and state.
122+
// resource migrations are atypical; prefer `n1ql` migrations.
123+
124+
await _resourceRunner.StatementsFromAsync( new[]
125+
{
126+
"statements.json",
127+
"migrationbucket/statements.json"
128+
},
129+
cancellationToken
130+
);
131+
132+
await _resourceRunner.DocumentsFromAsync( new[]
133+
{
134+
"migrationbucket/_default"
135+
},
136+
cancellationToken
137+
);
138+
}
139+
140+
public Task<bool> StartMethod()
141+
{
142+
//create process here
143+
}
144+
145+
public Task<bool> StopMethod()
146+
{
147+
//create process here
148+
}
149+
}
150+
```
151+
152+
### Profiles
153+
154+
There are times when you may want to scope migrations to specific environments. To allow this Hyperbee Migrations
155+
supports profiles. For instance, some migrations might only run during development. By decorating your migration
156+
with the profile of _"development"_ and setting **options** to include only that profile, you can control which
157+
migrations run in which environments.
158+
159+
```c#
160+
[Migration(3, "development")]
161+
public class DevelopmentOnlyMigration : Migration
162+
{
163+
public async override Task UpAsync( CancellationToken cancellationToken = default )
164+
{
165+
// do something nice for local developers
166+
}
167+
}
168+
169+
...
170+
171+
// In Startup.cs
172+
public void ConfigureServices( IServiceCollection services )
173+
{
174+
services.AddCouchbaseMigrations( options =>
175+
{
176+
// Configure to only run development migrations
177+
options.Profiles = new[] { "development" } };
178+
});
179+
}
180+
```
181+
182+
A migration may belong to multiple profiles.
183+
184+
```c#
185+
[Migration(3, "development", "staging")]
186+
public class TargetedMigration : Migration
187+
{
188+
// ...
189+
}
190+
```
191+
192+
### Cron Settings
193+
```c#
194+
[Migration(3, "StartMethod", "StopMethod")]
195+
public class DevelopmentOnlyMigration : Migration
196+
{
197+
public async override Task UpAsync( CancellationToken cancellationToken = default )
198+
{
199+
// do something nice for local developers
200+
}
201+
202+
public async Task<bool> StartMethod()
203+
{
204+
var helper = new MigrationCronHelper();
205+
var results = await helper.CronDelayAsync( "* * * * *" );
206+
return results;
207+
}
208+
209+
public Task<bool> StopMethod()
210+
{
211+
var helper = new MigrationCronHelper();
212+
var results = await helper.CronDelayAsync( "4 * * * *" );
213+
return results;
214+
}
215+
}
216+
```
217+
218+
### Journaling
219+
Journaling is a bool indicator. Null indicates there are no start or stop methods.
220+
```c#
221+
[Migration(3, null, null, false)]
222+
public class DevelopmentOnlyMigration : Migration
223+
{
224+
public async override Task UpAsync( CancellationToken cancellationToken = default )
225+
{
226+
// do something nice for local developers
227+
}
228+
}

docs/docs.projitems

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<MSBuildAllProjects Condition="'$(MSBuildVersion)' == '' Or '$(MSBuildVersion)' &lt; '16.0'">$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
5+
<HasSharedItems>true</HasSharedItems>
6+
<SharedGUID>5a1580f9-6806-401e-9cab-ac876db070fd</SharedGUID>
7+
</PropertyGroup>
8+
<PropertyGroup Label="Configuration">
9+
<Import_RootNamespace>docs</Import_RootNamespace>
10+
</PropertyGroup>
11+
<ItemGroup>
12+
<None Include="$(MSBuildThisFileDirectory).todo.md" />
13+
<None Include="$(MSBuildThisFileDirectory)couchbase.md" />
14+
<None Include="$(MSBuildThisFileDirectory)index.md" />
15+
<None Include="$(MSBuildThisFileDirectory)migration-runner.md" />
16+
<None Include="$(MSBuildThisFileDirectory)postgresql.md" />
17+
<None Include="$(MSBuildThisFileDirectory)mongodb.md" />
18+
<None Include="$(MSBuildThisFileDirectory)_config.yml" />
19+
</ItemGroup>
20+
<ItemGroup>
21+
<Content Include="$(MSBuildThisFileDirectory)_includes\nav_footer_custom.html" />
22+
</ItemGroup>
23+
</Project>

docs/docs.shproj

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup Label="Globals">
4+
<ProjectGuid>5a1580f9-6806-401e-9cab-ac876db070fd</ProjectGuid>
5+
<MinimumVisualStudioVersion>14.0</MinimumVisualStudioVersion>
6+
</PropertyGroup>
7+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
8+
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.Default.props" />
9+
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.props" />
10+
<PropertyGroup />
11+
<Import Project="docs.projitems" Label="Shared" />
12+
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.CSharp.targets" />
13+
</Project>

0 commit comments

Comments
 (0)