Initial commit carried over from private repo. This is V2.
This commit is contained in:
@ -0,0 +1,12 @@
|
||||
using Microsoft.EntityFrameworkCore.Design;
|
||||
|
||||
namespace MessengerApi.Db.Sql.Migrator
|
||||
{
|
||||
public partial class DesignTimeDbContextFactory : IDesignTimeDbContextFactory<MessengerSqlDbContext>
|
||||
{
|
||||
public MessengerSqlDbContext CreateDbContext(string[] args)
|
||||
{
|
||||
return new MessengerSqlDbContext(this.ConnectionString);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,22 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.6" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.6">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\MessengerApi.Db.Sql\MessengerApi.Db.Sql.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
16
code/MessengerApi.Db.Sql.Migrator/Program.cs
Normal file
16
code/MessengerApi.Db.Sql.Migrator/Program.cs
Normal file
@ -0,0 +1,16 @@
|
||||
namespace MessengerApi.Db.Sql.Migrator
|
||||
{
|
||||
internal class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
// You can use empty string to build the context when adding a migration - adding a migration does not hit the DB.
|
||||
|
||||
// DesignTimeDbFactory.ConnectionString.cs is not versioned on purposed. Add missing property file for this partial class and then run this command:
|
||||
// Add-Migration YourMigration -Project MessengerApi.Db.Sql -StartupProject MessengerApi.Db.Sql.Migrator -Verbose -Context MessengerSqlDbContext
|
||||
|
||||
// To update the database, make sure your connection string is correct and run this command:
|
||||
// Update-Database -Project MessengerApi.Db.Sql -StartupProject MessengerApi.Db.Sql.Migrator -Verbose -Context MessengerSqlDbContext
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user