mirror of https://github.com/abpframework/abp.git
8 changed files with 133 additions and 10 deletions
@ -0,0 +1,13 @@ |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using Volo.Abp; |
|||
|
|||
namespace VoloDocs.Migrator |
|||
{ |
|||
public static class AppExtensions |
|||
{ |
|||
public static T Resolve<T>(this IAbpApplicationWithInternalServiceProvider app) |
|||
{ |
|||
return (T)app.ServiceProvider.GetRequiredService<T>(); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,54 @@ |
|||
using System; |
|||
using Microsoft.EntityFrameworkCore; |
|||
using Volo.Abp; |
|||
using VoloDocs.EntityFrameworkCore; |
|||
|
|||
namespace VoloDocs.Migrator |
|||
{ |
|||
class Program |
|||
{ |
|||
static void Main(string[] args) |
|||
{ |
|||
Console.WriteLine("Initializing VoloDocs Migrator ... "); |
|||
|
|||
using (var app = AbpApplicationFactory.Create<VoloDocsMigratorModule>()) |
|||
{ |
|||
app.Initialize(); |
|||
|
|||
using (var dbContext = app.Resolve<VoloDocsDbContext>()) |
|||
{ |
|||
var connectionString = dbContext.Database.GetDbConnection().ConnectionString; |
|||
|
|||
Console.Clear(); |
|||
|
|||
Console.Write("\nThis program updates an existing database or creates a new one if not exists.\n" + |
|||
"The following connection string will be used:\n\n" + |
|||
new string('=', 70) + "\n" + |
|||
connectionString + "\n" + |
|||
new string('=', 70) + "\n\n" + |
|||
"Do you confirm to run the migration? (y/n) "); |
|||
|
|||
if (Console.ReadKey().Key == ConsoleKey.Y) |
|||
{ |
|||
try |
|||
{ |
|||
Console.WriteLine("\nMigrating..."); |
|||
|
|||
dbContext.Database.Migrate(); |
|||
|
|||
Console.WriteLine("\nCompleted."); |
|||
} |
|||
catch (Exception ex) |
|||
{ |
|||
Console.Write("\nAn error occured while migrating the database:\n"); |
|||
Console.Write(ex.ToString()); |
|||
} |
|||
} |
|||
} |
|||
|
|||
Console.WriteLine("Press ENTER to exit..."); |
|||
Console.ReadLine(); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,26 @@ |
|||
<Project Sdk="Microsoft.NET.Sdk"> |
|||
|
|||
<PropertyGroup> |
|||
<OutputType>Exe</OutputType> |
|||
<TargetFramework>netcoreapp2.2</TargetFramework> |
|||
</PropertyGroup> |
|||
|
|||
<ItemGroup> |
|||
<None Remove="appsettings.json" /> |
|||
</ItemGroup> |
|||
|
|||
<ItemGroup> |
|||
<Content Include="appsettings.json"> |
|||
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory> |
|||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> |
|||
</Content> |
|||
</ItemGroup> |
|||
|
|||
|
|||
<ItemGroup> |
|||
<ProjectReference Include="..\..\..\..\framework\src\Volo.Abp.Core\Volo.Abp.Core.csproj" /> |
|||
<ProjectReference Include="..\VoloDocs.EntityFrameworkCore\VoloDocs.EntityFrameworkCore.csproj" /> |
|||
<!--<ProjectReference Include="..\VoloDocs\VoloDocs.csproj" />--> |
|||
</ItemGroup> |
|||
|
|||
</Project> |
|||
@ -0,0 +1,29 @@ |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using Volo.Abp.Data; |
|||
using Volo.Abp.EntityFrameworkCore; |
|||
using Volo.Abp.Modularity; |
|||
using VoloDocs.EntityFrameworkCore; |
|||
|
|||
namespace VoloDocs.Migrator |
|||
{ |
|||
[DependsOn(typeof(VoloDocsEntityFrameworkCoreModule))] |
|||
public class VoloDocsMigratorModule : AbpModule |
|||
{ |
|||
public override void ConfigureServices(ServiceConfigurationContext context) |
|||
{ |
|||
var configuration = context.Services.GetConfiguration(); |
|||
|
|||
context.Services.AddAbpDbContext<VoloDocsDbContext>(); |
|||
|
|||
Configure<DbConnectionOptions>(options => |
|||
{ |
|||
options.ConnectionStrings.Default = configuration["ConnectionString"]; |
|||
}); |
|||
|
|||
Configure<AbpDbContextOptions>(options => |
|||
{ |
|||
options.UseSqlServer(); |
|||
}); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,3 @@ |
|||
{ |
|||
"ConnectionString": "Server=localhost;Database=VoloDocsNew;Trusted_Connection=True;MultipleActiveResultSets=true" |
|||
} |
|||
Loading…
Reference in new issue