48 changed files with 511 additions and 443 deletions
@ -0,0 +1,44 @@ |
|||
image: mcr.microsoft.com/dotnet/sdk:9.0 |
|||
|
|||
stages: |
|||
- build |
|||
- test |
|||
- tag |
|||
|
|||
build_job: |
|||
stage: build |
|||
script: |
|||
- echo "[ProjectName] - Build project..." |
|||
- dotnet build --configuration Release |
|||
only: |
|||
- dev |
|||
|
|||
test_job: |
|||
stage: test |
|||
script: |
|||
- echo "[ProjectName] - Unit testing..." |
|||
- dotnet test --no-build --configuration Release |
|||
dependencies: |
|||
- build_job |
|||
only: |
|||
- dev |
|||
|
|||
tag_job: |
|||
stage: tag |
|||
only: |
|||
- main |
|||
script: |
|||
- echo "[ProjectName] - Tag project..." |
|||
# 获取 common.props 中定义的版本号 |
|||
- export VERSION=$(sed -n 's/.*<Version>\([0-9]*\.[0-9]*\.[0-9]*\)<\/Version>.*/\1/p' common.props) |
|||
- echo $VERSION |
|||
|
|||
# 此处 yougitlab.com 替换为自己的 gitlab 服务器 |
|||
- git config --global user.email "ci@yougitlab.com" |
|||
- git config --global user.name "GitLab CI Bot" |
|||
|
|||
- git tag -f $VERSION |
|||
# 此处 yougitlab.com 替换为自己的 gitlab 服务器, 如未启用 https, 变更为 http://oauth2:$GITLAB_TOKEN@yougitlab.com/$CI_PROJECT_PATH.git |
|||
# 此处 $GITLAB_TOKEN 需要在gitlab服务器中配置 GITLAB_TOKEN 变量 |
|||
- git remote set-url origin https://oauth2:$GITLAB_TOKEN@yougitlab.com/$CI_PROJECT_PATH.git |
|||
- git push --force origin $VERSION |
|||
@ -0,0 +1,89 @@ |
|||
# ProjectName Pod |
|||
apiVersion: apps/v1 |
|||
kind: Deployment |
|||
metadata: |
|||
name: project-name-api |
|||
labels: |
|||
name: project-name-api |
|||
spec: |
|||
replicas: 1 |
|||
selector: |
|||
matchLabels: |
|||
name: project-name-api |
|||
template: |
|||
metadata: |
|||
labels: |
|||
name: project-name-api |
|||
spec: |
|||
containers: |
|||
- name: project-name-api |
|||
image: project-name-api:latest |
|||
env: |
|||
- name: ASPNETCORE_ENVIRONMENT |
|||
value: Production |
|||
# 时区问题自行修改 |
|||
# - name: TZ |
|||
# value: "Asia/Shanghai" |
|||
ports: |
|||
- containerPort: 8080 |
|||
imagePullPolicy: Always |
|||
livenessProbe: |
|||
httpGet: |
|||
path: /healthz |
|||
port: 8080 |
|||
volumeMounts: |
|||
# appsettings挂载 |
|||
# - mountPath: /app/appsettings.Production.json |
|||
# name: volume-cmkw2z |
|||
# subPath: appsettings.Production.json |
|||
- mountPath: /app/Logs |
|||
name: volume-xk3mds |
|||
subPath: ./logs |
|||
- mountPath: /app/Modules |
|||
name: volume-xk3mds |
|||
subPath: ./modules |
|||
volumes: |
|||
# 其他存储挂载自行处理 |
|||
- hostPath: |
|||
path: /var/opt/project-name |
|||
type: DirectoryOrCreate |
|||
# 注意变更名称 |
|||
name: volume-xk3mds |
|||
# appsettings挂载 |
|||
# - configMap: |
|||
# defaultMode: 420 |
|||
# name: project-name-api |
|||
# name: volume-cmkw2z |
|||
|
|||
--- |
|||
# ProjectName Service |
|||
kind: Service |
|||
apiVersion: v1 |
|||
metadata: |
|||
name: project-name-api |
|||
spec: |
|||
type: ClusterIP |
|||
ports: |
|||
- port: 8080 |
|||
selector: |
|||
name: project-name-api |
|||
|
|||
--- |
|||
# ProjectName Ingress |
|||
kind: Ingress |
|||
apiVersion: networking.k8s.io/v1 |
|||
metadata: |
|||
name: project-name-api |
|||
spec: |
|||
ingressClassName: nginx |
|||
rules: |
|||
- host: "project-name-api.local" |
|||
http: |
|||
paths: |
|||
- path: /api/project-name |
|||
pathType: Prefix |
|||
backend: |
|||
service: |
|||
name: project-name-api |
|||
port: |
|||
number: 8080 |
|||
@ -0,0 +1,9 @@ |
|||
services: |
|||
project-name-api: |
|||
build: |
|||
context: ../host/PackageName.CompanyName.ProjectName.HttpApi.Host/bin/Release/net9.0 |
|||
dockerfile: ../host/PackageName.CompanyName.ProjectName.HttpApi.Host/Dockerfile |
|||
volumes: |
|||
- /var/opt/project-name/logs:/app/Logs |
|||
- /var/opt/project-name/modules:/app/Modules |
|||
restart: always |
|||
@ -0,0 +1,15 @@ |
|||
services: |
|||
project-name-api: |
|||
hostname: project-name-api |
|||
container_name: project-name-api |
|||
environment: |
|||
- ASPNETCORE_ENVIRONMENT=Production |
|||
# 时区问题自行修改 |
|||
# - TZ=Asia/Shanghai |
|||
ports: |
|||
- "5000:8080" |
|||
healthcheck: |
|||
test: ["CMD-SHELL", "wget --spider http://localhost/healthz || exit"] |
|||
interval: 10s |
|||
timeout: 5s |
|||
retries: 5 |
|||
@ -1,147 +0,0 @@ |
|||
{ |
|||
"AgileConfig": { |
|||
"IsEnabled": false, |
|||
"env": "DEV", |
|||
"appId": "PackageName.CompanyName.ProjectName", |
|||
"secret": "1q2w3E*", |
|||
"nodes": "http://127.0.0.1:15000", |
|||
"name": "PackageName.CompanyName.ProjectName", |
|||
"tag": "PackageName.CompanyName.ProjectName" |
|||
}, |
|||
"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=ProjectName;User Id=root;Password=123456", |
|||
"ProjectName": "Server=127.0.0.1;Database=ProjectName;User Id=root;Password=123456", |
|||
"AbpSaas": "Server=127.0.0.1;Database=ProjectName;User Id=root;Password=123456", |
|||
"AbpFeatureManagement": "Server=127.0.0.1;Database=ProjectName;User Id=root;Password=123456", |
|||
"AbpPermissionManagement": "Server=127.0.0.1;Database=ProjectName;User Id=root;Password=123456", |
|||
"AbpSettingManagement": "Server=127.0.0.1;Database=ProjectName;User Id=root;Password=123456", |
|||
"AbpLocalizationManagement": "Server=127.0.0.1;Database=ProjectName;User Id=root;Password=123456", |
|||
"AbpTextTemplating": "Server=127.0.0.1;Database=ProjectName;User Id=root;Password=123456" |
|||
}, |
|||
"DistributedLock": { |
|||
"IsEnabled": true, |
|||
"Redis": { |
|||
"Configuration": "127.0.0.1,defaultDatabase=15" |
|||
} |
|||
}, |
|||
"OpenTelemetry": { |
|||
"IsEnabled": true, |
|||
"ZipKin": { |
|||
"Endpoint": "http://127.0.0.1:9411/api/v2/spans" |
|||
} |
|||
}, |
|||
"RemoteServices": {}, |
|||
"IdentityClients": { |
|||
"InternalServiceClient": { |
|||
"Authority": "http://127.0.0.1:44385", |
|||
"RequireHttps": false, |
|||
"GrantType": "client_credentials", |
|||
"Scope": "lingyun-abp-application", |
|||
"ClientId": "InternalServiceClient", |
|||
"ClientSecret": "1q2w3E*" |
|||
} |
|||
}, |
|||
"CAP": { |
|||
"EventBus": { |
|||
"DefaultGroupName": "ProjectName", |
|||
"GroupNamePrefix": "Dev", |
|||
"Version": "v1", |
|||
"FailedRetryInterval": 300, |
|||
"FailedRetryCount": 10 |
|||
}, |
|||
"MySql": { |
|||
"TableNamePrefix": "ProjectName_cap", |
|||
"ConnectionString": "Server=127.0.0.1;Database=ProjectName;User Id=root;Password=123456" |
|||
}, |
|||
"SqlServer": { |
|||
"TableNamePrefix": "ProjectName_cap", |
|||
"ConnectionString": "Server=127.0.0.1;Database=ProjectName;User Id=root;Password=123456" |
|||
}, |
|||
"Sqlite": { |
|||
"TableNamePrefix": "ProjectName_cap", |
|||
"ConnectionString": "Data Source=./cap.db" |
|||
}, |
|||
"Oracle": { |
|||
"TableNamePrefix": "ProjectName_cap", |
|||
"ConnectionString": "Data Source=ProjectName;Integrated Security=yes;" |
|||
}, |
|||
"PostgreSql": { |
|||
"TableNamePrefix": "ProjectName_cap", |
|||
"ConnectionString": "Host=localhost;Port=5432;Database=ProjectName;User ID=root;Password=123456;" |
|||
}, |
|||
"RabbitMQ": { |
|||
"HostName": "127.0.0.1", |
|||
"Port": 5672, |
|||
"UserName": "admin", |
|||
"Password": "123456", |
|||
"ExchangeName": "LINGYUN.Abp.Application", |
|||
"VirtualHost": "/" |
|||
} |
|||
}, |
|||
"Redis": { |
|||
"Configuration": "127.0.0.1,defaultDatabase=10", |
|||
"InstanceName": "LINGYUN.Abp.Application" |
|||
}, |
|||
"AuthServer": { |
|||
"Authority": "http://127.0.0.1:44385/", |
|||
"Audience": "lingyun-abp-application", |
|||
"MapInboundClaims": false, |
|||
"RequireHttpsMetadata": false, |
|||
"SwaggerClientId": "InternalServiceClient", |
|||
"SwaggerClientSecret": "1q2w3E*" |
|||
}, |
|||
"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" |
|||
} |
|||
} |
|||
] |
|||
} |
|||
} |
|||
@ -1,83 +0,0 @@ |
|||
{ |
|||
"ConnectionStrings": { |
|||
"Default": "Server=127.0.0.1;Database=ProjectName;User Id=root;Password=123456" |
|||
}, |
|||
"StringEncryption": { |
|||
"DefaultPassPhrase": "s46c5q55nxpeS8Ra", |
|||
"InitVectorBytes": "s83ng0abvd02js84", |
|||
"DefaultSalt": "sf&5)s3#" |
|||
}, |
|||
"AllowedHosts": "*", |
|||
"Serilog": { |
|||
"MinimumLevel": { |
|||
"Default": "Debug", |
|||
"Override": { |
|||
"Microsoft.EntityFrameworkCore": "Debug", |
|||
"System": "Information", |
|||
"Microsoft": "Information" |
|||
} |
|||
}, |
|||
"Enrich": [ "FromLogContext", "WithProcessId", "WithThreadId", "WithEnvironmentName", "WithMachineName", "WithApplicationName", "WithUniqueId" ], |
|||
"WriteTo": [ |
|||
{ |
|||
"Name": "Console", |
|||
"Args": { |
|||
"initialMinimumLevel": "Verbose", |
|||
"standardErrorFromLevel": "Verbose", |
|||
"restrictedToMinimumLevel": "Verbose", |
|||
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level:u3}] [{SourceContext}] [{ProcessId}] [{ThreadId}] - {Message:lj}{NewLine}{Exception}" |
|||
} |
|||
}, |
|||
{ |
|||
"Name": "File", |
|||
"Args": { |
|||
"path": "Logs/Debug-.log", |
|||
"restrictedToMinimumLevel": "Debug", |
|||
"rollingInterval": "Day", |
|||
"fileSizeLimitBytes": 5242880, |
|||
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level:u3}] [{SourceContext}] [{ProcessId}] [{ThreadId}] - {Message:lj}{NewLine}{Exception}" |
|||
} |
|||
}, |
|||
{ |
|||
"Name": "File", |
|||
"Args": { |
|||
"path": "Logs/Info-.log", |
|||
"restrictedToMinimumLevel": "Information", |
|||
"rollingInterval": "Day", |
|||
"fileSizeLimitBytes": 5242880, |
|||
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level:u3}] [{SourceContext}] [{ProcessId}] [{ThreadId}] - {Message:lj}{NewLine}{Exception}" |
|||
} |
|||
}, |
|||
{ |
|||
"Name": "File", |
|||
"Args": { |
|||
"path": "Logs/Warn-.log", |
|||
"restrictedToMinimumLevel": "Warning", |
|||
"rollingInterval": "Day", |
|||
"fileSizeLimitBytes": 5242880, |
|||
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level:u3}] [{SourceContext}] [{ProcessId}] [{ThreadId}] - {Message:lj}{NewLine}{Exception}" |
|||
} |
|||
}, |
|||
{ |
|||
"Name": "File", |
|||
"Args": { |
|||
"path": "Logs/Error-.log", |
|||
"restrictedToMinimumLevel": "Error", |
|||
"rollingInterval": "Day", |
|||
"fileSizeLimitBytes": 5242880, |
|||
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level:u3}] [{SourceContext}] [{ProcessId}] [{ThreadId}] - {Message:lj}{NewLine}{Exception}" |
|||
} |
|||
}, |
|||
{ |
|||
"Name": "File", |
|||
"Args": { |
|||
"path": "Logs/Fatal-.log", |
|||
"restrictedToMinimumLevel": "Fatal", |
|||
"rollingInterval": "Day", |
|||
"fileSizeLimitBytes": 5242880, |
|||
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level:u3}] [{SourceContext}] [{ProcessId}] [{ThreadId}] - {Message:lj}{NewLine}{Exception}" |
|||
} |
|||
} |
|||
] |
|||
} |
|||
} |
|||
@ -0,0 +1,3 @@ |
|||
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd"> |
|||
<ConfigureAwait ContinueOnCapturedContext="false" /> |
|||
</Weavers> |
|||
32
aspnet-core/templates/micro/content/host/PackageName.CompanyName.ProjectName.DbMigrator/PackageName.CompanyName.ProjectName.DbMigrator.csproj → aspnet-core/templates/micro/content/migrations/PackageName.CompanyName.ProjectName.DbMigrator.EntityFrameworkCore/PackageName.CompanyName.ProjectName.DbMigrator.EntityFrameworkCore.csproj
32
aspnet-core/templates/micro/content/host/PackageName.CompanyName.ProjectName.DbMigrator/PackageName.CompanyName.ProjectName.DbMigrator.csproj → aspnet-core/templates/micro/content/migrations/PackageName.CompanyName.ProjectName.DbMigrator.EntityFrameworkCore/PackageName.CompanyName.ProjectName.DbMigrator.EntityFrameworkCore.csproj
@ -0,0 +1,62 @@ |
|||
using Microsoft.EntityFrameworkCore; |
|||
using Microsoft.EntityFrameworkCore.Design; |
|||
using Microsoft.Extensions.Configuration; |
|||
using System; |
|||
using System.IO; |
|||
|
|||
namespace PackageName.CompanyName.ProjectName.EntityFrameworkCore; |
|||
public class ProjectNameDbContextFactory : IDesignTimeDbContextFactory<ProjectNameDbContext> |
|||
{ |
|||
public ProjectNameDbContext CreateDbContext(string[] args) |
|||
{ |
|||
var configuration = BuildConfiguration(); |
|||
var connectionString = configuration.GetConnectionString("ProjectName"); |
|||
|
|||
DbContextOptionsBuilder<ProjectNameDbContext> builder = null; |
|||
|
|||
try |
|||
{ |
|||
#if MySQL
|
|||
builder = new DbContextOptionsBuilder<ProjectNameDbContext>() |
|||
.UseMySql(connectionString, ServerVersion.AutoDetect(connectionString), b => |
|||
b.MigrationsAssembly(GetType().Assembly)); |
|||
#elif SqlServer
|
|||
builder = new DbContextOptionsBuilder<ProjectNameDbContext>() |
|||
.UseSqlServer(connectionString, b => b.MigrationsAssembly(GetType().Assembly)); |
|||
#elif Sqlite
|
|||
builder = new DbContextOptionsBuilder<ProjectNameDbContext>() |
|||
.UseSqlite(connectionString, b => b.MigrationsAssembly(GetType().Assembly)); |
|||
#elif Oracle
|
|||
builder = new DbContextOptionsBuilder<ProjectNameDbContext>() |
|||
.UseOracle(connectionString, b => b.MigrationsAssembly(GetType().Assembly)); |
|||
#elif OracleDevart
|
|||
builder = (DbContextOptionsBuilder<ProjectNameDbContext>) new DbContextOptionsBuilder<ProjectNameDbContext>() |
|||
.UseOracle(connectionString, b => b.MigrationsAssembly(GetType().Assembly)); |
|||
#elif PostgreSql
|
|||
builder = new DbContextOptionsBuilder<ProjectNameDbContext>() |
|||
.UseNpgsql(connectionString, b => b.MigrationsAssembly(GetType().Assembly)); |
|||
#endif
|
|||
return new ProjectNameDbContext(builder!.Options); |
|||
} |
|||
catch (Exception ex) |
|||
{ |
|||
Console.ForegroundColor = ConsoleColor.Red; |
|||
|
|||
Console.WriteLine("[ProjectName] - Database migrations failed: {message}", ex.Message); |
|||
|
|||
Console.ResetColor(); |
|||
|
|||
throw; |
|||
} |
|||
} |
|||
|
|||
private static IConfigurationRoot BuildConfiguration() |
|||
{ |
|||
var builder = new ConfigurationBuilder() |
|||
.SetBasePath(Path.Combine(Directory.GetCurrentDirectory(), "../PackageName.CompanyName.ProjectName.DbMigrator/")) |
|||
.AddJsonFile("appsettings.json", optional: false); |
|||
|
|||
return builder.Build(); |
|||
} |
|||
} |
|||
|
|||
0
aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.EntityFrameworkCore/PackageName/CompanyName/ProjectName/EntityFrameworkCore/ProjectNameDbMigrationEventHandler.cs → aspnet-core/templates/micro/content/migrations/PackageName.CompanyName.ProjectName.DbMigrator.EntityFrameworkCore/ProjectNameDbMigrationEventHandler.cs
0
aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.EntityFrameworkCore/PackageName/CompanyName/ProjectName/EntityFrameworkCore/ProjectNameDbMigrationEventHandler.cs → aspnet-core/templates/micro/content/migrations/PackageName.CompanyName.ProjectName.DbMigrator.EntityFrameworkCore/ProjectNameDbMigrationEventHandler.cs
14
aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.EntityFrameworkCore/PackageName/CompanyName/ProjectName/EntityFrameworkCore/ProjectNameDbMigrationService.cs → aspnet-core/templates/micro/content/migrations/PackageName.CompanyName.ProjectName.DbMigrator.EntityFrameworkCore/ProjectNameDbMigrationService.cs
14
aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.EntityFrameworkCore/PackageName/CompanyName/ProjectName/EntityFrameworkCore/ProjectNameDbMigrationService.cs → aspnet-core/templates/micro/content/migrations/PackageName.CompanyName.ProjectName.DbMigrator.EntityFrameworkCore/ProjectNameDbMigrationService.cs
@ -0,0 +1,105 @@ |
|||
using LINGYUN.Abp.Data.DbMigrator; |
|||
using LINGYUN.Abp.DataProtection.EntityFrameworkCore; |
|||
using LINGYUN.Abp.Saas.EntityFrameworkCore; |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using Volo.Abp.Data; |
|||
using Volo.Abp.EntityFrameworkCore; |
|||
using Volo.Abp.Modularity; |
|||
#if MySQL
|
|||
using Volo.Abp.EntityFrameworkCore.MySQL; |
|||
#elif SqlServer
|
|||
using Volo.Abp.EntityFrameworkCore.SqlServer; |
|||
using Microsoft.EntityFrameworkCore.Infrastructure; |
|||
#elif Sqlite
|
|||
using Volo.Abp.EntityFrameworkCore.Sqlite; |
|||
#elif Oracle
|
|||
using Volo.Abp.EntityFrameworkCore.Oracle; |
|||
#elif OracleDevart
|
|||
using Volo.Abp.EntityFrameworkCore.Oracle.Devart; |
|||
#elif PostgreSql
|
|||
using Volo.Abp.EntityFrameworkCore.PostgreSql; |
|||
#endif
|
|||
|
|||
namespace PackageName.CompanyName.ProjectName.EntityFrameworkCore; |
|||
|
|||
[DependsOn( |
|||
typeof(AbpDataDbMigratorModule), |
|||
typeof(ProjectNameEntityFrameworkCoreModule), |
|||
typeof(AbpSaasEntityFrameworkCoreModule), |
|||
#if MySQL
|
|||
typeof(AbpEntityFrameworkCoreMySQLModule), |
|||
#elif SqlServer
|
|||
typeof(AbpEntityFrameworkCoreSqlServerModule), |
|||
#elif Sqlite
|
|||
typeof(AbpEntityFrameworkCoreSqliteModule), |
|||
#elif Oracle
|
|||
typeof(AbpEntityFrameworkCoreOracleModule), |
|||
#elif OracleDevart
|
|||
typeof(AbpEntityFrameworkCoreOracleDevartModule), |
|||
#elif PostgreSql
|
|||
typeof(AbpEntityFrameworkCorePostgreSqlModule), |
|||
#endif
|
|||
typeof(AbpDataDbMigratorModule) |
|||
)] |
|||
public class ProjectNameDbMigratorEntityFrameworkCoreModule : AbpModule |
|||
{ |
|||
public override void ConfigureServices(ServiceConfigurationContext context) |
|||
{ |
|||
// 配置连接字符串
|
|||
Configure<AbpDbConnectionOptions>(options => |
|||
{ |
|||
// 业务数据库
|
|||
options.Databases.Configure("ProjectName", database => |
|||
{ |
|||
database.MapConnection( |
|||
"ProjectName" |
|||
); |
|||
}); |
|||
// abp框架数据库
|
|||
options.Databases.Configure("Framework", database => |
|||
{ |
|||
database.MapConnection( |
|||
"AbpSaas", |
|||
"AbpTextTemplating", |
|||
"AbpSettingManagement", |
|||
"AbpFeatureManagement", |
|||
"AbpPermissionManagement", |
|||
"AbpLocalizationManagement" |
|||
); |
|||
}); |
|||
}); |
|||
|
|||
// 配置Ef
|
|||
Configure<AbpDbContextOptions>(options => |
|||
{ |
|||
#if MySQL
|
|||
options.UseMySQL(mysql => |
|||
{ |
|||
// see: https://github.com/PomeloFoundation/Pomelo.EntityFrameworkCore.MySql/issues/1960
|
|||
mysql.TranslateParameterizedCollectionsToConstants(); |
|||
}); |
|||
options.UseMySQL<ProjectNameDbContext>(mysql => |
|||
{ |
|||
// see: https://github.com/PomeloFoundation/Pomelo.EntityFrameworkCore.MySql/issues/1960
|
|||
mysql.TranslateParameterizedCollectionsToConstants(); |
|||
}); |
|||
#elif SqlServer
|
|||
options.UseSqlServer(); |
|||
options.UseSqlServer<ProjectNameDbContext>(builder => |
|||
{ |
|||
// see https://learn.microsoft.com/en-us/sql/t-sql/statements/alter-database-transact-sql-compatibility-level?view=sql-server-ver16
|
|||
// builder.UseCompatibilityLevel(150);
|
|||
}); |
|||
#elif Sqlite
|
|||
options.UseSqlite(); |
|||
options.UseSqlite<ProjectNameDbContext>(); |
|||
#elif Oracle || OracleDevart
|
|||
options.UseOracle(); |
|||
options.UseOracle<ProjectNameDbContext>(); |
|||
#elif PostgreSql
|
|||
options.UseNpgsql(); |
|||
options.UseNpgsql<ProjectNameDbContext>(); |
|||
#endif
|
|||
}); |
|||
} |
|||
} |
|||
@ -0,0 +1,30 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> |
|||
<!-- This file was generated by Fody. Manual changes to this file will be lost when your project is rebuilt. --> |
|||
<xs:element name="Weavers"> |
|||
<xs:complexType> |
|||
<xs:all> |
|||
<xs:element name="ConfigureAwait" minOccurs="0" maxOccurs="1"> |
|||
<xs:complexType> |
|||
<xs:attribute name="ContinueOnCapturedContext" type="xs:boolean" /> |
|||
</xs:complexType> |
|||
</xs:element> |
|||
</xs:all> |
|||
<xs:attribute name="VerifyAssembly" type="xs:boolean"> |
|||
<xs:annotation> |
|||
<xs:documentation>'true' to run assembly verification (PEVerify) on the target assembly after all weavers have been executed.</xs:documentation> |
|||
</xs:annotation> |
|||
</xs:attribute> |
|||
<xs:attribute name="VerifyIgnoreCodes" type="xs:string"> |
|||
<xs:annotation> |
|||
<xs:documentation>A comma-separated list of error codes that can be safely ignored in assembly verification.</xs:documentation> |
|||
</xs:annotation> |
|||
</xs:attribute> |
|||
<xs:attribute name="GenerateXsd" type="xs:boolean"> |
|||
<xs:annotation> |
|||
<xs:documentation>'false' to turn off automatic generation of the XML Schema file.</xs:documentation> |
|||
</xs:annotation> |
|||
</xs:attribute> |
|||
</xs:complexType> |
|||
</xs:element> |
|||
</xs:schema> |
|||
@ -0,0 +1,39 @@ |
|||
<Project Sdk="Microsoft.NET.Sdk"> |
|||
|
|||
<Import Project="../../configureawait.props" /> |
|||
|
|||
<PropertyGroup> |
|||
<OutputType>Exe</OutputType> |
|||
<TargetFramework>net9.0</TargetFramework> |
|||
<ImplicitUsings>enable</ImplicitUsings> |
|||
<Nullable>enable</Nullable> |
|||
<IsPackable>false</IsPackable> |
|||
<LangVersion>latest</LangVersion> |
|||
</PropertyGroup> |
|||
|
|||
<ItemGroup> |
|||
<PackageReference Include="Serilog.Extensions.Logging" /> |
|||
<PackageReference Include="Serilog.Sinks.File" /> |
|||
<PackageReference Include="Serilog.Sinks.Console" /> |
|||
<PackageReference Include="Microsoft.Extensions.Hosting" /> |
|||
<PackageReference Include="Volo.Abp.Autofac" /> |
|||
</ItemGroup> |
|||
|
|||
<ItemGroup> |
|||
<Compile Remove="Logs\**" /> |
|||
<Content Remove="Logs\**" /> |
|||
<EmbeddedResource Remove="Logs\**" /> |
|||
<None Remove="Logs\**" /> |
|||
</ItemGroup> |
|||
|
|||
<ItemGroup> |
|||
<ProjectReference Include="..\PackageName.CompanyName.ProjectName.DbMigrator.EntityFrameworkCore\PackageName.CompanyName.ProjectName.DbMigrator.EntityFrameworkCore.csproj" /> |
|||
</ItemGroup> |
|||
|
|||
<ItemGroup> |
|||
<None Update="appsettings.json"> |
|||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> |
|||
</None> |
|||
</ItemGroup> |
|||
|
|||
</Project> |
|||
@ -0,0 +1,12 @@ |
|||
{ |
|||
"ConnectionStrings": { |
|||
"ProjectName": "Server=127.0.0.1;Database=ProjectName;User Id=root;Password=123456", |
|||
"Framework": "Server=127.0.0.1;Database=ProjectName;User Id=root;Password=123456" |
|||
}, |
|||
"DistributedLock": { |
|||
"IsEnabled": true, |
|||
"Redis": { |
|||
"Configuration": "127.0.0.1,defaultDatabase=15" |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,15 @@ |
|||
Write-host "[ProjectName] - migrate database..." |
|||
|
|||
Set-Location ./PackageName.CompanyName.ProjectName.DbMigrator.EntityFrameworkCore |
|||
dotnet ef migrations add Initial-ProjectName-Module |
|||
dotnet ef database update |
|||
|
|||
Write-host "[ProjectName] - database migrations successfuly completed." |
|||
|
|||
Write-host "[ProjectName] - seeding data to database..." |
|||
|
|||
Set-Location ../PackageName.CompanyName.ProjectName.DbMigrator |
|||
|
|||
dotnet run |
|||
|
|||
Write-host "[ProjectName] - seed data successfuly completed." |
|||
0
aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Domain/PackageName/CompanyName/ProjectName/Features/ProjectNameFeatureDefinitionProvider.cs → aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Domain.Shared/PackageName/CompanyName/ProjectName/Features/ProjectNameFeatureDefinitionProvider.cs
0
aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Domain/PackageName/CompanyName/ProjectName/Features/ProjectNameFeatureDefinitionProvider.cs → aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Domain.Shared/PackageName/CompanyName/ProjectName/Features/ProjectNameFeatureDefinitionProvider.cs
0
aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Domain/PackageName/CompanyName/ProjectName/Features/ProjectNameFeatureNames.cs → aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Domain.Shared/PackageName/CompanyName/ProjectName/Features/ProjectNameFeatureNames.cs
0
aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Domain/PackageName/CompanyName/ProjectName/Features/ProjectNameFeatureNames.cs → aspnet-core/templates/micro/content/src/PackageName.CompanyName.ProjectName.Domain.Shared/PackageName/CompanyName/ProjectName/Features/ProjectNameFeatureNames.cs
@ -0,0 +1,22 @@ |
|||
using Microsoft.Extensions.Logging; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.Data; |
|||
using Volo.Abp.DependencyInjection; |
|||
|
|||
namespace PackageName.CompanyName.ProjectName; |
|||
|
|||
public class ProjectNameDataSeedContributor : IDataSeedContributor, ITransientDependency |
|||
{ |
|||
private readonly ILogger<ProjectNameDataSeedContributor> _logger; |
|||
public ProjectNameDataSeedContributor(ILogger<ProjectNameDataSeedContributor> logger) |
|||
{ |
|||
_logger = logger; |
|||
} |
|||
|
|||
public Task SeedAsync(DataSeedContext context) |
|||
{ |
|||
_logger.LogInformation("Write your data seed logic here."); |
|||
|
|||
return Task.CompletedTask; |
|||
} |
|||
} |
|||
@ -1,49 +0,0 @@ |
|||
using Microsoft.EntityFrameworkCore; |
|||
using Microsoft.EntityFrameworkCore.Design; |
|||
using Microsoft.Extensions.Configuration; |
|||
using System.IO; |
|||
|
|||
namespace PackageName.CompanyName.ProjectName.EntityFrameworkCore; |
|||
public class ProjectNameDbContextFactory : IDesignTimeDbContextFactory<ProjectNameDbContext> |
|||
{ |
|||
public ProjectNameDbContext CreateDbContext(string[] args) |
|||
{ |
|||
var configuration = BuildConfiguration(); |
|||
var connectionString = configuration.GetConnectionString("ProjectName"); |
|||
|
|||
DbContextOptionsBuilder<ProjectNameDbContext> builder = null; |
|||
|
|||
#if MySQL
|
|||
builder = new DbContextOptionsBuilder<ProjectNameDbContext>() |
|||
.UseMySql(connectionString, ServerVersion.AutoDetect(connectionString)); |
|||
#elif SqlServer
|
|||
builder = new DbContextOptionsBuilder<ProjectNameDbContext>() |
|||
.UseSqlServer(connectionString); |
|||
#elif Sqlite
|
|||
builder = new DbContextOptionsBuilder<ProjectNameDbContext>() |
|||
.UseSqlite(connectionString); |
|||
#elif Oracle
|
|||
builder = new DbContextOptionsBuilder<ProjectNameDbContext>() |
|||
.UseOracle(connectionString); |
|||
#elif OracleDevart
|
|||
builder = (DbContextOptionsBuilder<ProjectNameDbContext>) new DbContextOptionsBuilder<ProjectNameDbContext>() |
|||
.UseOracle(connectionString); |
|||
#elif PostgreSql
|
|||
builder = new DbContextOptionsBuilder<ProjectNameDbContext>() |
|||
.UseNpgsql(connectionString); |
|||
#endif
|
|||
|
|||
return new ProjectNameDbContext(builder!.Options); |
|||
} |
|||
|
|||
private static IConfigurationRoot BuildConfiguration() |
|||
{ |
|||
var builder = new ConfigurationBuilder() |
|||
.SetBasePath(Path.Combine(Directory.GetCurrentDirectory(), "../../host/PackageName.CompanyName.ProjectName.DbMigrator/")) |
|||
.AddJsonFile("appsettings.json", optional: false) |
|||
.AddJsonFile("appsettings.Development.json", optional: true); |
|||
|
|||
return builder.Build(); |
|||
} |
|||
} |
|||
|
|||
Loading…
Reference in new issue