-
-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #102 from Nfactor26/mongo-migrations
Added project to migrate mongo db to v3 from v2
- Loading branch information
Showing
4 changed files
with
85 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
22 changes: 22 additions & 0 deletions
22
src/Pixel.Identity.Store.Mongo.Migrations/Pixel.Identity.Store.Mongo.Migrations.csproj
This file contains 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 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" /> | ||
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="8.0.0" /> | ||
<PackageReference Include="MongoDB.Driver" Version="2.23.1" /> | ||
<PackageReference Include="OpenIddict.Abstractions" Version="5.0.1" /> | ||
<PackageReference Include="OpenIddict.MongoDb" Version="5.0.1" /> | ||
<PackageReference Include="OpenIddict.MongoDb.Models" Version="5.0.1" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Update="appsettings.json"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</None> | ||
</ItemGroup> | ||
</Project> |
This file contains 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,41 @@ | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Hosting; | ||
using Microsoft.Extensions.Options; | ||
using MongoDB.Bson; | ||
using MongoDB.Driver; | ||
using OpenIddict.MongoDb; | ||
|
||
|
||
using IHost host = Host.CreateDefaultBuilder(args).Build(); | ||
var switchMappings = new Dictionary<string, string>() | ||
{ | ||
{ "--mongo-host", "mongo-host" }, | ||
{ "--mongo-db", "mongo-db" } }; | ||
|
||
IConfiguration config = new ConfigurationBuilder() | ||
.AddCommandLine(args, switchMappings) | ||
.AddJsonFile("appsettings.json", true, false) | ||
.AddEnvironmentVariables() | ||
.Build(); | ||
|
||
string mongoServer = config.GetValue<string>("mongo-host") ?? throw new Exception("mongo-host is required"); | ||
string mongoDb = config.GetValue<string>("mongo-db") ?? throw new Exception("mongo-db is required"); | ||
|
||
var services = new ServiceCollection(); | ||
services.AddOpenIddict() | ||
.AddCore() | ||
.UseMongoDb() | ||
.UseDatabase(new MongoClient(mongoServer).GetDatabase(mongoDb)); | ||
|
||
await using var provider = services.BuildServiceProvider(); | ||
var context = provider.GetRequiredService<IOpenIddictMongoDbContext>(); | ||
var options = provider.GetRequiredService<IOptionsMonitor<OpenIddictMongoDbOptions>>().CurrentValue; | ||
var database = await context.GetDatabaseAsync(CancellationToken.None); | ||
|
||
var applications = database.GetCollection<BsonDocument>(options.ApplicationsCollectionName); | ||
await applications.UpdateManyAsync( | ||
filter: Builders<BsonDocument>.Filter.Empty, | ||
update: Builders<BsonDocument>.Update.Rename("type", "client_type")); | ||
|
||
Console.WriteLine("Completed !!"); |
This file contains 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,4 @@ | ||
{ | ||
"mongo-host": "mongodb://localhost:27017", | ||
"mongo-db": "pixel-identity-db-test" | ||
} |