Browse Source

🎉 feat(aspnet-core/migrations): 新增 Entity Framework Core SQL Server 模块及相关配置文件

pull/1048/head
feijie 1 year ago
parent
commit
618e4d9599
  1. 7
      aspnet-core/LINGYUN.MicroService.SingleProject.sln
  2. 1
      aspnet-core/migrations/LY.MicroService.Applications.Single.DbMigrator/LY.MicroService.Applications.Single.DbMigrator.csproj
  3. 228
      aspnet-core/migrations/LY.MicroService.Applications.Single.DbMigrator/appsettings.SqlServer.json
  4. 16
      aspnet-core/migrations/LY.MicroService.Applications.Single.EntityFrameworkCore.SqlServer/LY.MicroService.Applications.Single.EntityFrameworkCore.SqlServer.csproj
  5. 59
      aspnet-core/migrations/LY.MicroService.Applications.Single.EntityFrameworkCore.SqlServer/README.en.md
  6. 59
      aspnet-core/migrations/LY.MicroService.Applications.Single.EntityFrameworkCore.SqlServer/README.md
  7. 35
      aspnet-core/migrations/LY.MicroService.Applications.Single.EntityFrameworkCore.SqlServer/SingleMigrationsDbContextFactory.cs
  8. 26
      aspnet-core/migrations/LY.MicroService.Applications.Single.EntityFrameworkCore.SqlServer/SingleMigrationsEntityFrameworkCoreSqlServerModule.cs
  9. 5
      aspnet-core/migrations/Migrate.ps1
  10. 5
      aspnet-core/migrations/MigrateEn.ps1
  11. 4
      docs/startup-aio-readme.md

7
aspnet-core/LINGYUN.MicroService.SingleProject.sln

@ -615,6 +615,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LY.MicroService.Application
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LY.MicroService.Applications.Single.EntityFrameworkCore.MySql", "migrations\LY.MicroService.Applications.Single.EntityFrameworkCore.MySql\LY.MicroService.Applications.Single.EntityFrameworkCore.MySql.csproj", "{2B167D92-2327-4679-9096-49F274FABE0C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LY.MicroService.Applications.Single.EntityFrameworkCore.SqlServer", "migrations\LY.MicroService.Applications.Single.EntityFrameworkCore.SqlServer\LY.MicroService.Applications.Single.EntityFrameworkCore.SqlServer.csproj", "{30EEF879-CFF7-4661-89CB-9CB68328D008}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -1613,6 +1615,10 @@ Global
{2B167D92-2327-4679-9096-49F274FABE0C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2B167D92-2327-4679-9096-49F274FABE0C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2B167D92-2327-4679-9096-49F274FABE0C}.Release|Any CPU.Build.0 = Release|Any CPU
{30EEF879-CFF7-4661-89CB-9CB68328D008}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{30EEF879-CFF7-4661-89CB-9CB68328D008}.Debug|Any CPU.Build.0 = Debug|Any CPU
{30EEF879-CFF7-4661-89CB-9CB68328D008}.Release|Any CPU.ActiveCfg = Release|Any CPU
{30EEF879-CFF7-4661-89CB-9CB68328D008}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -1909,6 +1915,7 @@ Global
{AA742577-63B0-4188-AA36-AC6E0ED99BB6} = {07DFEB1E-ED92-4E97-A801-FAB2D70F4F35}
{5A07FFDF-F979-44F9-BE24-81D6A25BEADB} = {0D69B63D-F082-4D57-9FF0-355642C56993}
{2B167D92-2327-4679-9096-49F274FABE0C} = {0D69B63D-F082-4D57-9FF0-355642C56993}
{30EEF879-CFF7-4661-89CB-9CB68328D008} = {0D69B63D-F082-4D57-9FF0-355642C56993}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {711A43C0-A2F8-4E5C-9B9F-F2551E4B3FF1}

1
aspnet-core/migrations/LY.MicroService.Applications.Single.DbMigrator/LY.MicroService.Applications.Single.DbMigrator.csproj

@ -59,6 +59,7 @@
<ProjectReference Include="..\..\modules\platform\LINGYUN.Abp.UI.Navigation.VueVbenAdmin\LINGYUN.Abp.UI.Navigation.VueVbenAdmin.csproj" />
<ProjectReference Include="..\LY.MicroService.Applications.Single.EntityFrameworkCore.PostgreSql\LY.MicroService.Applications.Single.EntityFrameworkCore.PostgreSql.csproj" />
<ProjectReference Include="..\LY.MicroService.Applications.Single.EntityFrameworkCore.MySql\LY.MicroService.Applications.Single.EntityFrameworkCore.Mysql.csproj" />
<ProjectReference Include="..\LY.MicroService.Applications.Single.EntityFrameworkCore.SqlServer\LY.MicroService.Applications.Single.EntityFrameworkCore.SqlServer.csproj" />
</ItemGroup>
</Project>

228
aspnet-core/migrations/LY.MicroService.Applications.Single.DbMigrator/appsettings.SqlServer.json

@ -0,0 +1,228 @@
{
"App": {
"ShowPii": true,
"SelfUrl": "http://127.0.0.1:30001/",
"CorsOrigins": "http://127.0.0.1:3100,http://127.0.0.1:30001",
"Urls": {
"Applications": {
"MVC": {
"RootUrl": "http://127.0.0.1:30001/",
"Urls": {
"Abp.Account.EmailConfirm": "Account/EmailConfirm",
"Abp.Account.EmailVerifyLogin": "Account/VerifyCode"
}
},
"STS": {
"RootUrl": "http://127.0.0.1:30001/"
},
"VueVbenAdmin": {
"RootUrl": "http://127.0.0.1:3100",
"Urls": {
"Abp.Account.EmailConfirm": "account/email-confirm"
}
}
}
}
},
"Auditing": {
"AllEntitiesSelector": true
},
"DistributedCache": {
"HideErrors": true,
"KeyPrefix": "LINGYUN.Abp.Application",
"GlobalCacheEntryOptions": {
"SlidingExpiration": "30:00:00",
"AbsoluteExpirationRelativeToNow": "60:00:00"
}
},
"ConnectionStrings": {
"Default": "Server=127.0.0.1;Database=Platform-V70;User Id=sa;Password=yourStrong(!)Password;TrustServerCertificate=True"
},
"DistributedLock": {
"IsEnabled": true,
"Redis": {
"Configuration": "127.0.0.1,defaultDatabase=14"
}
},
"Elsa": {
"Features": {
"DefaultPersistence": {
"Enabled": true,
"ConnectionStringIdentifier": "Default",
"EntityFrameworkCore": {
"SqlServer": {
"Enabled": true
}
}
},
"Console": true,
"Http": true,
"Email": true,
"TemporalQuartz": true,
"JavaScriptActivities": true,
"UserTask": true,
"Conductor": true,
"Telnyx": true,
"BlobStoring": true,
"Emailing": true,
"Notification": true,
"Sms": true,
"IM": true,
"PublishWebhook": true,
"Webhooks": {
"Enabled": true,
"ConnectionStringIdentifier": "Default",
"EntityFrameworkCore": {
"SqlServer": {
"Enabled": true
}
}
},
"WorkflowSettings": {
"Enabled": true,
"ConnectionStringIdentifier": "Default",
"EntityFrameworkCore": {
"SqlServer": {
"Enabled": true
}
}
}
},
"Server": {
"BaseUrl": "http://127.0.0.1:30000"
}
},
"Quartz": {
"UsePersistentStore": false,
"Properties": {
"quartz.jobStore.dataSource": "tkm",
"quartz.jobStore.type": "Quartz.Impl.AdoJobStore.JobStoreTX, Quartz",
"quartz.jobStore.driverDelegateType": "Quartz.Impl.AdoJobStore.SqlServerDelegate, Quartz",
"quartz.dataSource.tkm.connectionString": "Server=127.0.0.1;Database=Platform-V70;User Id=sa;Password=yourStrong(!)Password;",
"quartz.dataSource.tkm.provider": "SqlServer",
"quartz.jobStore.clustered": "true",
"quartz.serializer.type": "json",
"quartz.dataSource.tkm.connectionStringName": "TaskManagement"
}
},
"Redis": {
"IsEnabled": true,
"Configuration": "127.0.0.1,defaultDatabase=15",
"InstanceName": "LINGYUN.Abp.Application"
},
"AuthServer": {
"UseOpenIddict": true,
"Authority": "http://127.0.0.1:30001/",
"ApiName": "lingyun-abp-application",
"SwaggerClientId": "InternalServiceClient",
"SwaggerClientSecret": "1q2w3E*"
},
"IdentityServer": {
"Clients": {
"VueAdmin": {
"ClientId": "vue-admin-client",
"RootUrl": "http://127.0.0.1:3100/"
},
"InternalService": {
"ClientId": "InternalServiceClient"
}
}
},
"OpenIddict": {
"Applications": {
"VueAdmin": {
"ClientId": "vue-admin-client",
"RootUrl": "http://127.0.0.1:3100/"
},
"InternalService": {
"ClientId": "InternalServiceClient"
}
},
"Lifetime": {
"AuthorizationCode": "00:05:00",
"AccessToken": "14:00:00",
"DeviceCode": "00:10:00",
"IdentityToken": "00:20:00",
"RefreshToken": "14:00:00",
"RefreshTokenReuseLeeway": "00:00:30",
"UserCode": "00:10:00"
}
},
"Identity": {
"Password": {
"RequiredLength": 6,
"RequiredUniqueChars": 0,
"RequireNonAlphanumeric": false,
"RequireLowercase": false,
"RequireUppercase": false,
"RequireDigit": false
},
"Lockout": {
"AllowedForNewUsers": false,
"LockoutDuration": 5,
"MaxFailedAccessAttempts": 5
},
"SignIn": {
"RequireConfirmedEmail": false,
"RequireConfirmedPhoneNumber": false
}
},
"FeatureManagement": {
"IsDynamicStoreEnabled": true
},
"SettingManagement": {
"IsDynamicStoreEnabled": true
},
"PermissionManagement": {
"IsDynamicStoreEnabled": true
},
"TextTemplating": {
"IsDynamicStoreEnabled": true
},
"WebhooksManagement": {
"IsDynamicStoreEnabled": true
},
"Logging": {
"Serilog": {
"Elasticsearch": {
"IndexFormat": "abp.dev.logging-{0:yyyy.MM.dd}"
}
}
},
"AuditLogging": {
"Elasticsearch": {
"IndexPrefix": "abp.dev.auditing"
}
},
"Elasticsearch": {
"NodeUris": "http://127.0.0.1:9200"
},
"Serilog": {
"MinimumLevel": {
"Default": "Debug",
"Override": {
"System": "Warning",
"Microsoft": "Warning",
"DotNetCore": "Debug"
}
},
"WriteTo": [
{
"Name": "Console",
"Args": {
"restrictedToMinimumLevel": "Debug",
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level:u3}] [{SourceContext}] [{ProcessId}] [{ThreadId}] - {Message:lj}{NewLine}{Exception}"
}
},
{
"Name": "Elasticsearch",
"Args": {
"nodeUris": "http://127.0.0.1:9200",
"indexFormat": "abp.dev.logging-{0:yyyy.MM.dd}",
"autoRegisterTemplate": true,
"autoRegisterTemplateVersion": "ESv7"
}
}
]
}
}

16
aspnet-core/migrations/LY.MicroService.Applications.Single.EntityFrameworkCore.SqlServer/LY.MicroService.Applications.Single.EntityFrameworkCore.SqlServer.csproj

@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Volo.Abp.EntityFrameworkCore.SqlServer" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\modules\elsa\LINGYUN.Abp.Elsa.EntityFrameworkCore.SqlServer\LINGYUN.Abp.Elsa.EntityFrameworkCore.SqlServer.csproj" />
<ProjectReference Include="..\LY.MicroService.Applications.Single.EntityFrameworkCore\LY.MicroService.Applications.Single.EntityFrameworkCore.csproj" />
</ItemGroup>
</Project>

59
aspnet-core/migrations/LY.MicroService.Applications.Single.EntityFrameworkCore.SqlServer/README.en.md

@ -0,0 +1,59 @@
# SQL Server Database Migration Guide
This guide will help you manage SQL Server database migrations using the migration scripts.
## Prerequisites
1. Ensure .NET Core SDK is installed
2. Ensure Entity Framework Core tools are installed
```powershell
dotnet tool install --global dotnet-ef
```
3. Ensure SQL Server connection string is properly configured
## Usage Instructions
### 1. Create New Migration
1. Run the migration script in the `aspnet-core/migrations` directory:
```powershell
# Use English version
.\MigrateEn.ps1
# Or use Chinese version
.\Migrate.ps1
```
2. Select SQL Server database context from the menu:
```
[3] LY.MicroService.Applications.Single.EntityFrameworkCore.SqlServer
```
3. Enter migration name (optional):
- Press Enter to use default name: `AddNewMigration_yyyyMMdd_HHmmss`
- Or enter custom name, e.g.: `AddNewFeature`
### 2. Generate SQL Script
After creating the migration, the script will ask if you want to generate SQL script:
1. Choose whether to generate SQL script (Y/N)
2. If Y is selected, following options will be available:
- `[A]` - Generate SQL script for all migrations
- `[L]` - Generate SQL script for latest migration only
- `[0-9]` - Generate from specified migration version
Generated SQL scripts will be saved in:
```
aspnet-core/InitSql/LY.MicroService.Applications.Single.EntityFrameworkCore.SqlServer/
```
### 3. Apply Migration
Generated SQL scripts can be applied to database through:
1. Using SQL Server Management Studio or other SQL Server client tools to execute SQL script
2. Or using command line:
```bash
sqlcmd -S your_server -d your_database -i your_script.sql
```

59
aspnet-core/migrations/LY.MicroService.Applications.Single.EntityFrameworkCore.SqlServer/README.md

@ -0,0 +1,59 @@
# SQL Server 数据库迁移指南
本指南将帮助您使用迁移脚本来管理 SQL Server 数据库的迁移操作。
## 前置条件
1. 确保已安装 .NET Core SDK
2. 确保已安装 Entity Framework Core 工具
```powershell
dotnet tool install --global dotnet-ef
```
3. 确保已正确配置 SQL Server 连接字符串
## 使用说明
### 1. 创建新的迁移
1. 在 `aspnet-core/migrations` 目录下运行迁移脚本:
```powershell
# 使用中文版本
.\Migrate.ps1
# 或使用英文版本
.\MigrateEn.ps1
```
2. 在菜单中选择 SQL Server 数据库上下文:
```
[3] LY.MicroService.Applications.Single.EntityFrameworkCore.SqlServer
```
3. 输入迁移名称(可选):
- 直接回车将使用默认名称:`AddNewMigration_yyyyMMdd_HHmmss`
- 或输入自定义名称,如:`AddNewFeature`
### 2. 生成 SQL 脚本
在创建迁移后,脚本会询问是否需要生成 SQL 脚本:
1. 选择是否生成 SQL 脚本 (Y/N)
2. 如果选择 Y,将提供以下选项:
- `[A]` - 生成所有迁移的 SQL 脚本
- `[L]` - 仅生成最新迁移的 SQL 脚本
- `[0-9]` - 从指定的迁移版本开始生成
生成的 SQL 脚本将保存在:
```
aspnet-core/InitSql/LY.MicroService.Applications.Single.EntityFrameworkCore.SqlServer/
```
### 3. 应用迁移
生成的 SQL 脚本可以通过以下方式应用到数据库:
1. 使用 SQL Server Management Studio 或其他 SQL Server 客户端工具执行 SQL 脚本
2. 或使用命令行:
```bash
sqlcmd -S your_server -d your_database -i your_script.sql
```

35
aspnet-core/migrations/LY.MicroService.Applications.Single.EntityFrameworkCore.SqlServer/SingleMigrationsDbContextFactory.cs

@ -0,0 +1,35 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
using Microsoft.Extensions.Configuration;
using System;
using System.IO;
namespace LY.MicroService.Applications.Single.EntityFrameworkCore.SqlServer;
public class SingleMigrationsDbContextFactory : IDesignTimeDbContextFactory<SingleMigrationsDbContext>
{
public SingleMigrationsDbContext CreateDbContext(string[] args)
{
var configuration = BuildConfiguration();
var connectionString = configuration.GetConnectionString("Default");
var builder = new DbContextOptionsBuilder<SingleMigrationsDbContext>()
.UseSqlServer(connectionString,
b => b.MigrationsAssembly("LY.MicroService.Applications.Single.EntityFrameworkCore.SqlServer"));
return new SingleMigrationsDbContext(builder!.Options);
}
private static IConfigurationRoot BuildConfiguration()
{
var builder = new ConfigurationBuilder()
.SetBasePath(Path.Combine(Directory.GetCurrentDirectory(),
"../LY.MicroService.Applications.Single.DbMigrator/"))
.AddJsonFile("appsettings.json", optional: false)
.AddJsonFile(
"appsettings.SqlServer.json",
optional: false);
return builder.Build();
}
}

26
aspnet-core/migrations/LY.MicroService.Applications.Single.EntityFrameworkCore.SqlServer/SingleMigrationsEntityFrameworkCoreSqlServerModule.cs

@ -0,0 +1,26 @@
using LINGYUN.Abp.Elsa.EntityFrameworkCore.SqlServer;
using Microsoft.Extensions.DependencyInjection;
using System;
using Volo.Abp.EntityFrameworkCore;
using Volo.Abp.EntityFrameworkCore.SqlServer;
using Volo.Abp.Modularity;
namespace LY.MicroService.Applications.Single.EntityFrameworkCore.SqlServer;
[DependsOn(
typeof(AbpEntityFrameworkCoreSqlServerModule),
typeof(AbpElsaEntityFrameworkCoreSqlServerModule),
typeof(SingleMigrationsEntityFrameworkCoreModule)
)]
public class SingleMigrationsEntityFrameworkCoreSqlServerModule : AbpModule
{
public override void ConfigureServices(ServiceConfigurationContext context)
{
context.Services.AddAbpDbContext<SingleMigrationsDbContext>();
Configure<AbpDbContextOptions>(options =>
{
options.UseSqlServer();
});
}
}

5
aspnet-core/migrations/Migrate.ps1

@ -21,6 +21,11 @@ $dbContexts = @{
Context = "SingleMigrationsDbContext"
Factory = "SingleMigrationsDbContextFactory"
}
3 = @{
Name = "LY.MicroService.Applications.Single.EntityFrameworkCore.SqlServer"
Context = "SingleMigrationsDbContext"
Factory = "SingleMigrationsDbContextFactory"
}
}
# 显示DbContext选择菜单

5
aspnet-core/migrations/MigrateEn.ps1

@ -21,6 +21,11 @@ $dbContexts = @{
Context = "SingleMigrationsDbContext"
Factory = "SingleMigrationsDbContextFactory"
}
"3" = @{
Name = "LY.MicroService.Applications.Single.EntityFrameworkCore.SqlServer"
Context = "SingleMigrationsDbContext"
Factory = "SingleMigrationsDbContextFactory"
}
}
# Display DbContext selection menu

4
docs/startup-aio-readme.md

@ -69,7 +69,7 @@ docker run -d --name mysql \
CREATE DATABASE `Platform-V70`;
```
##### SQL Server(即将支持)
##### SQL Server
```shell
# 使用Docker启动SQL Server
@ -109,7 +109,7 @@ MySQL:
}
```
SQL Server(即将支持):
SQL Server:
```json
{

Loading…
Cancel
Save