-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added runtime migration for ef core (#58)
* Added runtime migration for ef core * mostly copied from warfabrik clone, but also with some fixed and new features, so that the default ids for migrations work and the database context can be configured better * added name of configurators so that one can have seperated logic for the different configurators * made it possible to load multiple configurators, so that one could have multiple databases for different use cases in one program
- Loading branch information
Showing
26 changed files
with
799 additions
and
0 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
...ameworkExtension/NonSucking.Framework.Extension.Database.InMemory/InMemoryConfigurator.cs
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,28 @@ | ||
| ||
using NonSucking.Framework.Extension.EntityFrameworkCore; | ||
using NonSucking.Framework.Extension.EntityFrameworkCore.Migrations; | ||
using Microsoft.EntityFrameworkCore; | ||
|
||
namespace NonSucking.Framework.Extension.Database.InMemory; | ||
public class InMemoryConfigurator : IDatabaseConfigurator | ||
{ | ||
public string Name => "InMemory"; | ||
public class MigrationContext : MigrationDatabaseContext | ||
{ | ||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) | ||
{ | ||
_ = optionsBuilder.UseInMemoryDatabase("Empty"); | ||
base.OnConfiguring(optionsBuilder); | ||
} | ||
} | ||
|
||
public IAutoMigrationContextBuilder GetEmptyForMigration() | ||
{ | ||
return new MigrationContext(); | ||
} | ||
|
||
public DbContextOptionsBuilder OnConfiguring(DbContextOptionsBuilder optionsBuilder, string connectionString) | ||
{ | ||
return optionsBuilder.UseInMemoryDatabase(connectionString); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
...ework.Extension.Database.InMemory/NonSucking.Framework.Extension.Database.InMemory.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,21 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net7.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="7.0.8" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\..\NonSucking.Framework.Extension.EntityFrameworkCore\NonSucking.Framework.Extension.EntityFrameworkCore.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<None Include="..\..\LICENSE"> | ||
<Pack>True</Pack> | ||
<PackagePath></PackagePath> | ||
</None> | ||
</ItemGroup> | ||
</Project> |
23 changes: 23 additions & 0 deletions
23
...tension.Database.InMemory/NonSucking.Framework.Extension.Database.InMemory.props.template
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,23 @@ | ||
<Project> | ||
<PropertyGroup> | ||
<Version>${VERSION_FULL}</Version> | ||
<AssemblyVersion>${VERSION_LONG}</AssemblyVersion> | ||
<Authors>${AUTHORS}</Authors> | ||
<Copyright>${COPYRIGHT}</Copyright> | ||
<Company>${COMPANY}</Company> | ||
<Title>${TITLE_INMEMORY}</Title> | ||
<Description>${DESCRIPTION_INMEMORY}</Description> | ||
<PackageReleaseNotes> | ||
This is a first preview version and not intended for productive use. Not everything has been tested or commented yet. | ||
</PackageReleaseNotes> | ||
<PackageTags> | ||
${TAGS_INMEMORY} | ||
</PackageTags> | ||
<!-- <PackageIconUrl>${ICON_URL}</PackageIconUrl> --> | ||
<RepositoryUrl>${REPO_URL}</RepositoryUrl> | ||
<PackageProjectUrl>$(RepositoryUrl)</PackageProjectUrl> | ||
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance> | ||
<PackageLicenseFile>LICENSE</PackageLicenseFile> | ||
<NeutralLanguage>en-US</NeutralLanguage> | ||
</PropertyGroup> | ||
</Project> |
29 changes: 29 additions & 0 deletions
29
EntityFrameworkExtension/NonSucking.Framework.Extension.Database.MSSQL/MSSQLConfigurator.cs
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,29 @@ | ||
| ||
using NonSucking.Framework.Extension.EntityFrameworkCore; | ||
using NonSucking.Framework.Extension.EntityFrameworkCore.Migrations; | ||
using Microsoft.EntityFrameworkCore; | ||
|
||
namespace NonSucking.Framework.Extension.Database.MSSQL; | ||
public class MSSQLConfigurator : IDatabaseConfigurator | ||
{ | ||
public string Name => "MSSQL"; | ||
public class MigrationContext : MigrationDatabaseContext | ||
{ | ||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) | ||
{ | ||
_ = optionsBuilder.UseSqlServer(); | ||
base.OnConfiguring(optionsBuilder); | ||
} | ||
|
||
} | ||
|
||
public IAutoMigrationContextBuilder GetEmptyForMigration() | ||
{ | ||
return new MigrationContext(); | ||
} | ||
|
||
public DbContextOptionsBuilder OnConfiguring(DbContextOptionsBuilder optionsBuilder, string connectionString) | ||
{ | ||
return optionsBuilder.UseSqlServer(connectionString); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
...g.Framework.Extension.Database.MSSQL/NonSucking.Framework.Extension.Database.MSSQL.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,21 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net7.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.8" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\..\NonSucking.Framework.Extension.EntityFrameworkCore\NonSucking.Framework.Extension.EntityFrameworkCore.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<None Include="..\..\LICENSE"> | ||
<Pack>True</Pack> | ||
<PackagePath></PackagePath> | ||
</None> | ||
</ItemGroup> | ||
</Project> |
23 changes: 23 additions & 0 deletions
23
...ork.Extension.Database.MSSQL/NonSucking.Framework.Extension.Database.MSSQL.props.template
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,23 @@ | ||
<Project> | ||
<PropertyGroup> | ||
<Version>${VERSION_FULL}</Version> | ||
<AssemblyVersion>${VERSION_LONG}</AssemblyVersion> | ||
<Authors>${AUTHORS}</Authors> | ||
<Copyright>${COPYRIGHT}</Copyright> | ||
<Company>${COMPANY}</Company> | ||
<Title>${TITLE_MSSQL}</Title> | ||
<Description>${DESCRIPTION_MSSQL}</Description> | ||
<PackageReleaseNotes> | ||
This is a first preview version and not intended for productive use. Not everything has been tested or commented yet. | ||
</PackageReleaseNotes> | ||
<PackageTags> | ||
${TAGS_MSSQL} | ||
</PackageTags> | ||
<!-- <PackageIconUrl>${ICON_URL}</PackageIconUrl> --> | ||
<RepositoryUrl>${REPO_URL}</RepositoryUrl> | ||
<PackageProjectUrl>$(RepositoryUrl)</PackageProjectUrl> | ||
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance> | ||
<PackageLicenseFile>LICENSE</PackageLicenseFile> | ||
<NeutralLanguage>en-US</NeutralLanguage> | ||
</PropertyGroup> | ||
</Project> |
30 changes: 30 additions & 0 deletions
30
EntityFrameworkExtension/NonSucking.Framework.Extension.Database.MySql/MySQLConfigurator.cs
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,30 @@ | ||
| ||
using NonSucking.Framework.Extension.EntityFrameworkCore; | ||
using NonSucking.Framework.Extension.EntityFrameworkCore.Migrations; | ||
using Microsoft.EntityFrameworkCore; | ||
|
||
namespace NonSucking.Framework.Extension.Database.MySql; | ||
public class MySQLConfigurator : IDatabaseConfigurator | ||
{ | ||
public string Name => "MySQL"; | ||
public class MigrationContext : MigrationDatabaseContext | ||
{ | ||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) | ||
{ | ||
_ = optionsBuilder.UseMySql("server=none;userid=none;password=none;database=none", ServerVersion.Create(10, 9, 3, Pomelo.EntityFrameworkCore.MySql.Infrastructure.ServerType.MariaDb)); | ||
base.OnConfiguring(optionsBuilder); | ||
} | ||
|
||
} | ||
|
||
public IAutoMigrationContextBuilder GetEmptyForMigration() | ||
{ | ||
return new MigrationContext(); | ||
} | ||
|
||
public DbContextOptionsBuilder OnConfiguring(DbContextOptionsBuilder optionsBuilder, string connectionString) | ||
{ | ||
return optionsBuilder.UseMySql(connectionString, ServerVersion.AutoDetect(connectionString)); | ||
} | ||
} | ||
|
22 changes: 22 additions & 0 deletions
22
...g.Framework.Extension.Database.MySql/NonSucking.Framework.Extension.Database.MySql.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> | ||
<TargetFramework>net7.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="7.0.0" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\..\NonSucking.Framework.Extension.EntityFrameworkCore\NonSucking.Framework.Extension.EntityFrameworkCore.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<None Include="..\..\LICENSE"> | ||
<Pack>True</Pack> | ||
<PackagePath></PackagePath> | ||
</None> | ||
</ItemGroup> | ||
</Project> |
23 changes: 23 additions & 0 deletions
23
...ork.Extension.Database.MySql/NonSucking.Framework.Extension.Database.MySql.props.template
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,23 @@ | ||
<Project> | ||
<PropertyGroup> | ||
<Version>${VERSION_FULL}</Version> | ||
<AssemblyVersion>${VERSION_LONG}</AssemblyVersion> | ||
<Authors>${AUTHORS}</Authors> | ||
<Copyright>${COPYRIGHT}</Copyright> | ||
<Company>${COMPANY}</Company> | ||
<Title>${TITLE_MYSQL}</Title> | ||
<Description>${DESCRIPTION_MYSQL}</Description> | ||
<PackageReleaseNotes> | ||
This is a first preview version and not intended for productive use. Not everything has been tested or commented yet. | ||
</PackageReleaseNotes> | ||
<PackageTags> | ||
${TAGS_MYSQL} | ||
</PackageTags> | ||
<!-- <PackageIconUrl>${ICON_URL}</PackageIconUrl> --> | ||
<RepositoryUrl>${REPO_URL}</RepositoryUrl> | ||
<PackageProjectUrl>$(RepositoryUrl)</PackageProjectUrl> | ||
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance> | ||
<PackageLicenseFile>LICENSE</PackageLicenseFile> | ||
<NeutralLanguage>en-US</NeutralLanguage> | ||
</PropertyGroup> | ||
</Project> |
23 changes: 23 additions & 0 deletions
23
...ion.Database.PostrgeSQL/NonSucking.Framework.Extension.Database.PostgreSQL.props.template
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,23 @@ | ||
<Project> | ||
<PropertyGroup> | ||
<Version>${VERSION_FULL}</Version> | ||
<AssemblyVersion>${VERSION_LONG}</AssemblyVersion> | ||
<Authors>${AUTHORS}</Authors> | ||
<Copyright>${COPYRIGHT}</Copyright> | ||
<Company>${COMPANY}</Company> | ||
<Title>${TITLE_POSTGRESQL}</Title> | ||
<Description>${DESCRIPTION_POSTGRESQL}</Description> | ||
<PackageReleaseNotes> | ||
This is a first preview version and not intended for productive use. Not everything has been tested or commented yet. | ||
</PackageReleaseNotes> | ||
<PackageTags> | ||
${TAGS_POSTGRESQL} | ||
</PackageTags> | ||
<!-- <PackageIconUrl>${ICON_URL}</PackageIconUrl> --> | ||
<RepositoryUrl>${REPO_URL}</RepositoryUrl> | ||
<PackageProjectUrl>$(RepositoryUrl)</PackageProjectUrl> | ||
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance> | ||
<PackageLicenseFile>LICENSE</PackageLicenseFile> | ||
<NeutralLanguage>en-US</NeutralLanguage> | ||
</PropertyGroup> | ||
</Project> |
23 changes: 23 additions & 0 deletions
23
...k.Extension.Database.PostrgeSQL/NonSucking.Framework.Extension.Database.PostrgeSQL.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,23 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net7.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="7.0.4" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\NonSucking.Framework.Extension.EntityFrameworkCore\NonSucking.Framework.Extension.EntityFrameworkCore.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<None Include="..\..\LICENSE"> | ||
<Pack>True</Pack> | ||
<PackagePath></PackagePath> | ||
</None> | ||
</ItemGroup> | ||
</Project> |
28 changes: 28 additions & 0 deletions
28
...eworkExtension/NonSucking.Framework.Extension.Database.PostrgeSQL/PostgresConfigurator.cs
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,28 @@ | ||
| ||
using NonSucking.Framework.Extension.EntityFrameworkCore; | ||
using NonSucking.Framework.Extension.EntityFrameworkCore.Migrations; | ||
using Microsoft.EntityFrameworkCore; | ||
|
||
namespace NonSucking.Framework.Extension.Database.PostrgeSQL; | ||
public class PostgresConfigurator : IDatabaseConfigurator | ||
{ | ||
public string Name => "PostrgeSQL"; | ||
public class MigrationContext : MigrationDatabaseContext | ||
{ | ||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) | ||
{ | ||
_ = optionsBuilder.UseNpgsql(); | ||
base.OnConfiguring(optionsBuilder); | ||
} | ||
|
||
} | ||
|
||
public IAutoMigrationContextBuilder GetEmptyForMigration() | ||
{ | ||
return new MigrationContext(); | ||
} | ||
public DbContextOptionsBuilder OnConfiguring(DbContextOptionsBuilder optionsBuilder, string connectionString) | ||
{ | ||
return optionsBuilder.UseNpgsql(connectionString); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
...Framework.Extension.Database.Sqlite/NonSucking.Framework.Extension.Database.Sqlite.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,21 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net7.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="7.0.8" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\..\NonSucking.Framework.Extension.EntityFrameworkCore\NonSucking.Framework.Extension.EntityFrameworkCore.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<None Include="..\..\LICENSE"> | ||
<Pack>True</Pack> | ||
<PackagePath></PackagePath> | ||
</None> | ||
</ItemGroup> | ||
</Project> |
23 changes: 23 additions & 0 deletions
23
...k.Extension.Database.Sqlite/NonSucking.Framework.Extension.Database.Sqlite.props.template
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,23 @@ | ||
<Project> | ||
<PropertyGroup> | ||
<Version>${VERSION_FULL}</Version> | ||
<AssemblyVersion>${VERSION_LONG}</AssemblyVersion> | ||
<Authors>${AUTHORS}</Authors> | ||
<Copyright>${COPYRIGHT}</Copyright> | ||
<Company>${COMPANY}</Company> | ||
<Title>${TITLE_SQLITE}</Title> | ||
<Description>${DESCRIPTION_SQLITE}</Description> | ||
<PackageReleaseNotes> | ||
This is a first preview version and not intended for productive use. Not everything has been tested or commented yet. | ||
</PackageReleaseNotes> | ||
<PackageTags> | ||
${TAGS_SQLITE} | ||
</PackageTags> | ||
<!-- <PackageIconUrl>${ICON_URL}</PackageIconUrl> --> | ||
<RepositoryUrl>${REPO_URL}</RepositoryUrl> | ||
<PackageProjectUrl>$(RepositoryUrl)</PackageProjectUrl> | ||
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance> | ||
<PackageLicenseFile>LICENSE</PackageLicenseFile> | ||
<NeutralLanguage>en-US</NeutralLanguage> | ||
</PropertyGroup> | ||
</Project> |
30 changes: 30 additions & 0 deletions
30
...tyFrameworkExtension/NonSucking.Framework.Extension.Database.Sqlite/SqLiteConfigurator.cs
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,30 @@ | ||
| ||
using Microsoft.EntityFrameworkCore; | ||
|
||
using NonSucking.Framework.Extension.EntityFrameworkCore; | ||
using NonSucking.Framework.Extension.EntityFrameworkCore.Migrations; | ||
|
||
namespace NonSucking.Framework.Extension.Database.Sqlite; | ||
public class SqLiteConfigurator : IDatabaseConfigurator | ||
{ | ||
public string Name => "SQLite"; | ||
|
||
public class MigrationContext : MigrationDatabaseContext | ||
{ | ||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) | ||
{ | ||
_ = optionsBuilder.UseSqlite(); | ||
base.OnConfiguring(optionsBuilder); | ||
} | ||
|
||
} | ||
|
||
public IAutoMigrationContextBuilder GetEmptyForMigration() | ||
{ | ||
return new MigrationContext(); | ||
} | ||
public DbContextOptionsBuilder OnConfiguring(DbContextOptionsBuilder optionsBuilder, string connectionString) | ||
{ | ||
return optionsBuilder.UseSqlite(connectionString); | ||
} | ||
} |
Oops, something went wrong.