diff --git a/.github/workflows/template-test.yml b/.github/workflows/template-test.yml index 1418c231..bc5cab11 100644 --- a/.github/workflows/template-test.yml +++ b/.github/workflows/template-test.yml @@ -22,6 +22,7 @@ jobs: matrix: framework: [ 'net10.0', 'net8.0', 'net9.0' ] aspire: [ 'true', 'false' ] + use-admin: [ 'true', 'false' ] scenario: # Test all databases with RabbitMQ - { database: 'MySql', messagequeue: 'RabbitMQ' } @@ -38,7 +39,7 @@ jobs: - { database: 'MySql', messagequeue: 'NATS' } - { database: 'MySql', messagequeue: 'AzureServiceBus' } - { database: 'MySql', messagequeue: 'AmazonSQS' } - name: ${{ matrix.scenario.database }}-${{ matrix.scenario.messagequeue }}-${{ matrix.framework }}-aspire-${{ matrix.aspire }} + name: ${{ matrix.scenario.database }}-${{ matrix.scenario.messagequeue }}-${{ matrix.framework }}-aspire-${{ matrix.aspire }}-admin-${{ matrix.use-admin }} steps: - uses: actions/checkout@v3 @@ -68,53 +69,53 @@ jobs: - name: Install template locally run: dotnet new install . - - name: Generate project from template - ${{ matrix.scenario.database }}-${{ matrix.scenario.messagequeue }}-${{ matrix.framework }}-aspire-${{ matrix.aspire }} + - name: Generate project from template - ${{ matrix.scenario.database }}-${{ matrix.scenario.messagequeue }}-${{ matrix.framework }}-aspire-${{ matrix.aspire }}-admin-${{ matrix.use-admin }} run: | - mkdir -p test-projects/${{ matrix.scenario.database }}-${{ matrix.scenario.messagequeue }}-${{ matrix.framework }}-aspire-${{ matrix.aspire }} - cd test-projects/${{ matrix.scenario.database }}-${{ matrix.scenario.messagequeue }}-${{ matrix.framework }}-aspire-${{ matrix.aspire }} + mkdir -p test-projects/${{ matrix.scenario.database }}-${{ matrix.scenario.messagequeue }}-${{ matrix.framework }}-aspire-${{ matrix.aspire }}-admin-${{ matrix.use-admin }} + cd test-projects/${{ matrix.scenario.database }}-${{ matrix.scenario.messagequeue }}-${{ matrix.framework }}-aspire-${{ matrix.aspire }}-admin-${{ matrix.use-admin }} if [ "${{ matrix.aspire }}" == "true" ]; then - dotnet new netcorepal-web -n TestProject -F ${{ matrix.framework }} -D ${{ matrix.scenario.database }} -M ${{ matrix.scenario.messagequeue }} --UseAspire + dotnet new netcorepal-web -n TestProject -F ${{ matrix.framework }} -D ${{ matrix.scenario.database }} -M ${{ matrix.scenario.messagequeue }} --UseAspire --UseAdmin ${{ matrix.use-admin }} else - dotnet new netcorepal-web -n TestProject -F ${{ matrix.framework }} -D ${{ matrix.scenario.database }} -M ${{ matrix.scenario.messagequeue }} + dotnet new netcorepal-web -n TestProject -F ${{ matrix.framework }} -D ${{ matrix.scenario.database }} -M ${{ matrix.scenario.messagequeue }} --UseAdmin ${{ matrix.use-admin }} fi - name: Restore dependencies for generated project run: | - cd test-projects/${{ matrix.scenario.database }}-${{ matrix.scenario.messagequeue }}-${{ matrix.framework }}-aspire-${{ matrix.aspire }}/TestProject + cd test-projects/${{ matrix.scenario.database }}-${{ matrix.scenario.messagequeue }}-${{ matrix.framework }}-aspire-${{ matrix.aspire }}-admin-${{ matrix.use-admin }}/TestProject # Restore dependencies, but allow missing preview packages if ! dotnet restore --ignore-failed-sources; then - echo "❌ RESTORE FAILED for ${{ matrix.scenario.database }}-${{ matrix.scenario.messagequeue }}-${{ matrix.framework }}-aspire-${{ matrix.aspire }}" + echo "❌ RESTORE FAILED for ${{ matrix.scenario.database }}-${{ matrix.scenario.messagequeue }}-${{ matrix.framework }}-aspire-${{ matrix.aspire }}-admin-${{ matrix.use-admin }}" exit 1 fi - name: Build generated project run: | - cd test-projects/${{ matrix.scenario.database }}-${{ matrix.scenario.messagequeue }}-${{ matrix.framework }}-aspire-${{ matrix.aspire }}/TestProject + cd test-projects/${{ matrix.scenario.database }}-${{ matrix.scenario.messagequeue }}-${{ matrix.framework }}-aspire-${{ matrix.aspire }}-admin-${{ matrix.use-admin }}/TestProject # Build the project - this must succeed if ! dotnet build --no-restore --configuration Release --verbosity minimal; then - echo "❌ BUILD FAILED for ${{ matrix.scenario.database }}-${{ matrix.scenario.messagequeue }}-${{ matrix.framework }}-aspire-${{ matrix.aspire }}" + echo "❌ BUILD FAILED for ${{ matrix.scenario.database }}-${{ matrix.scenario.messagequeue }}-${{ matrix.framework }}-aspire-${{ matrix.aspire }}-admin-${{ matrix.use-admin }}" echo "Build logs:" dotnet build --no-restore --configuration Release --verbosity normal exit 1 fi - echo "✅ BUILD SUCCEEDED for ${{ matrix.scenario.database }}-${{ matrix.scenario.messagequeue }}-${{ matrix.framework }}-aspire-${{ matrix.aspire }}" + echo "✅ BUILD SUCCEEDED for ${{ matrix.scenario.database }}-${{ matrix.scenario.messagequeue }}-${{ matrix.framework }}-aspire-${{ matrix.aspire }}-admin-${{ matrix.use-admin }}" - name: Run tests for generated project if: ${{ inputs.include-tests }} run: | - cd test-projects/${{ matrix.scenario.database }}-${{ matrix.scenario.messagequeue }}-${{ matrix.framework }}-aspire-${{ matrix.aspire }}/TestProject + cd test-projects/${{ matrix.scenario.database }}-${{ matrix.scenario.messagequeue }}-${{ matrix.framework }}-aspire-${{ matrix.aspire }}-admin-${{ matrix.use-admin }}/TestProject # Run tests - this must succeed if ! dotnet test --no-build --configuration Release \ --verbosity normal \ --logger "console;verbosity=normal"; then - echo "❌ TESTS FAILED for ${{ matrix.scenario.database }}-${{ matrix.scenario.messagequeue }}-${{ matrix.framework }}-aspire-${{ matrix.aspire }}" + echo "❌ TESTS FAILED for ${{ matrix.scenario.database }}-${{ matrix.scenario.messagequeue }}-${{ matrix.framework }}-aspire-${{ matrix.aspire }}-admin-${{ matrix.use-admin }}" exit 1 fi - echo "✅ TESTS SUCCEEDED for ${{ matrix.scenario.database }}-${{ matrix.scenario.messagequeue }}-${{ matrix.framework }}-aspire-${{ matrix.aspire }}" + echo "✅ TESTS SUCCEEDED for ${{ matrix.scenario.database }}-${{ matrix.scenario.messagequeue }}-${{ matrix.framework }}-aspire-${{ matrix.aspire }}-admin-${{ matrix.use-admin }}" - name: Verify project structure and templates run: | - cd test-projects/${{ matrix.scenario.database }}-${{ matrix.scenario.messagequeue }}-${{ matrix.framework }}-aspire-${{ matrix.aspire }}/TestProject + cd test-projects/${{ matrix.scenario.database }}-${{ matrix.scenario.messagequeue }}-${{ matrix.framework }}-aspire-${{ matrix.aspire }}-admin-${{ matrix.use-admin }}/TestProject echo "Project structure verification:" ls -la src/ echo "Framework verification in csproj:" @@ -141,10 +142,87 @@ jobs: echo "✅ Aspire projects correctly not generated" fi fi + if [ "${{ matrix.use-admin }}" == "true" ]; then + echo "Verifying Admin files are present when UseAdmin=true" + if [ -d "src/TestProject.Domain/AggregatesModel/UserAggregate" ]; then + echo "✅ UserAggregate found" + else + echo "❌ UserAggregate not found when UseAdmin=true" + exit 1 + fi + if [ -d "src/TestProject.Domain/AggregatesModel/RoleAggregate" ]; then + echo "✅ RoleAggregate found" + else + echo "❌ RoleAggregate not found when UseAdmin=true" + exit 1 + fi + if [ -d "src/TestProject.Domain/AggregatesModel/DeptAggregate" ]; then + echo "✅ DeptAggregate found" + else + echo "❌ DeptAggregate not found when UseAdmin=true" + exit 1 + fi + if [ -d "src/TestProject.Web/Endpoints/Identity/Admin" ]; then + echo "✅ Admin endpoints directory found" + else + echo "❌ Admin endpoints directory not found when UseAdmin=true" + exit 1 + fi + if [ -d "src/frontend" ]; then + echo "✅ Frontend directory found" + else + echo "❌ Frontend directory not found when UseAdmin=true" + exit 1 + fi + if [ -d "src/TestProject.Web/AppPermissions" ]; then + echo "✅ AppPermissions directory found" + else + echo "❌ AppPermissions directory not found when UseAdmin=true" + exit 1 + fi + else + echo "Verifying Admin files are absent when UseAdmin=false" + if [ -d "src/TestProject.Domain/AggregatesModel/UserAggregate" ]; then + echo "❌ UserAggregate found when it should be excluded" + exit 1 + else + echo "✅ UserAggregate correctly excluded" + fi + if [ -d "src/TestProject.Domain/AggregatesModel/RoleAggregate" ]; then + echo "❌ RoleAggregate found when it should be excluded" + exit 1 + else + echo "✅ RoleAggregate correctly excluded" + fi + if [ -d "src/TestProject.Domain/AggregatesModel/DeptAggregate" ]; then + echo "❌ DeptAggregate found when it should be excluded" + exit 1 + else + echo "✅ DeptAggregate correctly excluded" + fi + if [ -d "src/TestProject.Web/Endpoints/Identity/Admin" ]; then + echo "❌ Admin endpoints directory found when it should be excluded" + exit 1 + else + echo "✅ Admin endpoints directory correctly excluded" + fi + if [ -d "src/frontend" ]; then + echo "❌ Frontend directory found when it should be excluded" + exit 1 + else + echo "✅ Frontend directory correctly excluded" + fi + if [ -d "src/TestProject.Web/AppPermissions" ]; then + echo "❌ AppPermissions directory found when it should be excluded" + exit 1 + else + echo "✅ AppPermissions directory correctly excluded" + fi + fi - name: Verify solution file format run: | - cd test-projects/${{ matrix.scenario.database }}-${{ matrix.scenario.messagequeue }}-${{ matrix.framework }}-aspire-${{ matrix.aspire }}/TestProject + cd test-projects/${{ matrix.scenario.database }}-${{ matrix.scenario.messagequeue }}-${{ matrix.framework }}-aspire-${{ matrix.aspire }}-admin-${{ matrix.use-admin }}/TestProject echo "Solution file format verification for framework: ${{ matrix.framework }}" if [ "${{ matrix.framework }}" == "net8.0" ]; then # For net8.0, expect .sln file and no .slnx file @@ -182,16 +260,16 @@ jobs: - name: Verify Dockerfile template substitution run: | - cd test-projects/${{ matrix.scenario.database }}-${{ matrix.scenario.messagequeue }}-${{ matrix.framework }}-aspire-${{ matrix.aspire }}/TestProject + cd test-projects/${{ matrix.scenario.database }}-${{ matrix.scenario.messagequeue }}-${{ matrix.framework }}-aspire-${{ matrix.aspire }}-admin-${{ matrix.use-admin }}/TestProject echo "Dockerfile framework verification:" grep -E "(aspnet|sdk):" src/TestProject.Web/Dockerfile - name: Build Docker image for generated project if: ${{ inputs.include-docker-build }} run: | - cd test-projects/${{ matrix.scenario.database }}-${{ matrix.scenario.messagequeue }}-${{ matrix.framework }}-aspire-${{ matrix.aspire }}/TestProject + cd test-projects/${{ matrix.scenario.database }}-${{ matrix.scenario.messagequeue }}-${{ matrix.framework }}-aspire-${{ matrix.aspire }}-admin-${{ matrix.use-admin }}/TestProject # Build Docker image - this must succeed for Docker tests - CONFIG_NAME="${{ matrix.scenario.database }}-${{ matrix.scenario.messagequeue }}-${{ matrix.framework }}-aspire-${{ matrix.aspire }}" + CONFIG_NAME="${{ matrix.scenario.database }}-${{ matrix.scenario.messagequeue }}-${{ matrix.framework }}-aspire-${{ matrix.aspire }}-admin-${{ matrix.use-admin }}" IMAGE_TAG="testproject-$(echo "$CONFIG_NAME" | tr '[:upper:]' '[:lower:]'):latest" echo "Building Docker image with tag: $IMAGE_TAG" if ! docker build -f src/TestProject.Web/Dockerfile -t "$IMAGE_TAG" .; then @@ -438,4 +516,4 @@ jobs: - name: Uninstall template run: dotnet new uninstall . - if: always() + if: always() \ No newline at end of file diff --git a/.gitignore b/.gitignore index 4c46a271..512fcbff 100644 --- a/.gitignore +++ b/.gitignore @@ -28,6 +28,8 @@ x86/ [Aa][Rr][Mm]64/ bld/ [Bb]in/ +# Exception: allow frontend scripts bin directory +!template/src/frontend/scripts/**/bin/ [Oo]bj/ [Ll]og/ [Ll]ogs/ @@ -197,9 +199,10 @@ PublishScripts/ # NuGet Symbol Packages *.snupkg # The packages folder can be ignored because of Package Restore -**/[Pp]ackages/* +# Only ignore NuGet packages folders at project root level, not frontend workspace packages +/[Pp]ackages/* # except build/, which is used as an MSBuild target. -!**/[Pp]ackages/build/ +!/[Pp]ackages/build/ # Uncomment if necessary however generally it will be regenerated when needed #!**/[Pp]ackages/repositories.config # NuGet v3's project.json files produces more ignorable files @@ -387,3 +390,8 @@ FodyWeavers.xsd .idea/ *.sln.iml /.vs + +# Internal packages build outputs (generated by unbuild --stub, contains absolute paths) +src/frontend/internal/**/dist/ +src/frontend/packages/**/dist/ +src/frontend/scripts/**/dist/ diff --git a/README.md b/README.md index a9ea2609..95b28f5f 100644 --- a/README.md +++ b/README.md @@ -108,6 +108,7 @@ dotnet new list | `--MessageQueue` | `-M` | 消息队列提供程序 | `RabbitMQ`, `Kafka`, `AzureServiceBus`, `AmazonSQS`, `NATS`, `RedisStreams`, `Pulsar` | `RabbitMQ` | | `--UseAspire` | `-U` | 启用 Aspire Dashboard 支持 | `true`, `false` | `false` | | `--IncludeCopilotInstructions` | `-I` | 是否包含 Copilot 指令文件 | `true`, `false` | `true` | +| `--UseAdmin` | | 是否包含 Admin 功能(用户、角色、部门管理、权限系统、前端) | `true`, `false` | `false` | #### 使用示例 @@ -168,6 +169,19 @@ dotnet new netcorepal-web -n My.Project.Name -I false > **提示:** 创建项目后,请根据选择的数据库和消息队列配置,使用对应的基础设施初始化脚本来启动所需的服务。详细说明请参考生成项目中的 `scripts/README.md` 文件。 +### 关于 Admin 功能 + +当启用 `--UseAdmin` 选项时,模板会包含以下功能: + ++ **用户管理**:用户的创建、更新、删除、查询等功能 ++ **角色管理**:角色的创建、更新、删除、权限分配等功能 ++ **部门管理**:部门的创建、更新、删除、树形结构管理等功能 ++ **权限系统**:基于角色的权限控制(RBAC),支持权限码定义和验证 ++ **JWT 认证**:完整的 JWT Token 认证和刷新 Token 机制 ++ **前端界面**:基于 Vue 3 + Vben Admin 的管理后台界面 + +启用 Admin 功能后,系统会自动创建默认的管理员账户(用户名:`admin`,密码:`123456`)。 + ### 关于 Aspire Dashboard 当启用 `--UseAspire` 选项时,模板会生成以下额外的项目: diff --git a/scripts/gen-all-migrations.ps1 b/scripts/gen-all-migrations.ps1 new file mode 100644 index 00000000..b428265e --- /dev/null +++ b/scripts/gen-all-migrations.ps1 @@ -0,0 +1,111 @@ +# Generate migration scripts for all database + dotnet version combinations +# Output to template/src/ABC.Template.Infrastructure/MigrationsAll/Database-Framework directories + +$ErrorActionPreference = "Stop" +$TEMPLATE_ROOT = $PSScriptRoot | Split-Path -Parent +$INFRA_MIGRATIONS_PATH = Join-Path $TEMPLATE_ROOT "template\src\ABC.Template.Infrastructure\MigrationsAll" +$TMP_ROOT = Join-Path $env:TEMP "netcorepal-migrations-$(New-Guid)" + +# Database types +$DATABASES = @("MySql", "SqlServer", "PostgreSQL", "Sqlite", "GaussDB", "DMDB") +# Dotnet versions - check which SDKs are installed +$ALL_FRAMEWORKS = @("net8.0", "net9.0", "net10.0") +$INSTALLED_SDKS = dotnet --list-sdks | ForEach-Object { if ($_ -match '(\d+\.\d+\.\d+)') { $matches[1] } } +$FRAMEWORKS = @() +foreach ($fw in $ALL_FRAMEWORKS) { + $sdkVersion = if ($fw -eq "net8.0") { "8.0" } elseif ($fw -eq "net9.0") { "9.0" } else { "10.0" } + $hasSdk = $INSTALLED_SDKS | Where-Object { $_.StartsWith($sdkVersion) } + if ($hasSdk) { + $FRAMEWORKS += $fw + Write-Host "Found SDK for $fw, will generate migrations" + } else { + Write-Host "Warning: SDK for $fw not found, skipping" + } +} +if ($FRAMEWORKS.Count -eq 0) { + Write-Host "Error: No compatible SDKs found. Please install .NET 8.0, 9.0, or 10.0 SDK." + exit 1 +} + +# 1. Clear MigrationsAll directory before generation +Write-Host "==> Clearing $INFRA_MIGRATIONS_PATH ..." +if (Test-Path $INFRA_MIGRATIONS_PATH) { + Remove-Item -Recurse -Force $INFRA_MIGRATIONS_PATH +} +New-Item -ItemType Directory -Path $INFRA_MIGRATIONS_PATH -Force | Out-Null + +$MIGRATION_NAME = "Init" + +# Generate migrations for both UseAdmin=true and UseAdmin=false +$USE_ADMIN_VALUES = @($false, $true) + +foreach ($db in $DATABASES) { + foreach ($fw in $FRAMEWORKS) { + foreach ($useAdmin in $USE_ADMIN_VALUES) { + $adminSuffix = if ($useAdmin) { "-admin" } else { "" } + $PRJ_DIR = Join-Path $TMP_ROOT "${db}-${fw}${adminSuffix}" + $OUTDIR = Join-Path $INFRA_MIGRATIONS_PATH "${db}-${fw}${adminSuffix}" + + Write-Host "==> Cleaning $PRJ_DIR ..." + if (Test-Path $PRJ_DIR) { + Remove-Item -Recurse -Force $PRJ_DIR + } + + $adminParam = if ($useAdmin) { "--UseAdmin true" } else { "" } + Write-Host "==> Generating $db $fw project with UseAdmin=$useAdmin..." + if ($useAdmin) { + dotnet new netcorepal-web -n ABC.Template -F $fw -D $db -M RabbitMQ --UseAdmin true --output $PRJ_DIR + } else { + dotnet new netcorepal-web -n ABC.Template -F $fw -D $db -M RabbitMQ --output $PRJ_DIR + } + + $INFRA_DIR = Join-Path $PRJ_DIR "src\ABC.Template.Infrastructure" + + # Recursively clean the Migrations directory generated by dotnet new to avoid template pollution + $MIGRATIONS_DIR = Join-Path $INFRA_DIR "Migrations" + if (Test-Path $MIGRATIONS_DIR) { + Remove-Item -Recurse -Force $MIGRATIONS_DIR + } + + Write-Host "==> Running dotnet restore..." + Push-Location $PRJ_DIR + try { + dotnet restore --ignore-failed-sources + } finally { + Pop-Location + } + + Write-Host "==> Running dotnet build..." + Push-Location $PRJ_DIR + try { + dotnet build --no-restore + } finally { + Pop-Location + } + + Write-Host "==> Cleaning target migration directory..." + if (Test-Path $OUTDIR) { + Remove-Item -Recurse -Force $OUTDIR + } + + Write-Host "==> Generating migration $MIGRATION_NAME..." + Push-Location $INFRA_DIR + try { + dotnet ef migrations add $MIGRATION_NAME --output-dir Migrations + } finally { + Pop-Location + } + + New-Item -ItemType Directory -Path $OUTDIR -Force | Out-Null + $GENERATED_MIGRATIONS = Join-Path $INFRA_DIR "Migrations" + Copy-Item -Path "$GENERATED_MIGRATIONS\*" -Destination $OUTDIR -Recurse -Force + Write-Host "==> $db $fw UseAdmin=$useAdmin migration copied to $OUTDIR" + } + } +} + +Write-Host "==> Cleaning temporary directory..." +if (Test-Path $TMP_ROOT) { + Remove-Item -Recurse -Force $TMP_ROOT +} +Write-Host "All migrations generated successfully!" diff --git a/scripts/gen-all-migrations.sh b/scripts/gen-all-migrations.sh index 197ae9a3..b29437bc 100755 --- a/scripts/gen-all-migrations.sh +++ b/scripts/gen-all-migrations.sh @@ -12,38 +12,53 @@ DATABASES=(MySql SqlServer PostgreSQL Sqlite GaussDB DMDB) FRAMEWORKS=(net8.0 net9.0 net10.0) TEMPLATE_ROOT="$(pwd)" -INFRA_MIGRATIONS_PATH="$TEMPLATE_ROOT/template/src/ABC.Template.Infrastructure/Migrations" +INFRA_MIGRATIONS_PATH="$TEMPLATE_ROOT/template/src/ABC.Template.Infrastructure/MigrationsAll" TMP_ROOT="$(mktemp -d /tmp/netcorepal-migrations-XXXXXXXX)" -# 1. 生成前清空 Migrations 目录 +# 1. 生成前清空 MigrationsAll 目录 echo "==> 清空 $INFRA_MIGRATIONS_PATH ..." rm -rf "$INFRA_MIGRATIONS_PATH" mkdir -p "$INFRA_MIGRATIONS_PATH" MIGRATION_NAME=Init +# Generate migrations for both UseAdmin=true and UseAdmin=false for db in "${DATABASES[@]}"; do for fw in "${FRAMEWORKS[@]}"; do - PRJ_DIR="$TMP_ROOT/${db}-${fw}" - OUTDIR="$INFRA_MIGRATIONS_PATH/${db}-${fw}" - echo "==> 清理 $PRJ_DIR ..." - rm -rf "$PRJ_DIR" - echo "==> dotnet new 生成 $db $fw 项目..." - dotnet new netcorepal-web -n ABC.Template -F $fw -D $db -M RabbitMQ --output "$PRJ_DIR" - INFRA_DIR="$PRJ_DIR/src/ABC.Template.Infrastructure" - # 递归清理 dotnet new 生成的 Migrations 目录,避免模板污染 - rm -rf "$INFRA_DIR/Migrations" - echo "==> dotnet restore..." - (cd "$PRJ_DIR" && dotnet restore) - echo "==> dotnet build..." - (cd "$PRJ_DIR" && dotnet build --no-restore) - echo "==> 清理目标迁移目录..." - rm -rf "$OUTDIR" - echo "==> 生成迁移 $MIGRATION_NAME..." - (cd "$INFRA_DIR" && dotnet ef migrations add $MIGRATION_NAME --output-dir Migrations) - mkdir -p "$OUTDIR" - cp -r "$INFRA_DIR"/Migrations/* "$OUTDIR"/ - echo "==> $db $fw 迁移已拷贝到 $OUTDIR" + for useAdmin in false true; do + if [ "$useAdmin" = "true" ]; then + ADMIN_SUFFIX="-admin" + ADMIN_PARAM="--UseAdmin true" + else + ADMIN_SUFFIX="" + ADMIN_PARAM="" + fi + + PRJ_DIR="$TMP_ROOT/${db}-${fw}${ADMIN_SUFFIX}" + OUTDIR="$INFRA_MIGRATIONS_PATH/${db}-${fw}${ADMIN_SUFFIX}" + echo "==> 清理 $PRJ_DIR ..." + rm -rf "$PRJ_DIR" + echo "==> dotnet new 生成 $db $fw 项目 (UseAdmin=$useAdmin)..." + if [ "$useAdmin" = "true" ]; then + dotnet new netcorepal-web -n ABC.Template -F $fw -D $db -M RabbitMQ --UseAdmin true --output "$PRJ_DIR" + else + dotnet new netcorepal-web -n ABC.Template -F $fw -D $db -M RabbitMQ --output "$PRJ_DIR" + fi + INFRA_DIR="$PRJ_DIR/src/ABC.Template.Infrastructure" + # 递归清理 dotnet new 生成的 Migrations 目录,避免模板污染 + rm -rf "$INFRA_DIR/Migrations" + echo "==> dotnet restore..." + (cd "$PRJ_DIR" && dotnet restore) + echo "==> dotnet build..." + (cd "$PRJ_DIR" && dotnet build --no-restore) + echo "==> 清理目标迁移目录..." + rm -rf "$OUTDIR" + echo "==> 生成迁移 $MIGRATION_NAME..." + (cd "$INFRA_DIR" && dotnet ef migrations add $MIGRATION_NAME --output-dir Migrations) + mkdir -p "$OUTDIR" + cp -r "$INFRA_DIR"/Migrations/* "$OUTDIR"/ + echo "==> $db $fw UseAdmin=$useAdmin 迁移已拷贝到 $OUTDIR" + done done done diff --git a/template/.gitignore b/template/.gitignore index 7af8161b..d2ed0a3d 100644 --- a/template/.gitignore +++ b/template/.gitignore @@ -28,6 +28,8 @@ x86/ [Aa][Rr][Mm]64/ bld/ [Bb]in/ +# Exception: allow frontend scripts bin directory +!src/frontend/scripts/**/bin/ [Oo]bj/ [Ll]og/ [Ll]ogs/ @@ -197,9 +199,10 @@ PublishScripts/ # NuGet Symbol Packages *.snupkg # The packages folder can be ignored because of Package Restore -**/[Pp]ackages/* +# Only ignore NuGet packages folders at project root level, not frontend workspace packages +/[Pp]ackages/* # except build/, which is used as an MSBuild target. -!**/[Pp]ackages/build/ +!/[Pp]ackages/build/ # Uncomment if necessary however generally it will be regenerated when needed #!**/[Pp]ackages/repositories.config # NuGet v3's project.json files produces more ignorable files @@ -388,3 +391,8 @@ FodyWeavers.xsd .idea/ *.sln.iml /.vs + +# Internal packages build outputs (generated by unbuild --stub, contains absolute paths) +src/frontend/internal/**/dist/ +src/frontend/packages/**/dist/ +src/frontend/scripts/**/dist/ diff --git a/template/.template.config/template.json b/template/.template.config/template.json index 4c3784d4..39b3e5c8 100644 --- a/template/.template.config/template.json +++ b/template/.template.config/template.json @@ -1,303 +1,673 @@ { - "$schema": "http://json.schemastore.org/template", - "author": "NetCorePal", - "classifications": [ "Web" ], - "tags": { - "language": "C#", - "type": "project" + "$schema": "http://json.schemastore.org/template", + "author": "NetCorePal", + "classifications": [ "Web" ], + "tags": { + "language": "C#", + "type": "project" + }, + "identity": "NetCorePal.Web", + "name": "NetCorePal Cloud Web Application", + "shortName": "netcorepal-web", + "sourceName": "ABC.Template", + "preferNameDirectory": true, + "symbols": { + "Framework": { + "type": "parameter", + "description": "The target framework for the project", + "datatype": "choice", + "choices": [ + { + "choice": "net8.0", + "description": "Target .NET 8.0" + }, + { + "choice": "net9.0", + "description": "Target .NET 9.0" + }, + { + "choice": "net10.0", + "description": "Target .NET 10.0" + } + ], + "defaultValue": "net10.0", + "replaces": "NETCOREPAL_FRAMEWORK" }, - "identity": "NetCorePal.Web", - "name": "NetCorePal Cloud Web Application", - "shortName": "netcorepal-web", - "sourceName": "ABC.Template", - "preferNameDirectory": true, - "symbols": { - "Framework": { - "type": "parameter", - "description": "The target framework for the project", - "datatype": "choice", - "choices": [ - { - "choice": "net8.0", - "description": "Target .NET 8.0" - }, - { - "choice": "net9.0", - "description": "Target .NET 9.0" - }, - { - "choice": "net10.0", - "description": "Target .NET 10.0" - } - ], - "defaultValue": "net10.0", - "replaces": "NETCOREPAL_FRAMEWORK" - }, - "Database": { - "type": "parameter", - "description": "The database provider to use", - "datatype": "choice", - "choices": [ - { - "choice": "SqlServer", - "description": "Use Microsoft SQL Server" - }, - { - "choice": "MySql", - "description": "Use MySQL with Pomelo provider" - }, - { - "choice": "PostgreSQL", - "description": "Use PostgreSQL" - }, - { - "choice": "Sqlite", - "description": "Use SQLite" - }, - { - "choice": "GaussDB", - "description": "Use GaussDB" - }, - { - "choice": "DMDB", - "description": "Use DMDB" - }, - { - "choice": "MongoDB", - "description": "Use MongoDB" - } - ], - "defaultValue": "MySql" - }, - "MessageQueue": { - "type": "parameter", - "description": "The message queue provider to use with CAP", - "datatype": "choice", - "choices": [ - { - "choice": "RabbitMQ", - "description": "Use RabbitMQ" - }, - { - "choice": "Kafka", - "description": "Use Apache Kafka" - }, - { - "choice": "AzureServiceBus", - "description": "Use Azure Service Bus" - }, - { - "choice": "AmazonSQS", - "description": "Use Amazon SQS" - }, - { - "choice": "NATS", - "description": "Use NATS" - }, - { - "choice": "RedisStreams", - "description": "Use Redis Streams" - }, - { - "choice": "Pulsar", - "description": "Use Apache Pulsar" - } - ], - "defaultValue": "RabbitMQ" - }, - "UseAspire": { - "type": "parameter", - "datatype": "bool", - "defaultValue": "false", - "description": "Enable Aspire Dashboard support for observability and orchestration" - }, - "IncludeCopilotInstructions": { - "type": "parameter", - "datatype": "bool", - "defaultValue": "true", - "description": "Include Copilot instructions files (.github directory) in the generated template" - }, - "SdkVersion": { - "type": "generated", - "generator": "switch", - "dataType": "string", - "parameters": { - "cases": [ - { "condition": "(Framework == \"net8.0\")", "value": "8.0.100" }, - { "condition": "(Framework == \"net9.0\")", "value": "9.0.100" }, - { "condition": "(Framework == \"net10.0\")", "value": "10.0.100" } - ], - "defaultValue": "9.0.100" - }, - "replaces": "NETCOREPAL_SDK_VERSION" - }, - "DockerFramework": { - "type": "generated", - "generator": "switch", - "dataType": "string", - "parameters": { - "cases": [ - { "condition": "(Framework == \"net8.0\")", "value": "8.0" }, - { "condition": "(Framework == \"net9.0\")", "value": "9.0" }, - { "condition": "(Framework == \"net10.0\")", "value": "10.0" } - ], - "defaultValue": "9.0" - }, - "replaces": "NETCOREPAL_DOCKER_FRAMEWORK" - }, - "UseSqlServer": { - "type": "computed", - "value": "(Database == \"SqlServer\")" - }, - "UseMySql": { - "type": "computed", - "value": "(Database == \"MySql\")" - }, - "UsePostgreSQL": { - "type": "computed", - "value": "(Database == \"PostgreSQL\")" - }, - "UseSqlite": { - "type": "computed", - "value": "(Database == \"Sqlite\")" - }, - "UseGaussDB": { - "type": "computed", - "value": "(Database == \"GaussDB\")" - }, - "UseDMDB": { - "type": "computed", - "value": "(Database == \"DMDB\")" - }, - "UseMongoDB": { - "type": "computed", - "value": "(Database == \"MongoDB\")" - }, - "UseRabbitMQ": { - "type": "computed", - "value": "(MessageQueue == \"RabbitMQ\")" - }, - "UseKafka": { - "type": "computed", - "value": "(MessageQueue == \"Kafka\")" - }, - "UseAzureServiceBus": { - "type": "computed", - "value": "(MessageQueue == \"AzureServiceBus\")" - }, - "UseAmazonSQS": { - "type": "computed", - "value": "(MessageQueue == \"AmazonSQS\")" - }, - "UseNATS": { - "type": "computed", - "value": "(MessageQueue == \"NATS\")" - }, - "UseRedisStreams": { - "type": "computed", - "value": "(MessageQueue == \"RedisStreams\")" - }, - "UsePulsar": { - "type": "computed", - "value": "(MessageQueue == \"Pulsar\")" + "Database": { + "type": "parameter", + "description": "The database provider to use", + "datatype": "choice", + "choices": [ + { + "choice": "SqlServer", + "description": "Use Microsoft SQL Server" + }, + { + "choice": "MySql", + "description": "Use MySQL with Pomelo provider" + }, + { + "choice": "PostgreSQL", + "description": "Use PostgreSQL" + }, + { + "choice": "Sqlite", + "description": "Use SQLite" + }, + { + "choice": "GaussDB", + "description": "Use GaussDB" + }, + { + "choice": "DMDB", + "description": "Use DMDB" + }, + { + "choice": "MongoDB", + "description": "Use MongoDB" } + ], + "defaultValue": "MySql" }, - "sources": [ + "MessageQueue": { + "type": "parameter", + "description": "The message queue provider to use with CAP", + "datatype": "choice", + "choices": [ { - "modifiers": [ - { "condition": "(!IncludeCopilotInstructions)", "exclude": [ ".github/**" ] }, - { "condition": "(Framework == \"net8.0\")", "exclude": [ "*.slnx" ] }, - { "condition": "(Framework == \"net9.0\" || Framework == \"net10.0\")", "exclude": [ "*.sln" ] }, - { "condition": "(!UseAspire)", "exclude": [ "src/ABC.Template.AppHost/**", "src/ABC.Template.ServiceDefaults/**", "test/ABC.Template.TestAppHost/**", "test/ABC.Template.AppHost.Tests/**" ] }, - - // SqlServer - { "condition": "(Database == \"SqlServer\" && Framework == \"net8.0\")", "rename": { - "src/ABC.Template.Infrastructure/MigrationsAll/SqlServer-net8.0": "src/ABC.Template.Infrastructure/Migrations" - } }, - { "condition": "(Database == \"SqlServer\" && Framework == \"net9.0\")", "rename": { - "src/ABC.Template.Infrastructure/MigrationsAll/SqlServer-net9.0": "src/ABC.Template.Infrastructure/Migrations" - } }, - { "condition": "(Database == \"SqlServer\" && Framework == \"net10.0\")", "rename": { - "src/ABC.Template.Infrastructure/MigrationsAll/SqlServer-net10.0": "src/ABC.Template.Infrastructure/Migrations" - } }, - { "condition": "(Database != \"SqlServer\" || Framework != \"net8.0\")", "exclude": [ "src/ABC.Template.Infrastructure/MigrationsAll/SqlServer-net8.0/**" ] }, - { "condition": "(Database != \"SqlServer\" || Framework != \"net9.0\")", "exclude": [ "src/ABC.Template.Infrastructure/MigrationsAll/SqlServer-net9.0/**" ] }, - { "condition": "(Database != \"SqlServer\" || Framework != \"net10.0\")", "exclude": [ "src/ABC.Template.Infrastructure/MigrationsAll/SqlServer-net10.0/**" ] }, + "choice": "RabbitMQ", + "description": "Use RabbitMQ" + }, + { + "choice": "Kafka", + "description": "Use Apache Kafka" + }, + { + "choice": "AzureServiceBus", + "description": "Use Azure Service Bus" + }, + { + "choice": "AmazonSQS", + "description": "Use Amazon SQS" + }, + { + "choice": "NATS", + "description": "Use NATS" + }, + { + "choice": "RedisStreams", + "description": "Use Redis Streams" + }, + { + "choice": "Pulsar", + "description": "Use Apache Pulsar" + } + ], + "defaultValue": "RabbitMQ" + }, + "UseAspire": { + "type": "parameter", + "datatype": "bool", + "defaultValue": "false", + "description": "Enable Aspire Dashboard support for observability and orchestration" + }, + "IncludeCopilotInstructions": { + "type": "parameter", + "datatype": "bool", + "defaultValue": "true", + "description": "Include Copilot instructions files (.github directory) in the generated template" + }, + "UseAdmin": { + "type": "parameter", + "datatype": "bool", + "defaultValue": "false", + "description": "Include Admin functionality (user, role, department management, permissions, and frontend)" + }, + "SdkVersion": { + "type": "generated", + "generator": "switch", + "dataType": "string", + "parameters": { + "cases": [ + { + "condition": "(Framework == \"net8.0\")", + "value": "8.0.100" + }, + { + "condition": "(Framework == \"net9.0\")", + "value": "9.0.100" + }, + { + "condition": "(Framework == \"net10.0\")", + "value": "10.0.100" + } + ], + "defaultValue": "9.0.100" + }, + "replaces": "NETCOREPAL_SDK_VERSION" + }, + "DockerFramework": { + "type": "generated", + "generator": "switch", + "dataType": "string", + "parameters": { + "cases": [ + { + "condition": "(Framework == \"net8.0\")", + "value": "8.0" + }, + { + "condition": "(Framework == \"net9.0\")", + "value": "9.0" + }, + { + "condition": "(Framework == \"net10.0\")", + "value": "10.0" + } + ], + "defaultValue": "9.0" + }, + "replaces": "NETCOREPAL_DOCKER_FRAMEWORK" + }, + "UseSqlServer": { + "type": "computed", + "value": "(Database == \"SqlServer\")" + }, + "UseMySql": { + "type": "computed", + "value": "(Database == \"MySql\")" + }, + "UsePostgreSQL": { + "type": "computed", + "value": "(Database == \"PostgreSQL\")" + }, + "UseSqlite": { + "type": "computed", + "value": "(Database == \"Sqlite\")" + }, + "UseGaussDB": { + "type": "computed", + "value": "(Database == \"GaussDB\")" + }, + "UseDMDB": { + "type": "computed", + "value": "(Database == \"DMDB\")" + }, + "UseMongoDB": { + "type": "computed", + "value": "(Database == \"MongoDB\")" + }, + "UseRabbitMQ": { + "type": "computed", + "value": "(MessageQueue == \"RabbitMQ\")" + }, + "UseKafka": { + "type": "computed", + "value": "(MessageQueue == \"Kafka\")" + }, + "UseAzureServiceBus": { + "type": "computed", + "value": "(MessageQueue == \"AzureServiceBus\")" + }, + "UseAmazonSQS": { + "type": "computed", + "value": "(MessageQueue == \"AmazonSQS\")" + }, + "UseNATS": { + "type": "computed", + "value": "(MessageQueue == \"NATS\")" + }, + "UseRedisStreams": { + "type": "computed", + "value": "(MessageQueue == \"RedisStreams\")" + }, + "UsePulsar": { + "type": "computed", + "value": "(MessageQueue == \"Pulsar\")" + } + }, + "sources": [ + { + "modifiers": [ + { + "condition": "(!IncludeCopilotInstructions)", + "exclude": [ ".github/**" ] + }, + { + "condition": "(Framework == \"net8.0\")", + "exclude": [ "*.slnx" ] + }, + { + "condition": "(Framework == \"net9.0\" || Framework == \"net10.0\")", + "exclude": [ "*.sln" ] + }, + { + "condition": "(!UseAspire)", + "exclude": [ "src/ABC.Template.AppHost/**", "src/ABC.Template.ServiceDefaults/**", "test/ABC.Template.TestAppHost/**", "test/ABC.Template.AppHost.Tests/**" ] + }, + { + "condition": "(!UseAdmin)", + "exclude": [ + "src/frontend/**", + "src/ABC.Template.Domain/AggregatesModel/UserAggregate/**", + "src/ABC.Template.Domain/AggregatesModel/RoleAggregate/**", + "src/ABC.Template.Domain/AggregatesModel/DeptAggregate/**", + "src/ABC.Template.Domain/DomainEvents/RoleEvents.cs", + "src/ABC.Template.Domain/DomainEvents/DeptEvents/**", + "src/ABC.Template.Domain/ErrorCodes.cs", + "src/ABC.Template.Infrastructure/EntityConfigurations/UserEntityTypeConfiguration.cs", + "src/ABC.Template.Infrastructure/EntityConfigurations/RoleEntityTypeConfiguration.cs", + "src/ABC.Template.Infrastructure/EntityConfigurations/DeptEntityTypeConfiguration.cs", + "src/ABC.Template.Infrastructure/Repositories/UserRepository.cs", + "src/ABC.Template.Infrastructure/Repositories/RoleRepository.cs", + "src/ABC.Template.Infrastructure/Repositories/DeptRepository.cs", + "src/ABC.Template.Web/AppPermissions/**", + "src/ABC.Template.Web/Application/Commands/Identity/**", + "src/ABC.Template.Web/Application/Queries/UserQuery.cs", + "src/ABC.Template.Web/Application/Queries/RoleQuery.cs", + "src/ABC.Template.Web/Application/Queries/DeptQuery.cs", + "src/ABC.Template.Web/Application/DomainEventHandlers/DeptInfoChangedDomainEventHandlerForUpdateUserDeptName.cs", + "src/ABC.Template.Web/Application/DomainEventHandlers/RoleInfoChangedDomainEventHandlerForUpdateUserRoleName.cs", + "src/ABC.Template.Web/Endpoints/Identity/**", + "src/ABC.Template.Web/Utils/SeedDatabaseExtension.cs", + "src/ABC.Template.Web/Utils/PasswordHasher.cs", + "src/ABC.Template.Web/Utils/TokenGenerator.cs", + "src/ABC.Template.Web/Extensions/ServiceCollectionExtensions.cs", + "test/ABC.Template.Web.Tests/UserTests.cs", + "test/ABC.Template.Web.Tests/RoleTests.cs", + "test/ABC.Template.Web.Tests/DeptTests.cs", + "test/ABC.Template.Web.Tests/Fixtures/AuthenticatedTestBase.cs" + ] + }, + { + "description": "Include turbo-run bin directory which is otherwise excluded by default", + "condition": "(UseAdmin)", + "include": [ + "src/frontend/scripts/turbo-run/bin/**" + ] + }, + // SqlServer + { + "condition": "(Database == \"SqlServer\" && Framework == \"net8.0\" && UseAdmin)", + "rename": { + "src/ABC.Template.Infrastructure/MigrationsAll/SqlServer-net8.0-admin": "src/ABC.Template.Infrastructure/Migrations" + } + }, + { + "condition": "(Database == \"SqlServer\" && Framework == \"net8.0\" && !UseAdmin)", + "rename": { + "src/ABC.Template.Infrastructure/MigrationsAll/SqlServer-net8.0": "src/ABC.Template.Infrastructure/Migrations" + } + }, + { + "condition": "(Database == \"SqlServer\" && Framework == \"net9.0\" && UseAdmin)", + "rename": { + "src/ABC.Template.Infrastructure/MigrationsAll/SqlServer-net9.0-admin": "src/ABC.Template.Infrastructure/Migrations" + } + }, + { + "condition": "(Database == \"SqlServer\" && Framework == \"net9.0\" && !UseAdmin)", + "rename": { + "src/ABC.Template.Infrastructure/MigrationsAll/SqlServer-net9.0": "src/ABC.Template.Infrastructure/Migrations" + } + }, + { + "condition": "(Database == \"SqlServer\" && Framework == \"net10.0\" && UseAdmin)", + "rename": { + "src/ABC.Template.Infrastructure/MigrationsAll/SqlServer-net10.0-admin": "src/ABC.Template.Infrastructure/Migrations" + } + }, + { + "condition": "(Database == \"SqlServer\" && Framework == \"net10.0\" && !UseAdmin)", + "rename": { + "src/ABC.Template.Infrastructure/MigrationsAll/SqlServer-net10.0": "src/ABC.Template.Infrastructure/Migrations" + } + }, + { + "condition": "(Database != \"SqlServer\" || Framework != \"net8.0\" || UseAdmin)", + "exclude": [ "src/ABC.Template.Infrastructure/MigrationsAll/SqlServer-net8.0/**" ] + }, + { + "condition": "(Database != \"SqlServer\" || Framework != \"net8.0\" || !UseAdmin)", + "exclude": [ "src/ABC.Template.Infrastructure/MigrationsAll/SqlServer-net8.0-admin/**" ] + }, + { + "condition": "(Database != \"SqlServer\" || Framework != \"net9.0\" || UseAdmin)", + "exclude": [ "src/ABC.Template.Infrastructure/MigrationsAll/SqlServer-net9.0/**" ] + }, + { + "condition": "(Database != \"SqlServer\" || Framework != \"net9.0\" || !UseAdmin)", + "exclude": [ "src/ABC.Template.Infrastructure/MigrationsAll/SqlServer-net9.0-admin/**" ] + }, + { + "condition": "(Database != \"SqlServer\" || Framework != \"net10.0\" || UseAdmin)", + "exclude": [ "src/ABC.Template.Infrastructure/MigrationsAll/SqlServer-net10.0/**" ] + }, + { + "condition": "(Database != \"SqlServer\" || Framework != \"net10.0\" || !UseAdmin)", + "exclude": [ "src/ABC.Template.Infrastructure/MigrationsAll/SqlServer-net10.0-admin/**" ] + }, - // MySql - { "condition": "(Database == \"MySql\" && Framework == \"net8.0\")", "rename": { - "src/ABC.Template.Infrastructure/MigrationsAll/MySql-net8.0": "src/ABC.Template.Infrastructure/Migrations" - } }, - { "condition": "(Database == \"MySql\" && Framework == \"net9.0\")", "rename": { - "src/ABC.Template.Infrastructure/MigrationsAll/MySql-net9.0": "src/ABC.Template.Infrastructure/Migrations" - } }, - { "condition": "(Database == \"MySql\" && Framework == \"net10.0\")", "rename": { - "src/ABC.Template.Infrastructure/MigrationsAll/MySql-net10.0": "src/ABC.Template.Infrastructure/Migrations" - } }, - { "condition": "(Database != \"MySql\" || Framework != \"net8.0\")", "exclude": [ "src/ABC.Template.Infrastructure/MigrationsAll/MySql-net8.0/**" ] }, - { "condition": "(Database != \"MySql\" || Framework != \"net9.0\")", "exclude": [ "src/ABC.Template.Infrastructure/MigrationsAll/MySql-net9.0/**" ] }, - { "condition": "(Database != \"MySql\" || Framework != \"net10.0\")", "exclude": [ "src/ABC.Template.Infrastructure/MigrationsAll/MySql-net10.0/**" ] }, + // MySql + { + "condition": "(Database == \"MySql\" && Framework == \"net8.0\" && UseAdmin)", + "rename": { + "src/ABC.Template.Infrastructure/MigrationsAll/MySql-net8.0-admin": "src/ABC.Template.Infrastructure/Migrations" + } + }, + { + "condition": "(Database == \"MySql\" && Framework == \"net8.0\" && !UseAdmin)", + "rename": { + "src/ABC.Template.Infrastructure/MigrationsAll/MySql-net8.0": "src/ABC.Template.Infrastructure/Migrations" + } + }, + { + "condition": "(Database == \"MySql\" && Framework == \"net9.0\" && UseAdmin)", + "rename": { + "src/ABC.Template.Infrastructure/MigrationsAll/MySql-net9.0-admin": "src/ABC.Template.Infrastructure/Migrations" + } + }, + { + "condition": "(Database == \"MySql\" && Framework == \"net9.0\" && !UseAdmin)", + "rename": { + "src/ABC.Template.Infrastructure/MigrationsAll/MySql-net9.0": "src/ABC.Template.Infrastructure/Migrations" + } + }, + { + "condition": "(Database == \"MySql\" && Framework == \"net10.0\" && UseAdmin)", + "rename": { + "src/ABC.Template.Infrastructure/MigrationsAll/MySql-net10.0-admin": "src/ABC.Template.Infrastructure/Migrations" + } + }, + { + "condition": "(Database == \"MySql\" && Framework == \"net10.0\" && !UseAdmin)", + "rename": { + "src/ABC.Template.Infrastructure/MigrationsAll/MySql-net10.0": "src/ABC.Template.Infrastructure/Migrations" + } + }, + { + "condition": "(Database != \"MySql\" || Framework != \"net8.0\" || UseAdmin)", + "exclude": [ "src/ABC.Template.Infrastructure/MigrationsAll/MySql-net8.0/**" ] + }, + { + "condition": "(Database != \"MySql\" || Framework != \"net8.0\" || !UseAdmin)", + "exclude": [ "src/ABC.Template.Infrastructure/MigrationsAll/MySql-net8.0-admin/**" ] + }, + { + "condition": "(Database != \"MySql\" || Framework != \"net9.0\" || UseAdmin)", + "exclude": [ "src/ABC.Template.Infrastructure/MigrationsAll/MySql-net9.0/**" ] + }, + { + "condition": "(Database != \"MySql\" || Framework != \"net9.0\" || !UseAdmin)", + "exclude": [ "src/ABC.Template.Infrastructure/MigrationsAll/MySql-net9.0-admin/**" ] + }, + { + "condition": "(Database != \"MySql\" || Framework != \"net10.0\" || UseAdmin)", + "exclude": [ "src/ABC.Template.Infrastructure/MigrationsAll/MySql-net10.0/**" ] + }, + { + "condition": "(Database != \"MySql\" || Framework != \"net10.0\" || !UseAdmin)", + "exclude": [ "src/ABC.Template.Infrastructure/MigrationsAll/MySql-net10.0-admin/**" ] + }, - // PostgreSQL - { "condition": "(Database == \"PostgreSQL\" && Framework == \"net8.0\")", "rename": { - "src/ABC.Template.Infrastructure/MigrationsAll/PostgreSQL-net8.0": "src/ABC.Template.Infrastructure/Migrations" - } }, - { "condition": "(Database == \"PostgreSQL\" && Framework == \"net9.0\")", "rename": { - "src/ABC.Template.Infrastructure/MigrationsAll/PostgreSQL-net9.0": "src/ABC.Template.Infrastructure/Migrations" - } }, - { "condition": "(Database == \"PostgreSQL\" && Framework == \"net10.0\")", "rename": { - "src/ABC.Template.Infrastructure/MigrationsAll/PostgreSQL-net10.0": "src/ABC.Template.Infrastructure/Migrations" - } }, - { "condition": "(Database != \"PostgreSQL\" || Framework != \"net8.0\")", "exclude": [ "src/ABC.Template.Infrastructure/MigrationsAll/PostgreSQL-net8.0/**" ] }, - { "condition": "(Database != \"PostgreSQL\" || Framework != \"net9.0\")", "exclude": [ "src/ABC.Template.Infrastructure/MigrationsAll/PostgreSQL-net9.0/**" ] }, - { "condition": "(Database != \"PostgreSQL\" || Framework != \"net10.0\")", "exclude": [ "src/ABC.Template.Infrastructure/MigrationsAll/PostgreSQL-net10.0/**" ] }, + // PostgreSQL + { + "condition": "(Database == \"PostgreSQL\" && Framework == \"net8.0\" && UseAdmin)", + "rename": { + "src/ABC.Template.Infrastructure/MigrationsAll/PostgreSQL-net8.0-admin": "src/ABC.Template.Infrastructure/Migrations" + } + }, + { + "condition": "(Database == \"PostgreSQL\" && Framework == \"net8.0\" && !UseAdmin)", + "rename": { + "src/ABC.Template.Infrastructure/MigrationsAll/PostgreSQL-net8.0": "src/ABC.Template.Infrastructure/Migrations" + } + }, + { + "condition": "(Database == \"PostgreSQL\" && Framework == \"net9.0\" && UseAdmin)", + "rename": { + "src/ABC.Template.Infrastructure/MigrationsAll/PostgreSQL-net9.0-admin": "src/ABC.Template.Infrastructure/Migrations" + } + }, + { + "condition": "(Database == \"PostgreSQL\" && Framework == \"net9.0\" && !UseAdmin)", + "rename": { + "src/ABC.Template.Infrastructure/MigrationsAll/PostgreSQL-net9.0": "src/ABC.Template.Infrastructure/Migrations" + } + }, + { + "condition": "(Database == \"PostgreSQL\" && Framework == \"net10.0\" && UseAdmin)", + "rename": { + "src/ABC.Template.Infrastructure/MigrationsAll/PostgreSQL-net10.0-admin": "src/ABC.Template.Infrastructure/Migrations" + } + }, + { + "condition": "(Database == \"PostgreSQL\" && Framework == \"net10.0\" && !UseAdmin)", + "rename": { + "src/ABC.Template.Infrastructure/MigrationsAll/PostgreSQL-net10.0": "src/ABC.Template.Infrastructure/Migrations" + } + }, + { + "condition": "(Database != \"PostgreSQL\" || Framework != \"net8.0\" || UseAdmin)", + "exclude": [ "src/ABC.Template.Infrastructure/MigrationsAll/PostgreSQL-net8.0/**" ] + }, + { + "condition": "(Database != \"PostgreSQL\" || Framework != \"net8.0\" || !UseAdmin)", + "exclude": [ "src/ABC.Template.Infrastructure/MigrationsAll/PostgreSQL-net8.0-admin/**" ] + }, + { + "condition": "(Database != \"PostgreSQL\" || Framework != \"net9.0\" || UseAdmin)", + "exclude": [ "src/ABC.Template.Infrastructure/MigrationsAll/PostgreSQL-net9.0/**" ] + }, + { + "condition": "(Database != \"PostgreSQL\" || Framework != \"net9.0\" || !UseAdmin)", + "exclude": [ "src/ABC.Template.Infrastructure/MigrationsAll/PostgreSQL-net9.0-admin/**" ] + }, + { + "condition": "(Database != \"PostgreSQL\" || Framework != \"net10.0\" || UseAdmin)", + "exclude": [ "src/ABC.Template.Infrastructure/MigrationsAll/PostgreSQL-net10.0/**" ] + }, + { + "condition": "(Database != \"PostgreSQL\" || Framework != \"net10.0\" || !UseAdmin)", + "exclude": [ "src/ABC.Template.Infrastructure/MigrationsAll/PostgreSQL-net10.0-admin/**" ] + }, - // Sqlite - { "condition": "(Database == \"Sqlite\" && Framework == \"net8.0\")", "rename": { - "src/ABC.Template.Infrastructure/MigrationsAll/Sqlite-net8.0": "src/ABC.Template.Infrastructure/Migrations" - } }, - { "condition": "(Database == \"Sqlite\" && Framework == \"net9.0\")", "rename": { - "src/ABC.Template.Infrastructure/MigrationsAll/Sqlite-net9.0": "src/ABC.Template.Infrastructure/Migrations" - } }, - { "condition": "(Database == \"Sqlite\" && Framework == \"net10.0\")", "rename": { - "src/ABC.Template.Infrastructure/MigrationsAll/Sqlite-net10.0": "src/ABC.Template.Infrastructure/Migrations" - } }, - { "condition": "(Database != \"Sqlite\" || Framework != \"net8.0\")", "exclude": [ "src/ABC.Template.Infrastructure/MigrationsAll/Sqlite-net8.0/**" ] }, - { "condition": "(Database != \"Sqlite\" || Framework != \"net9.0\")", "exclude": [ "src/ABC.Template.Infrastructure/MigrationsAll/Sqlite-net9.0/**" ] }, - { "condition": "(Database != \"Sqlite\" || Framework != \"net10.0\")", "exclude": [ "src/ABC.Template.Infrastructure/MigrationsAll/Sqlite-net10.0/**" ] }, + // Sqlite + { + "condition": "(Database == \"Sqlite\" && Framework == \"net8.0\" && UseAdmin)", + "rename": { + "src/ABC.Template.Infrastructure/MigrationsAll/Sqlite-net8.0-admin": "src/ABC.Template.Infrastructure/Migrations" + } + }, + { + "condition": "(Database == \"Sqlite\" && Framework == \"net8.0\" && !UseAdmin)", + "rename": { + "src/ABC.Template.Infrastructure/MigrationsAll/Sqlite-net8.0": "src/ABC.Template.Infrastructure/Migrations" + } + }, + { + "condition": "(Database == \"Sqlite\" && Framework == \"net9.0\" && UseAdmin)", + "rename": { + "src/ABC.Template.Infrastructure/MigrationsAll/Sqlite-net9.0-admin": "src/ABC.Template.Infrastructure/Migrations" + } + }, + { + "condition": "(Database == \"Sqlite\" && Framework == \"net9.0\" && !UseAdmin)", + "rename": { + "src/ABC.Template.Infrastructure/MigrationsAll/Sqlite-net9.0": "src/ABC.Template.Infrastructure/Migrations" + } + }, + { + "condition": "(Database == \"Sqlite\" && Framework == \"net10.0\" && UseAdmin)", + "rename": { + "src/ABC.Template.Infrastructure/MigrationsAll/Sqlite-net10.0-admin": "src/ABC.Template.Infrastructure/Migrations" + } + }, + { + "condition": "(Database == \"Sqlite\" && Framework == \"net10.0\" && !UseAdmin)", + "rename": { + "src/ABC.Template.Infrastructure/MigrationsAll/Sqlite-net10.0": "src/ABC.Template.Infrastructure/Migrations" + } + }, + { + "condition": "(Database != \"Sqlite\" || Framework != \"net8.0\" || UseAdmin)", + "exclude": [ "src/ABC.Template.Infrastructure/MigrationsAll/Sqlite-net8.0/**" ] + }, + { + "condition": "(Database != \"Sqlite\" || Framework != \"net8.0\" || !UseAdmin)", + "exclude": [ "src/ABC.Template.Infrastructure/MigrationsAll/Sqlite-net8.0-admin/**" ] + }, + { + "condition": "(Database != \"Sqlite\" || Framework != \"net9.0\" || UseAdmin)", + "exclude": [ "src/ABC.Template.Infrastructure/MigrationsAll/Sqlite-net9.0/**" ] + }, + { + "condition": "(Database != \"Sqlite\" || Framework != \"net9.0\" || !UseAdmin)", + "exclude": [ "src/ABC.Template.Infrastructure/MigrationsAll/Sqlite-net9.0-admin/**" ] + }, + { + "condition": "(Database != \"Sqlite\" || Framework != \"net10.0\" || UseAdmin)", + "exclude": [ "src/ABC.Template.Infrastructure/MigrationsAll/Sqlite-net10.0/**" ] + }, + { + "condition": "(Database != \"Sqlite\" || Framework != \"net10.0\" || !UseAdmin)", + "exclude": [ "src/ABC.Template.Infrastructure/MigrationsAll/Sqlite-net10.0-admin/**" ] + }, - // GaussDB - { "condition": "(Database == \"GaussDB\" && Framework == \"net8.0\")", "rename": { - "src/ABC.Template.Infrastructure/MigrationsAll/GaussDB-net8.0": "src/ABC.Template.Infrastructure/Migrations" - } }, - { "condition": "(Database == \"GaussDB\" && Framework == \"net9.0\")", "rename": { - "src/ABC.Template.Infrastructure/MigrationsAll/GaussDB-net9.0": "src/ABC.Template.Infrastructure/Migrations" - } }, - { "condition": "(Database == \"GaussDB\" && Framework == \"net10.0\")", "rename": { - "src/ABC.Template.Infrastructure/MigrationsAll/GaussDB-net10.0": "src/ABC.Template.Infrastructure/Migrations" - } }, - { "condition": "(Database != \"GaussDB\" || Framework != \"net8.0\")", "exclude": [ "src/ABC.Template.Infrastructure/MigrationsAll/GaussDB-net8.0/**" ] }, - { "condition": "(Database != \"GaussDB\" || Framework != \"net9.0\")", "exclude": [ "src/ABC.Template.Infrastructure/MigrationsAll/GaussDB-net9.0/**" ] }, - { "condition": "(Database != \"GaussDB\" || Framework != \"net10.0\")", "exclude": [ "src/ABC.Template.Infrastructure/MigrationsAll/GaussDB-net10.0/**" ] }, + // GaussDB + { + "condition": "(Database == \"GaussDB\" && Framework == \"net8.0\" && UseAdmin)", + "rename": { + "src/ABC.Template.Infrastructure/MigrationsAll/GaussDB-net8.0-admin": "src/ABC.Template.Infrastructure/Migrations" + } + }, + { + "condition": "(Database == \"GaussDB\" && Framework == \"net8.0\" && !UseAdmin)", + "rename": { + "src/ABC.Template.Infrastructure/MigrationsAll/GaussDB-net8.0": "src/ABC.Template.Infrastructure/Migrations" + } + }, + { + "condition": "(Database == \"GaussDB\" && Framework == \"net9.0\" && UseAdmin)", + "rename": { + "src/ABC.Template.Infrastructure/MigrationsAll/GaussDB-net9.0-admin": "src/ABC.Template.Infrastructure/Migrations" + } + }, + { + "condition": "(Database == \"GaussDB\" && Framework == \"net9.0\" && !UseAdmin)", + "rename": { + "src/ABC.Template.Infrastructure/MigrationsAll/GaussDB-net9.0": "src/ABC.Template.Infrastructure/Migrations" + } + }, + { + "condition": "(Database == \"GaussDB\" && Framework == \"net10.0\" && UseAdmin)", + "rename": { + "src/ABC.Template.Infrastructure/MigrationsAll/GaussDB-net10.0-admin": "src/ABC.Template.Infrastructure/Migrations" + } + }, + { + "condition": "(Database == \"GaussDB\" && Framework == \"net10.0\" && !UseAdmin)", + "rename": { + "src/ABC.Template.Infrastructure/MigrationsAll/GaussDB-net10.0": "src/ABC.Template.Infrastructure/Migrations" + } + }, + { + "condition": "(Database != \"GaussDB\" || Framework != \"net8.0\" || UseAdmin)", + "exclude": [ "src/ABC.Template.Infrastructure/MigrationsAll/GaussDB-net8.0/**" ] + }, + { + "condition": "(Database != \"GaussDB\" || Framework != \"net8.0\" || !UseAdmin)", + "exclude": [ "src/ABC.Template.Infrastructure/MigrationsAll/GaussDB-net8.0-admin/**" ] + }, + { + "condition": "(Database != \"GaussDB\" || Framework != \"net9.0\" || UseAdmin)", + "exclude": [ "src/ABC.Template.Infrastructure/MigrationsAll/GaussDB-net9.0/**" ] + }, + { + "condition": "(Database != \"GaussDB\" || Framework != \"net9.0\" || !UseAdmin)", + "exclude": [ "src/ABC.Template.Infrastructure/MigrationsAll/GaussDB-net9.0-admin/**" ] + }, + { + "condition": "(Database != \"GaussDB\" || Framework != \"net10.0\" || UseAdmin)", + "exclude": [ "src/ABC.Template.Infrastructure/MigrationsAll/GaussDB-net10.0/**" ] + }, + { + "condition": "(Database != \"GaussDB\" || Framework != \"net10.0\" || !UseAdmin)", + "exclude": [ "src/ABC.Template.Infrastructure/MigrationsAll/GaussDB-net10.0-admin/**" ] + }, - // DMDB - { "condition": "(Database == \"DMDB\" && Framework == \"net8.0\")", "rename": { - "src/ABC.Template.Infrastructure/MigrationsAll/DMDB-net8.0": "src/ABC.Template.Infrastructure/Migrations" - } }, - { "condition": "(Database == \"DMDB\" && Framework == \"net9.0\")", "rename": { - "src/ABC.Template.Infrastructure/MigrationsAll/DMDB-net9.0": "src/ABC.Template.Infrastructure/Migrations" - } }, - { "condition": "(Database == \"DMDB\" && Framework == \"net10.0\")", "rename": { - "src/ABC.Template.Infrastructure/MigrationsAll/DMDB-net10.0": "src/ABC.Template.Infrastructure/Migrations" - } }, - { "condition": "(Database != \"DMDB\" || Framework != \"net8.0\")", "exclude": [ "src/ABC.Template.Infrastructure/MigrationsAll/DMDB-net8.0/**" ] }, - { "condition": "(Database != \"DMDB\" || Framework != \"net9.0\")", "exclude": [ "src/ABC.Template.Infrastructure/MigrationsAll/DMDB-net9.0/**" ] }, - { "condition": "(Database != \"DMDB\" || Framework != \"net10.0\")", "exclude": [ "src/ABC.Template.Infrastructure/MigrationsAll/DMDB-net10.0/**" ] }, - { "condition": "(Database != \"DMDB\")", "exclude": [ "src/ABC.Template.Infrastructure/MyDmDateTimeOffsetTypeMapping.cs" ] }, + // DMDB + { + "condition": "(Database == \"DMDB\" && Framework == \"net8.0\" && UseAdmin)", + "rename": { + "src/ABC.Template.Infrastructure/MigrationsAll/DMDB-net8.0-admin": "src/ABC.Template.Infrastructure/Migrations" + } + }, + { + "condition": "(Database == \"DMDB\" && Framework == \"net8.0\" && !UseAdmin)", + "rename": { + "src/ABC.Template.Infrastructure/MigrationsAll/DMDB-net8.0": "src/ABC.Template.Infrastructure/Migrations" + } + }, + { + "condition": "(Database == \"DMDB\" && Framework == \"net9.0\" && UseAdmin)", + "rename": { + "src/ABC.Template.Infrastructure/MigrationsAll/DMDB-net9.0-admin": "src/ABC.Template.Infrastructure/Migrations" + } + }, + { + "condition": "(Database == \"DMDB\" && Framework == \"net9.0\" && !UseAdmin)", + "rename": { + "src/ABC.Template.Infrastructure/MigrationsAll/DMDB-net9.0": "src/ABC.Template.Infrastructure/Migrations" + } + }, + { + "condition": "(Database == \"DMDB\" && Framework == \"net10.0\" && UseAdmin)", + "rename": { + "src/ABC.Template.Infrastructure/MigrationsAll/DMDB-net10.0-admin": "src/ABC.Template.Infrastructure/Migrations" + } + }, + { + "condition": "(Database == \"DMDB\" && Framework == \"net10.0\" && !UseAdmin)", + "rename": { + "src/ABC.Template.Infrastructure/MigrationsAll/DMDB-net10.0": "src/ABC.Template.Infrastructure/Migrations" + } + }, + { + "condition": "(Database != \"DMDB\" || Framework != \"net8.0\" || UseAdmin)", + "exclude": [ "src/ABC.Template.Infrastructure/MigrationsAll/DMDB-net8.0/**" ] + }, + { + "condition": "(Database != \"DMDB\" || Framework != \"net8.0\" || !UseAdmin)", + "exclude": [ "src/ABC.Template.Infrastructure/MigrationsAll/DMDB-net8.0-admin/**" ] + }, + { + "condition": "(Database != \"DMDB\" || Framework != \"net9.0\" || UseAdmin)", + "exclude": [ "src/ABC.Template.Infrastructure/MigrationsAll/DMDB-net9.0/**" ] + }, + { + "condition": "(Database != \"DMDB\" || Framework != \"net9.0\" || !UseAdmin)", + "exclude": [ "src/ABC.Template.Infrastructure/MigrationsAll/DMDB-net9.0-admin/**" ] + }, + { + "condition": "(Database != \"DMDB\" || Framework != \"net10.0\" || UseAdmin)", + "exclude": [ "src/ABC.Template.Infrastructure/MigrationsAll/DMDB-net10.0/**" ] + }, + { + "condition": "(Database != \"DMDB\" || Framework != \"net10.0\" || !UseAdmin)", + "exclude": [ "src/ABC.Template.Infrastructure/MigrationsAll/DMDB-net10.0-admin/**" ] + }, + { + "condition": "(Database != \"DMDB\")", + "exclude": [ "src/ABC.Template.Infrastructure/MyDmDateTimeOffsetTypeMapping.cs" ] + }, - // MongoDB - { "condition": "(Database == \"MongoDB\")", "exclude": [ "src/ABC.Template.Infrastructure/MigrationsAll" ] } - ] + // MongoDB + { + "condition": "(Database == \"MongoDB\")", + "exclude": [ "src/ABC.Template.Infrastructure/MigrationsAll" ] } - ] + ] + } + ] } diff --git a/template/Directory.Packages.props b/template/Directory.Packages.props index e84680b3..63bc3e02 100644 --- a/template/Directory.Packages.props +++ b/template/Directory.Packages.props @@ -140,6 +140,9 @@ + + + diff --git a/template/src/ABC.Template.AppHost/ABC.Template.AppHost.csproj b/template/src/ABC.Template.AppHost/ABC.Template.AppHost.csproj index 40d3c21d..ddec8719 100644 --- a/template/src/ABC.Template.AppHost/ABC.Template.AppHost.csproj +++ b/template/src/ABC.Template.AppHost/ABC.Template.AppHost.csproj @@ -35,6 +35,9 @@ + + + diff --git a/template/src/ABC.Template.AppHost/Program.cs b/template/src/ABC.Template.AppHost/Program.cs index 610d65e7..23199955 100644 --- a/template/src/ABC.Template.AppHost/Program.cs +++ b/template/src/ABC.Template.AppHost/Program.cs @@ -94,7 +94,7 @@ //#endif // Add web project with infrastructure dependencies -builder.AddProject("web") +var web = builder.AddProject("web") .WithExternalHttpEndpoints() .WithHttpHealthCheck("/health") .WithReference(redis) @@ -135,4 +135,16 @@ //#endif ; +//#if (UseAdmin) +// Add frontend project +var frontend = builder.AddJavaScriptApp("frontend", "../frontend") + .WithPnpm() + .WithDeveloperCertificateTrust(true) + .WithHttpEndpoint(port: 5666, env: "VITE_PORT", name: "http", isProxied: false) + .WithExternalHttpEndpoints() + .WithEnvironment("VITE_API_BASE", web.GetEndpoint("http")) + .WithReference(web) + .WaitFor(web); +//#endif + await builder.Build().RunAsync(); diff --git a/template/src/ABC.Template.Domain/AggregatesModel/DeliverAggregate/DeliverRecord.cs b/template/src/ABC.Template.Domain/AggregatesModel/DeliverAggregate/DeliverRecord.cs deleted file mode 100644 index 56410d39..00000000 --- a/template/src/ABC.Template.Domain/AggregatesModel/DeliverAggregate/DeliverRecord.cs +++ /dev/null @@ -1,19 +0,0 @@ -using ABC.Template.Domain.AggregatesModel.OrderAggregate; - -namespace ABC.Template.Domain.AggregatesModel.DeliverAggregate; - -public partial record DeliverRecordId : IGuidStronglyTypedId; - -public class DeliverRecord : Entity, IAggregateRoot -{ - protected DeliverRecord() { } - - - public DeliverRecord(OrderId orderId) - { - this.OrderId = orderId; - } - - public OrderId OrderId { get; private set; } = default!; -} - diff --git a/template/src/ABC.Template.Domain/AggregatesModel/DeptAggregate/Dept.cs b/template/src/ABC.Template.Domain/AggregatesModel/DeptAggregate/Dept.cs new file mode 100644 index 00000000..76f657ef --- /dev/null +++ b/template/src/ABC.Template.Domain/AggregatesModel/DeptAggregate/Dept.cs @@ -0,0 +1,195 @@ +using System.ComponentModel.DataAnnotations.Schema; +using ABC.Template.Domain.DomainEvents.DeptEvents; +using ABC.Template.Domain; + +namespace ABC.Template.Domain.AggregatesModel.DeptAggregate; + +/// +/// 部门ID(强类型ID) +/// +public partial record DeptId : IInt64StronglyTypedId; + +/// +/// 部门聚合根 +/// 用于管理企业部门的层级结构 +/// +public class Dept : Entity, IAggregateRoot +{ + /// + /// 部门名称 + /// + public string Name { get; private set; } = string.Empty; + + /// + /// 备注 + /// + public string Remark { get; private set; } = string.Empty; + + /// + /// 上级部门ID + /// + public DeptId ParentId { get; private set; } = default!; + + /// + /// 状态(0=禁用,1=启用) + /// + public int Status { get; private set; } = 1; + + /// + /// 创建时间 + /// + public DateTimeOffset CreatedAt { get; init; } + + /// + /// 是否删除 + /// + public Deleted IsDeleted { get; private set; } = new Deleted(false); + + /// + /// 删除时间 + /// + public DeletedTime DeletedAt { get; private set; } = new DeletedTime(DateTimeOffset.UtcNow); + + /// + /// 更新时间 + /// + public UpdateTime UpdateTime { get; private set; } = new UpdateTime(DateTimeOffset.UtcNow); + + /// + /// 子部门(不映射到数据库,用于内存中的树形结构) + /// + [NotMapped] + public virtual ICollection Children { get; } = []; + + protected Dept() + { + } + + /// + /// 创建部门 + /// + /// 部门名称 + /// 备注 + /// 上级部门ID + /// 状态(0=禁用,1=启用) + public Dept(string name, string remark, DeptId parentId, int status) + { + CreatedAt =DateTimeOffset.UtcNow; + Name = name; + Remark = remark; + ParentId = parentId; + Status = status; + } + + /// + /// 更新部门信息 + /// + /// 部门名称 + /// 备注 + /// 上级部门ID + /// 状态(0=禁用,1=启用) + public void UpdateInfo(string name, string remark, DeptId parentId, int status) + { + Name = name; + Remark = remark; + ParentId = parentId; + Status = status; + UpdateTime = new UpdateTime(DateTimeOffset.UtcNow); + + AddDomainEvent(new DeptInfoChangedDomainEvent(this)); + } + + /// + /// 激活部门 + /// + public void Activate() + { + if (Status == 1) + { + throw new KnownException("部门已经是激活状态", ErrorCodes.DeptAlreadyActivated); + } + + Status = 1; + UpdateTime = new UpdateTime(DateTimeOffset.UtcNow); + } + + /// + /// 停用部门 + /// + public void Deactivate() + { + if (Status == 0) + { + throw new KnownException("部门已经被停用", ErrorCodes.DeptAlreadyDeactivated); + } + + Status = 0; + UpdateTime = new UpdateTime(DateTimeOffset.UtcNow); + } + + /// + /// 软删除部门 + /// + public void SoftDelete() + { + if (IsDeleted) + { + throw new KnownException("部门已经被删除", ErrorCodes.DeptAlreadyDeleted); + } + + IsDeleted = true; + UpdateTime = new UpdateTime(DateTimeOffset.UtcNow); + } + + /// + /// 添加子部门 + /// + /// 子部门 + public void AddChild(Dept child) + { + if (child == null) + { + throw new KnownException("子部门不能为空", ErrorCodes.ChildDeptCannotBeEmpty); + } + + Children.Add(child); + } + + /// + /// 移除子部门 + /// + /// 子部门 + public void RemoveChild(Dept child) + { + if (child == null) + { + throw new KnownException("子部门不能为空", ErrorCodes.ChildDeptCannotBeEmpty); + } + + Children.Remove(child); + } + + /// + /// 获取所有子部门(包括子级的子级) + /// + /// 所有子部门 + public IEnumerable GetAllChildren() + { + var result = new List(); + foreach (var child in Children) + { + result.Add(child); + result.AddRange(child.GetAllChildren()); + } + return result; + } + + /// + /// 获取部门层级路径 + /// + /// 层级路径 + public string GetPath() + { + return Name; + } +} diff --git a/template/src/ABC.Template.Domain/AggregatesModel/OrderAggregate/Order.cs b/template/src/ABC.Template.Domain/AggregatesModel/OrderAggregate/Order.cs deleted file mode 100644 index 570b8201..00000000 --- a/template/src/ABC.Template.Domain/AggregatesModel/OrderAggregate/Order.cs +++ /dev/null @@ -1,52 +0,0 @@ -using ABC.Template.Domain.DomainEvents; -using NetCorePal.Extensions.Domain; -using System.ComponentModel.DataAnnotations; -using System.ComponentModel.DataAnnotations.Schema; -using NetCorePal.Extensions.Primitives; - -namespace ABC.Template.Domain.AggregatesModel.OrderAggregate; - -public partial record OrderId : IGuidStronglyTypedId; - -/// -/// 聚合根 -/// -public partial class Order : Entity, IAggregateRoot -{ - /// - /// 受保护的默认构造函数,用以作为EF Core的反射入口 - /// - protected Order() - { - } - - public Order(string name, int count) - { - this.Name = name; - this.Count = count; - this.AddDomainEvent(new OrderCreatedDomainEvent(this)); - } - - public bool Paid { get; private set; } = false; - - public string Name { get; private set; } = string.Empty; - - public int Count { get; private set; } - - public RowVersion RowVersion { get; private set; } = new RowVersion(); - - public UpdateTime UpdateTime { get; private set; } = new UpdateTime(DateTimeOffset.UtcNow); - - public void OrderPaid() - { - if (Paid) - { - throw new KnownException("Order has been paid"); - } - else - { - this.Paid = true; - this.AddDomainEvent(new OrderPaidDomainEvent(this)); - } - } -} diff --git a/template/src/ABC.Template.Domain/AggregatesModel/RoleAggregate/Role.cs b/template/src/ABC.Template.Domain/AggregatesModel/RoleAggregate/Role.cs new file mode 100644 index 00000000..3bf2f420 --- /dev/null +++ b/template/src/ABC.Template.Domain/AggregatesModel/RoleAggregate/Role.cs @@ -0,0 +1,88 @@ +using ABC.Template.Domain.DomainEvents.RoleEvents; +using ABC.Template.Domain; + +namespace ABC.Template.Domain.AggregatesModel.RoleAggregate; + +public partial record RoleId : IGuidStronglyTypedId; + +public class Role : Entity, IAggregateRoot +{ + protected Role() + { + } + + public string Name { get; private set; } = string.Empty; + public string Description { get; private set; } = string.Empty; + public DateTimeOffset CreatedAt { get; init; } + public bool IsActive { get; private set; } = true; + public Deleted IsDeleted { get; private set; } = new Deleted(false); + public DeletedTime DeletedAt { get; private set; } = new DeletedTime(DateTimeOffset.UtcNow); + + public virtual ICollection Permissions { get; init; } = []; + + public Role(string name, string description, IEnumerable permissions) + { + CreatedAt =DateTimeOffset.UtcNow; + Name = name; + Description = description; + Permissions = new List(permissions); + IsActive = true; + } + + public void UpdateRoleInfo(string name, string description) + { + Name = name; + Description = description; + AddDomainEvent(new RoleInfoChangedDomainEvent(this)); + } + + public void UpdateRolePermissions(IEnumerable newPermissions) + { + var currentPermissionMap = Permissions.ToDictionary(p => p.PermissionCode); + var newPermissionMap = newPermissions.ToDictionary(p => p.PermissionCode); + + var permissionsToRemove = currentPermissionMap.Keys.Except(newPermissionMap.Keys).ToList(); + foreach (var permissionCode in permissionsToRemove) + { + Permissions.Remove(currentPermissionMap[permissionCode]); + } + + var permissionsToAdd = newPermissionMap.Keys.Except(currentPermissionMap.Keys).ToList(); + foreach (var permissionCode in permissionsToAdd) + { + Permissions.Add(newPermissionMap[permissionCode]); + } + + AddDomainEvent(new RolePermissionChangedDomainEvent(this)); + } + + public void Deactivate() + { + if (!IsActive) + { + throw new KnownException("角色已经被停用", ErrorCodes.RoleAlreadyDeactivated); + } + + IsActive = false; + } + + public void Activate() + { + if (IsActive) + { + throw new KnownException("角色已经是激活状态", ErrorCodes.RoleAlreadyActivated); + } + + IsActive = true; + } + + public void SoftDelete() + { + IsDeleted = true; + } + + public bool HasPermission(string permissionCode) + { + return Permissions.Any(p => p.PermissionCode == permissionCode); + } +} diff --git a/template/src/ABC.Template.Domain/AggregatesModel/RoleAggregate/RolePermission.cs b/template/src/ABC.Template.Domain/AggregatesModel/RoleAggregate/RolePermission.cs new file mode 100644 index 00000000..d8e739ef --- /dev/null +++ b/template/src/ABC.Template.Domain/AggregatesModel/RoleAggregate/RolePermission.cs @@ -0,0 +1,27 @@ +namespace ABC.Template.Domain.AggregatesModel.RoleAggregate; + +public class RolePermission +{ + protected RolePermission() + { + } + + public RoleId RoleId { get; internal set; } = default!; + public string PermissionCode { get; private set; } = string.Empty; + public string PermissionName { get; private set; } = string.Empty; + public string PermissionDescription { get; private set; } = string.Empty; + + + public RolePermission(string permissionCode, string permissionName, string permissionDescription) + { + PermissionCode = permissionCode; + PermissionName = permissionName; + PermissionDescription = permissionDescription; + } + + public void UpdatePermissionInfo(string permissionName, string permissionDescription) + { + PermissionName = permissionName; + PermissionDescription = permissionDescription; + } +} diff --git a/template/src/ABC.Template.Domain/AggregatesModel/UserAggregate/User.cs b/template/src/ABC.Template.Domain/AggregatesModel/UserAggregate/User.cs new file mode 100644 index 00000000..4ba598f8 --- /dev/null +++ b/template/src/ABC.Template.Domain/AggregatesModel/UserAggregate/User.cs @@ -0,0 +1,176 @@ +using ABC.Template.Domain.AggregatesModel.RoleAggregate; +using ABC.Template.Domain.AggregatesModel.DeptAggregate; + +namespace ABC.Template.Domain.AggregatesModel.UserAggregate; + +public partial record UserId : IInt64StronglyTypedId; + +public class User : Entity, IAggregateRoot +{ + protected User() + { + } + + public string Name { get; private set; } = string.Empty; + public string Email { get; private set; } = string.Empty; + public string Phone { get; private set; } = string.Empty; + public string RealName { get; private set; } = string.Empty; + public int Status { get; private set; } + public string PasswordHash { get; private set; } = string.Empty; + public bool IsActive { get; private set; } = true; + public DateTimeOffset CreatedAt { get; init; } + public DateTimeOffset? LastLoginTime { get; private set; } + public UpdateTime UpdateTime { get; private set; } = new UpdateTime(DateTimeOffset.UtcNow); + public Deleted IsDeleted { get; private set; } = new Deleted(false); + public DeletedTime DeletedAt { get; private set; } = new DeletedTime(DateTimeOffset.UtcNow); + public string Gender { get; private set; } = string.Empty; + public int Age { get; private set; } + public DateTimeOffset BirthDate { get; private set; } = default!; + + public virtual ICollection Roles { get; } = []; + + public virtual UserDept Dept { get; private set; } = default!; + + public ICollection RefreshTokens { get; } = []; + + public User(string name, string phone, string password, IEnumerable roles, string realName, int status, string email, string gender, DateTimeOffset birthDate) + { + CreatedAt =DateTimeOffset.UtcNow; + Name = name; + Phone = phone; + PasswordHash = password; + RealName = realName; + Status = status; + Email = email; + Gender = gender; + Age = CalculateAge(birthDate); + BirthDate = birthDate; + foreach (var userRole in roles) + { + Roles.Add(userRole); + } + } + + public void SoftDelete() + { + IsDeleted = true; + } + + public void PasswordReset(string password) + { + PasswordHash = password; + } + + public void SetUserRefreshToken(string refreshToken) + { + var refreshTokenInfo = new UserRefreshToken(refreshToken); + RefreshTokens.Add(refreshTokenInfo); + } + + public void UpdateLastLoginTime(DateTimeOffset loginTime) + { + LastLoginTime = loginTime; + UpdateTime = new UpdateTime(DateTimeOffset.UtcNow); + } + + public static int CalculateAge(DateTimeOffset birthDate) + { + var today =DateTimeOffset.UtcNow.Date; + int age = today.Year - birthDate.Year; + if (birthDate.Date > today.AddYears(-age)) + { + age--; + } + return age; + } + + public void UpdateUserInfo(string name, string phone, string realName, int status, string email, string gender, DateTimeOffset birthDate) + { + Name = name; + Phone = phone; + RealName = realName; + Status = status; + Email = email; + Gender = gender; + Age = CalculateAge(birthDate); + BirthDate = birthDate; + } + + public void UpdateRoleInfo(RoleId roleId, string roleName) + { + var savedRole = Roles.FirstOrDefault(r => r.RoleId == roleId); + savedRole?.UpdateRoleInfo(roleName); + UpdateTime = new UpdateTime(DateTimeOffset.UtcNow); + } + + public void UpdatePassword(string newPasswordHash) + { + if (!string.IsNullOrEmpty(newPasswordHash)) + { + PasswordHash = newPasswordHash; + UpdateTime = new UpdateTime(DateTimeOffset.UtcNow); + } + } + + public void UpdateRoles(IEnumerable rolesToBeAssigned) + { + var currentRoleMap = Roles.ToDictionary(r => r.RoleId); + var targetRoleMap = rolesToBeAssigned.ToDictionary(r => r.RoleId); + + var roleIdsToRemove = currentRoleMap.Keys.Except(targetRoleMap.Keys); + foreach (var roleId in roleIdsToRemove) + { + Roles.Remove(currentRoleMap[roleId]); + } + + var roleIdsToAdd = targetRoleMap.Keys.Except(currentRoleMap.Keys); + foreach (var roleId in roleIdsToAdd) + { + var targetRole = targetRoleMap[roleId]; + Roles.Add(targetRole); + } + } + + /// + /// 分配部门 + /// + /// 部门 + public void AssignDept(UserDept dept) + { + ArgumentNullException.ThrowIfNull(dept); + + Dept = dept; + } + + /// + /// 更新部门名称 + /// + /// 新的部门名称 + public void UpdateDeptName(string deptName) + { + if (Dept == null) + { + return; + } + + Dept.UpdateDeptName(deptName); + UpdateTime = new UpdateTime(DateTimeOffset.UtcNow); + } + + /// + /// 撤销所有未过期的刷新令牌(用于退出登录) + /// + public void RevokeAllRefreshTokens() + { + var now = DateTimeOffset.UtcNow; + foreach (var token in RefreshTokens) + { + // 只撤销未过期且未使用的令牌 + if (!token.IsRevoked && !token.IsUsed && token.ExpiresTime > now) + { + token.Revoke(); + } + } + UpdateTime = new UpdateTime(now); + } +} diff --git a/template/src/ABC.Template.Domain/AggregatesModel/UserAggregate/UserDept.cs b/template/src/ABC.Template.Domain/AggregatesModel/UserAggregate/UserDept.cs new file mode 100644 index 00000000..1420b383 --- /dev/null +++ b/template/src/ABC.Template.Domain/AggregatesModel/UserAggregate/UserDept.cs @@ -0,0 +1,82 @@ +using ABC.Template.Domain.AggregatesModel.DeptAggregate; +using ABC.Template.Domain; + +namespace ABC.Template.Domain.AggregatesModel.UserAggregate; + +/// +/// 用户部门关系实体 +/// 表示用户与部门的一对一关系 +/// +public class UserDept +{ + /// + /// 用户ID + /// + public UserId UserId { get; private set; } = default!; + + /// + /// 部门ID + /// + public DeptId DeptId { get; private set; } = default!; + + /// + /// 部门名称 + /// + public string DeptName { get; private set; } = string.Empty; + + /// + /// 分配时间 + /// + public DateTimeOffset AssignedAt { get; init; } + + protected UserDept() + { + } + + /// + /// 创建用户部门关系 + /// + /// 用户ID + /// 部门ID + /// 部门名称 + public UserDept(UserId userId, DeptId deptId, string deptName) + { + UserId = userId; + DeptId = deptId; + AssignedAt = DateTimeOffset.UtcNow; + DeptName = deptName; + } + + /// + /// 更新部门名称 + /// + /// 新的部门名称 + public void UpdateDeptName(string deptName) + { + if (string.IsNullOrWhiteSpace(deptName)) + { + throw new KnownException("部门名称不能为空", ErrorCodes.DeptNameCannotBeEmpty); + } + + DeptName = deptName; + } + +//#if (UseMongoDB) + /// + /// 更新部门信息(部门ID和部门名称) + /// MongoDB 下 UpdateUser 直接操作 UserDepts 集合时使用,用于就地更新已有 UserDept。 + /// + /// 新的部门ID + /// 新的部门名称 + public void UpdateDept(DeptId deptId, string deptName) + { + if (string.IsNullOrWhiteSpace(deptName)) + { + throw new KnownException("部门名称不能为空", ErrorCodes.DeptNameCannotBeEmpty); + } + + DeptId = deptId; + DeptName = deptName; + } +//#endif +} diff --git a/template/src/ABC.Template.Domain/AggregatesModel/UserAggregate/UserRefreshToken.cs b/template/src/ABC.Template.Domain/AggregatesModel/UserAggregate/UserRefreshToken.cs new file mode 100644 index 00000000..28db55df --- /dev/null +++ b/template/src/ABC.Template.Domain/AggregatesModel/UserAggregate/UserRefreshToken.cs @@ -0,0 +1,41 @@ +using ABC.Template.Domain; + +namespace ABC.Template.Domain.AggregatesModel.UserAggregate; + +public partial record UserRefreshTokenId : IInt64StronglyTypedId; + +public class UserRefreshToken : Entity +{ + protected UserRefreshToken() + { + } + + public UserRefreshToken(string token) + { + Token = token; + CreatedTime =DateTimeOffset.UtcNow; + ExpiresTime = CreatedTime.AddDays(1); + } + + public UserId UserId { get; private set; } = null!; + public string Token { get; private set; } = string.Empty; + public DateTimeOffset CreatedTime { get; init; } + public DateTimeOffset ExpiresTime { get; init; } + public bool IsUsed { get; private set; } + public bool IsRevoked { get; private set; } + + public void Use() + { + if (IsUsed || + IsRevoked || + ExpiresTime +/// 部门信息变更领域事件 +/// +public record DeptInfoChangedDomainEvent(Dept Dept) : IDomainEvent; diff --git a/template/src/ABC.Template.Domain/DomainEvents/OrderDomainEvents.cs b/template/src/ABC.Template.Domain/DomainEvents/OrderDomainEvents.cs deleted file mode 100644 index 2e7f5478..00000000 --- a/template/src/ABC.Template.Domain/DomainEvents/OrderDomainEvents.cs +++ /dev/null @@ -1,7 +0,0 @@ -using ABC.Template.Domain.AggregatesModel.OrderAggregate; - -namespace ABC.Template.Domain.DomainEvents; - -public record OrderCreatedDomainEvent(Order Order) : IDomainEvent; - -public record OrderPaidDomainEvent(Order Order) : IDomainEvent; diff --git a/template/src/ABC.Template.Domain/DomainEvents/RoleEvents.cs b/template/src/ABC.Template.Domain/DomainEvents/RoleEvents.cs new file mode 100644 index 00000000..56d33cee --- /dev/null +++ b/template/src/ABC.Template.Domain/DomainEvents/RoleEvents.cs @@ -0,0 +1,6 @@ +using ABC.Template.Domain.AggregatesModel.RoleAggregate; + +namespace ABC.Template.Domain.DomainEvents.RoleEvents; + +public record RoleInfoChangedDomainEvent(Role Role) : IDomainEvent; +public record RolePermissionChangedDomainEvent(Role Role) : IDomainEvent; diff --git a/template/src/ABC.Template.Domain/ErrorCodes.cs b/template/src/ABC.Template.Domain/ErrorCodes.cs new file mode 100644 index 00000000..b617b88a --- /dev/null +++ b/template/src/ABC.Template.Domain/ErrorCodes.cs @@ -0,0 +1,114 @@ +namespace ABC.Template.Domain; + +/// +/// 错误码定义 +/// +public sealed class ErrorCodes +{ + private ErrorCodes() + { + + } + + #region 用户相关错误 (100xxx) + + /// + /// 未找到账户 + /// + public const int AccountNotFound = 100001; + + /// + /// 用户名或密码错误 + /// + public const int UserNameOrPasswordError = 100002; + + /// + /// 未找到用户 + /// + public const int UserNotFound = 100003; + + /// + /// 无效的用户身份 + /// + public const int InvalidUserIdentity = 100004; + + /// + /// 无效的用户 + /// + public const int InvalidUser = 100005; + + /// + /// 无效的令牌 + /// + public const int InvalidToken = 100006; + + /// + /// 无效的刷新令牌 + /// + public const int InvalidRefreshToken = 100007; + + #endregion + + #region 角色相关错误 (110xxx) + + /// + /// 未找到角色 + /// + public const int RoleNotFound = 110001; + + /// + /// 不能删除管理员角色 + /// + public const int CannotDeleteAdminRole = 110002; + + /// + /// 角色已经被停用 + /// + public const int RoleAlreadyDeactivated = 110003; + + /// + /// 角色已经是激活状态 + /// + public const int RoleAlreadyActivated = 110004; + + #endregion + + #region 部门相关错误 (120xxx) + + /// + /// 未找到部门 + /// + public const int DeptNotFound = 120001; + + /// + /// 该部门下存在子部门,无法删除 + /// + public const int DeptHasChildrenCannotDelete = 120002; + + /// + /// 部门已经是激活状态 + /// + public const int DeptAlreadyActivated = 120003; + + /// + /// 部门已经被停用 + /// + public const int DeptAlreadyDeactivated = 120004; + + /// + /// 部门已经被删除 + /// + public const int DeptAlreadyDeleted = 120005; + + /// + /// 部门名称不能为空 + /// + public const int DeptNameCannotBeEmpty = 120006; + + /// + /// 子部门不能为空 + /// + public const int ChildDeptCannotBeEmpty = 120007; + + #endregion +} diff --git a/template/src/ABC.Template.Infrastructure/ApplicationDbContext.cs b/template/src/ABC.Template.Infrastructure/ApplicationDbContext.cs index 28ff925c..a44333c2 100644 --- a/template/src/ABC.Template.Infrastructure/ApplicationDbContext.cs +++ b/template/src/ABC.Template.Infrastructure/ApplicationDbContext.cs @@ -1,11 +1,14 @@ -using ABC.Template.Domain.AggregatesModel.OrderAggregate; using MediatR; using Microsoft.EntityFrameworkCore; //#if (UseDMDB) using Microsoft.EntityFrameworkCore.Storage; //#endif using NetCorePal.Extensions.DistributedTransactions.CAP.Persistence; -using ABC.Template.Domain.AggregatesModel.DeliverAggregate; +//#if (UseAdmin) +using ABC.Template.Domain.AggregatesModel.UserAggregate; +using ABC.Template.Domain.AggregatesModel.RoleAggregate; +using ABC.Template.Domain.AggregatesModel.DeptAggregate; +//#endif namespace ABC.Template.Infrastructure; @@ -25,7 +28,7 @@ public partial class ApplicationDbContext(DbContextOptions , IDMDBCapDataStorage //#elif (UseMongoDB) , IMongoDBCapDataStorage - //#endif +//#endif { protected override void OnModelCreating(ModelBuilder modelBuilder) { @@ -39,13 +42,13 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) } -//#if (UseDMDB) + //#if (UseDMDB) protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { optionsBuilder.ReplaceService(); base.OnConfiguring(optionsBuilder); } -//#endif + //#endif protected override void ConfigureConventions(ModelConfigurationBuilder configurationBuilder) { @@ -53,6 +56,12 @@ protected override void ConfigureConventions(ModelConfigurationBuilder configura base.ConfigureConventions(configurationBuilder); } - public DbSet Orders => Set(); - public DbSet DeliverRecords => Set(); + //#if (UseAdmin) + public DbSet Users => Set(); + public DbSet Roles => Set(); + public DbSet RolePermissions => Set(); + public DbSet UserRoles => Set(); + public DbSet Depts => Set(); + public DbSet UserDepts => Set(); + //#endif } diff --git a/template/src/ABC.Template.Infrastructure/DesignTimeApplicationDbContextFactory.cs b/template/src/ABC.Template.Infrastructure/DesignTimeApplicationDbContextFactory.cs index e06d2f72..5e57a7b0 100644 --- a/template/src/ABC.Template.Infrastructure/DesignTimeApplicationDbContextFactory.cs +++ b/template/src/ABC.Template.Infrastructure/DesignTimeApplicationDbContextFactory.cs @@ -52,6 +52,8 @@ public ApplicationDbContext CreateDbContext(string[] args) { b.MigrationsAssembly(typeof(DesignTimeApplicationDbContextFactory).Assembly.FullName); }); + + options.UseMongoDB("mongodb://localhost:27017/any", "any"); }); var provider = services.BuildServiceProvider(); diff --git a/template/src/ABC.Template.Infrastructure/EntityConfigurations/DeliverRecordConfiguration.cs b/template/src/ABC.Template.Infrastructure/EntityConfigurations/DeliverRecordConfiguration.cs deleted file mode 100644 index d5d026f8..00000000 --- a/template/src/ABC.Template.Infrastructure/EntityConfigurations/DeliverRecordConfiguration.cs +++ /dev/null @@ -1,15 +0,0 @@ -using ABC.Template.Domain.AggregatesModel.DeliverAggregate; - -namespace ABC.Template.Infrastructure.EntityConfigurations -{ - internal class DeliverRecordConfiguration : IEntityTypeConfiguration - { - public void Configure(EntityTypeBuilder builder) - { - builder.ToTable("deliverrecord"); - builder.HasKey(t => t.Id); - builder.Property(t => t.Id).UseGuidVersion7ValueGenerator(); - } - } - -} diff --git a/template/src/ABC.Template.Infrastructure/EntityConfigurations/DeptEntityTypeConfiguration.cs b/template/src/ABC.Template.Infrastructure/EntityConfigurations/DeptEntityTypeConfiguration.cs new file mode 100644 index 00000000..8f858190 --- /dev/null +++ b/template/src/ABC.Template.Infrastructure/EntityConfigurations/DeptEntityTypeConfiguration.cs @@ -0,0 +1,47 @@ +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata.Builders; +using ABC.Template.Domain.AggregatesModel.DeptAggregate; + +namespace ABC.Template.Infrastructure.EntityConfigurations; + +/// +/// 部门实体类型配置 +/// +internal class DeptEntityTypeConfiguration : IEntityTypeConfiguration +{ + public void Configure(EntityTypeBuilder builder) + { + builder.ToTable("dept"); + + builder.HasKey(d => d.Id); + builder.Property(t => t.Id).UseSnowFlakeValueGenerator(); + + builder.Property(d => d.Name) + .IsRequired() + .HasMaxLength(100); + + builder.Property(d => d.Remark) + .HasMaxLength(500); + + builder.Property(d => d.Status) + .IsRequired(); + + builder.Property(d => d.CreatedAt) + .IsRequired(); + + builder.Property(d => d.IsDeleted) + .IsRequired(); + + builder.Property(d => d.DeletedAt); + + builder.Property(d => d.UpdateTime); + + // 索引 + builder.HasIndex(d => d.ParentId); + builder.HasIndex(d => d.Status); + builder.HasIndex(d => d.IsDeleted); + + // 软删除过滤器 + builder.HasQueryFilter(d => !d.IsDeleted); + } +} \ No newline at end of file diff --git a/template/src/ABC.Template.Infrastructure/EntityConfigurations/OrderEntityTypeConfiguration.cs b/template/src/ABC.Template.Infrastructure/EntityConfigurations/OrderEntityTypeConfiguration.cs deleted file mode 100644 index 18d9d005..00000000 --- a/template/src/ABC.Template.Infrastructure/EntityConfigurations/OrderEntityTypeConfiguration.cs +++ /dev/null @@ -1,18 +0,0 @@ -using ABC.Template.Domain.AggregatesModel.OrderAggregate; - -namespace ABC.Template.Infrastructure.EntityConfigurations -{ - internal class OrderEntityTypeConfiguration : IEntityTypeConfiguration - { - public void Configure(EntityTypeBuilder builder) - { - builder.ToTable("order"); - builder.HasKey(t => t.Id); - builder.Property(t => t.Id).UseGuidVersion7ValueGenerator(); - builder.Property(b => b.Name).HasMaxLength(100); - builder.Property(b => b.Count); - builder.Property(b => b.Paid); - } - } - -} diff --git a/template/src/ABC.Template.Infrastructure/EntityConfigurations/RoleEntityTypeConfiguration.cs b/template/src/ABC.Template.Infrastructure/EntityConfigurations/RoleEntityTypeConfiguration.cs new file mode 100644 index 00000000..c09e997f --- /dev/null +++ b/template/src/ABC.Template.Infrastructure/EntityConfigurations/RoleEntityTypeConfiguration.cs @@ -0,0 +1,48 @@ +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata.Builders; +using ABC.Template.Domain.AggregatesModel.RoleAggregate; + +namespace ABC.Template.Infrastructure.EntityConfigurations; + +internal class RoleEntityTypeConfiguration : IEntityTypeConfiguration +{ + public void Configure(EntityTypeBuilder builder) + { + builder.ToTable("role"); + builder.HasKey(t => t.Id); + builder.Property(t => t.Id).UseGuidVersion7ValueGenerator(); + + builder.Property(b => b.Name).HasMaxLength(50).IsRequired(); + builder.Property(b => b.Description).HasMaxLength(200); + builder.Property(b => b.CreatedAt); + builder.Property(b => b.IsActive); + builder.Property(b => b.IsDeleted); + + builder.HasIndex(b => b.Name).IsUnique(); + + builder.HasMany(r => r.Permissions).WithOne().HasForeignKey(rp => rp.RoleId); + builder.Navigation(e => e.Permissions).AutoInclude(); + + builder.HasQueryFilter(b => !b.IsDeleted); + } +} + +internal class RolePermissionEntityTypeConfiguration : IEntityTypeConfiguration +{ + public void Configure(EntityTypeBuilder builder) + { + builder.ToTable("role_permission"); + + builder.HasKey(t => new { t.RoleId, t.PermissionCode }); + + builder.Property(b => b.RoleId); + builder.Property(b => b.PermissionCode).HasMaxLength(100).IsRequired(); + builder.Property(b => b.PermissionName).HasMaxLength(100); + builder.Property(b => b.PermissionDescription).HasMaxLength(200); + + builder.HasOne() + .WithMany(r => r.Permissions) + .HasForeignKey(rp => rp.RoleId) + .OnDelete(DeleteBehavior.Cascade); + } +} \ No newline at end of file diff --git a/template/src/ABC.Template.Infrastructure/EntityConfigurations/UserEntityTypeConfiguration.cs b/template/src/ABC.Template.Infrastructure/EntityConfigurations/UserEntityTypeConfiguration.cs new file mode 100644 index 00000000..618218ba --- /dev/null +++ b/template/src/ABC.Template.Infrastructure/EntityConfigurations/UserEntityTypeConfiguration.cs @@ -0,0 +1,113 @@ +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata.Builders; +using ABC.Template.Domain.AggregatesModel.UserAggregate; + +namespace ABC.Template.Infrastructure.EntityConfigurations; + +internal class UserEntityTypeConfiguration : IEntityTypeConfiguration +{ + public void Configure(EntityTypeBuilder builder) + { + builder.ToTable("user"); + builder.HasKey(t => t.Id); + builder.Property(t => t.Id).UseSnowFlakeValueGenerator(); + + builder.Property(b => b.Name).HasMaxLength(50).IsRequired(); + builder.Property(b => b.Email).HasMaxLength(100).IsRequired(); + builder.Property(b => b.PasswordHash).HasMaxLength(255).IsRequired(); + builder.Property(b => b.Phone).HasMaxLength(20); + builder.Property(b => b.RealName).HasMaxLength(50); + builder.Property(b => b.Gender).HasMaxLength(10); + builder.Property(b => b.Age); + builder.Property(b => b.BirthDate); + builder.Property(b => b.IsActive); + builder.Property(b => b.CreatedAt); + builder.Property(b => b.LastLoginTime); + builder.Property(b => b.UpdateTime); + + builder.HasIndex(b => b.Name); + builder.HasIndex(b => b.Email); + + builder.HasMany(au => au.Roles) + .WithOne() + .HasForeignKey(aur => aur.UserId) + .OnDelete(DeleteBehavior.ClientCascade); + builder.Navigation(au => au.Roles).AutoInclude(); + + builder.HasMany(u => u.RefreshTokens) + .WithOne() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade); + + builder.HasOne(au => au.Dept) + .WithOne() + .HasForeignKey(ud => ud.UserId) + .OnDelete(DeleteBehavior.ClientCascade); + builder.Navigation(au => au.Dept).AutoInclude(); + } +} + +internal class UserDeptEntityTypeConfiguration : IEntityTypeConfiguration +{ + public void Configure(EntityTypeBuilder builder) + { + builder.ToTable("user_dept"); + + builder.HasKey(ud => ud.UserId); + +//#if (UseMongoDB) + // MongoDB 要求主键必须映射到 _id 元素 + builder.Property(ud => ud.UserId) + .HasElementName("_id"); + builder.Property(ud => ud.DeptId); + builder.Property(ud => ud.DeptName).HasMaxLength(100); + builder.Property(ud => ud.AssignedAt) + .IsRequired(); + + // 注意:不能为主键字段(映射到 _id)创建索引,因为 MongoDB 的 _id 字段已经有默认的唯一索引 + builder.HasIndex(ud => ud.DeptId); +//#else + builder.Property(ud => ud.UserId); + builder.Property(ud => ud.DeptId); + builder.Property(ud => ud.DeptName).HasMaxLength(100); + builder.Property(ud => ud.AssignedAt) + .IsRequired(); + + // 索引 + builder.HasIndex(ud => ud.UserId); + builder.HasIndex(ud => ud.DeptId); +//#endif + } +} + +internal class UserRoleEntityTypeConfiguration : IEntityTypeConfiguration +{ + public void Configure(EntityTypeBuilder builder) + { + builder.ToTable("user_role"); + + builder.HasKey(t => new { t.UserId, t.RoleId }); + + builder.Property(b => b.UserId); + builder.Property(b => b.RoleId); + builder.Property(b => b.RoleName).HasMaxLength(50).IsRequired(); + + builder.HasOne() + .WithMany(u => u.Roles) + .HasForeignKey(ur => ur.UserId) + .OnDelete(DeleteBehavior.Cascade); + } +} + +internal class UserRefreshTokenConfiguration : IEntityTypeConfiguration +{ + public void Configure(EntityTypeBuilder builder) + { + builder.ToTable("user_refresh_token"); + builder.HasKey(x => x.Id); + builder.Property(x => x.Id).UseSnowFlakeValueGenerator(); + builder.Property(x => x.Token).HasMaxLength(500).IsRequired(); + builder.Property(x => x.CreatedTime).IsRequired(); + builder.Property(x => x.ExpiresTime).IsRequired(); + } +} \ No newline at end of file diff --git a/template/src/ABC.Template.Infrastructure/MigrationsAll/DMDB-net10.0-admin/20260122055126_Init.Designer.cs b/template/src/ABC.Template.Infrastructure/MigrationsAll/DMDB-net10.0-admin/20260122055126_Init.Designer.cs new file mode 100644 index 00000000..a3e7de1a --- /dev/null +++ b/template/src/ABC.Template.Infrastructure/MigrationsAll/DMDB-net10.0-admin/20260122055126_Init.Designer.cs @@ -0,0 +1,433 @@ +// +using System; +using ABC.Template.Infrastructure; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace ABC.Template.Infrastructure.Migrations +{ + [DbContext(typeof(ApplicationDbContext))] + [Migration("20260122055126_Init")] + partial class Init + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("Dm:ValueGenerationStrategy", DmValueGenerationStrategy.IdentityColumn) + .HasAnnotation("ProductVersion", "9.0.1") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.DeptAggregate.Dept", b => + { + b.Property("Id") + .HasColumnType("BIGINT"); + + b.Property("CreatedAt") + .HasColumnType("DATETIME WITH TIME ZONE"); + + b.Property("DeletedAt") + .HasColumnType("DATETIME WITH TIME ZONE"); + + b.Property("IsDeleted") + .HasColumnType("BIT"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("NVARCHAR2(100)"); + + b.Property("ParentId") + .HasColumnType("BIGINT"); + + b.Property("Remark") + .IsRequired() + .HasMaxLength(500) + .HasColumnType("NVARCHAR2(500)"); + + b.Property("Status") + .HasColumnType("INT"); + + b.Property("UpdateTime") + .HasColumnType("DATETIME WITH TIME ZONE"); + + b.HasKey("Id"); + + b.HasIndex("IsDeleted"); + + b.HasIndex("ParentId"); + + b.HasIndex("Status"); + + b.ToTable("dept", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.Role", b => + { + b.Property("Id") + .HasColumnType("CHAR(36)"); + + b.Property("CreatedAt") + .HasColumnType("DATETIME WITH TIME ZONE"); + + b.Property("DeletedAt") + .HasColumnType("DATETIME WITH TIME ZONE"); + + b.Property("Description") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("NVARCHAR2(200)"); + + b.Property("IsActive") + .HasColumnType("BIT"); + + b.Property("IsDeleted") + .HasColumnType("BIT"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("NVARCHAR2(50)"); + + b.HasKey("Id"); + + b.HasIndex("Name") + .IsUnique(); + + b.ToTable("role", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.RolePermission", b => + { + b.Property("RoleId") + .HasColumnType("CHAR(36)"); + + b.Property("PermissionCode") + .HasMaxLength(100) + .HasColumnType("NVARCHAR2(100)"); + + b.Property("PermissionDescription") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("NVARCHAR2(200)"); + + b.Property("PermissionName") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("NVARCHAR2(100)"); + + b.HasKey("RoleId", "PermissionCode"); + + b.ToTable("role_permission", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.User", b => + { + b.Property("Id") + .HasColumnType("BIGINT"); + + b.Property("Age") + .HasColumnType("INT"); + + b.Property("BirthDate") + .HasColumnType("DATETIME WITH TIME ZONE"); + + b.Property("CreatedAt") + .HasColumnType("DATETIME WITH TIME ZONE"); + + b.Property("DeletedAt") + .HasColumnType("DATETIME WITH TIME ZONE"); + + b.Property("Email") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("NVARCHAR2(100)"); + + b.Property("Gender") + .IsRequired() + .HasMaxLength(10) + .HasColumnType("NVARCHAR2(10)"); + + b.Property("IsActive") + .HasColumnType("BIT"); + + b.Property("IsDeleted") + .HasColumnType("BIT"); + + b.Property("LastLoginTime") + .HasColumnType("DATETIME WITH TIME ZONE"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("NVARCHAR2(50)"); + + b.Property("PasswordHash") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("NVARCHAR2(255)"); + + b.Property("Phone") + .IsRequired() + .HasMaxLength(20) + .HasColumnType("NVARCHAR2(20)"); + + b.Property("RealName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("NVARCHAR2(50)"); + + b.Property("Status") + .HasColumnType("INT"); + + b.Property("UpdateTime") + .HasColumnType("DATETIME WITH TIME ZONE"); + + b.HasKey("Id"); + + b.HasIndex("Email"); + + b.HasIndex("Name"); + + b.ToTable("user", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserDept", b => + { + b.Property("UserId") + .HasColumnType("BIGINT"); + + b.Property("AssignedAt") + .HasColumnType("DATETIME WITH TIME ZONE"); + + b.Property("DeptId") + .HasColumnType("BIGINT"); + + b.Property("DeptName") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("NVARCHAR2(100)"); + + b.HasKey("UserId"); + + b.HasIndex("DeptId"); + + b.HasIndex("UserId"); + + b.ToTable("user_dept", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRefreshToken", b => + { + b.Property("Id") + .HasColumnType("BIGINT"); + + b.Property("CreatedTime") + .HasColumnType("DATETIME WITH TIME ZONE"); + + b.Property("ExpiresTime") + .HasColumnType("DATETIME WITH TIME ZONE"); + + b.Property("IsRevoked") + .HasColumnType("BIT"); + + b.Property("IsUsed") + .HasColumnType("BIT"); + + b.Property("Token") + .IsRequired() + .HasMaxLength(500) + .HasColumnType("NVARCHAR2(500)"); + + b.Property("UserId") + .HasColumnType("BIGINT"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("user_refresh_token", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRole", b => + { + b.Property("UserId") + .HasColumnType("BIGINT"); + + b.Property("RoleId") + .HasColumnType("CHAR(36)"); + + b.Property("RoleName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("NVARCHAR2(50)"); + + b.HasKey("UserId", "RoleId"); + + b.ToTable("user_role", (string)null); + }); + + modelBuilder.Entity("NetCorePal.Extensions.DistributedTransactions.CAP.Persistence.CapLock", b => + { + b.Property("Key") + .HasMaxLength(128) + .HasColumnType("NVARCHAR2(128)"); + + b.Property("Instance") + .HasMaxLength(256) + .HasColumnType("NVARCHAR2(256)"); + + b.Property("LastLockTime") + .HasColumnType("TIMESTAMP"); + + b.HasKey("Key"); + + b.ToTable("CAPLock", (string)null); + }); + + modelBuilder.Entity("NetCorePal.Extensions.DistributedTransactions.CAP.Persistence.PublishedMessage", b => + { + b.Property("Id") + .HasColumnType("BIGINT"); + + b.Property("Added") + .HasColumnType("TIMESTAMP"); + + b.Property("Content") + .HasColumnType("TEXT"); + + b.Property("ExpiresAt") + .HasColumnType("TIMESTAMP"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("NVARCHAR2(200)"); + + b.Property("Retries") + .HasColumnType("INT"); + + b.Property("StatusName") + .IsRequired() + .HasMaxLength(40) + .HasColumnType("NVARCHAR2(40)"); + + b.Property("Version") + .HasMaxLength(20) + .HasColumnType("NVARCHAR2(20)"); + + b.HasKey("Id"); + + b.HasIndex(new[] { "ExpiresAt", "StatusName" }, "IX_ExpiresAt_StatusName"); + + b.HasIndex(new[] { "Version", "ExpiresAt", "StatusName" }, "IX_Version_ExpiresAt_StatusName"); + + b.ToTable("CAPPublishedMessage", (string)null); + }); + + modelBuilder.Entity("NetCorePal.Extensions.DistributedTransactions.CAP.Persistence.ReceivedMessage", b => + { + b.Property("Id") + .HasColumnType("BIGINT"); + + b.Property("Added") + .HasColumnType("TIMESTAMP"); + + b.Property("Content") + .HasColumnType("TEXT"); + + b.Property("ExpiresAt") + .HasColumnType("TIMESTAMP"); + + b.Property("Group") + .HasMaxLength(200) + .HasColumnType("NVARCHAR2(200)"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(400) + .HasColumnType("NVARCHAR2(400)"); + + b.Property("Retries") + .HasColumnType("INT"); + + b.Property("StatusName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("NVARCHAR2(50)"); + + b.Property("Version") + .HasMaxLength(20) + .HasColumnType("NVARCHAR2(20)"); + + b.HasKey("Id"); + + b.HasIndex(new[] { "ExpiresAt", "StatusName" }, "IX_ExpiresAt_StatusName") + .HasDatabaseName("IX_ExpiresAt_StatusName1"); + + b.HasIndex(new[] { "Version", "ExpiresAt", "StatusName" }, "IX_Version_ExpiresAt_StatusName") + .HasDatabaseName("IX_Version_ExpiresAt_StatusName1"); + + b.ToTable("CAPReceivedMessage", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.RolePermission", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.RoleAggregate.Role", null) + .WithMany("Permissions") + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserDept", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.UserAggregate.User", null) + .WithOne("Dept") + .HasForeignKey("ABC.Template.Domain.AggregatesModel.UserAggregate.UserDept", "UserId") + .OnDelete(DeleteBehavior.ClientCascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRefreshToken", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.UserAggregate.User", null) + .WithMany("RefreshTokens") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRole", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.UserAggregate.User", null) + .WithMany("Roles") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.Role", b => + { + b.Navigation("Permissions"); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.User", b => + { + b.Navigation("Dept") + .IsRequired(); + + b.Navigation("RefreshTokens"); + + b.Navigation("Roles"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/template/src/ABC.Template.Infrastructure/MigrationsAll/DMDB-net10.0-admin/20260122055126_Init.cs b/template/src/ABC.Template.Infrastructure/MigrationsAll/DMDB-net10.0-admin/20260122055126_Init.cs new file mode 100644 index 00000000..3e54f7ab --- /dev/null +++ b/template/src/ABC.Template.Infrastructure/MigrationsAll/DMDB-net10.0-admin/20260122055126_Init.cs @@ -0,0 +1,308 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace ABC.Template.Infrastructure.Migrations +{ + /// + public partial class Init : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "CAPLock", + columns: table => new + { + Key = table.Column(type: "NVARCHAR2(128)", maxLength: 128, nullable: false), + Instance = table.Column(type: "NVARCHAR2(256)", maxLength: 256, nullable: true), + LastLockTime = table.Column(type: "TIMESTAMP", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_CAPLock", x => x.Key); + }); + + migrationBuilder.CreateTable( + name: "CAPPublishedMessage", + columns: table => new + { + Id = table.Column(type: "BIGINT", nullable: false), + Version = table.Column(type: "NVARCHAR2(20)", maxLength: 20, nullable: true), + Name = table.Column(type: "NVARCHAR2(200)", maxLength: 200, nullable: false), + Content = table.Column(type: "TEXT", nullable: true), + Retries = table.Column(type: "INT", nullable: true), + Added = table.Column(type: "TIMESTAMP", nullable: false), + ExpiresAt = table.Column(type: "TIMESTAMP", nullable: true), + StatusName = table.Column(type: "NVARCHAR2(40)", maxLength: 40, nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_CAPPublishedMessage", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "CAPReceivedMessage", + columns: table => new + { + Id = table.Column(type: "BIGINT", nullable: false), + Version = table.Column(type: "NVARCHAR2(20)", maxLength: 20, nullable: true), + Name = table.Column(type: "NVARCHAR2(400)", maxLength: 400, nullable: false), + Group = table.Column(type: "NVARCHAR2(200)", maxLength: 200, nullable: true), + Content = table.Column(type: "TEXT", nullable: true), + Retries = table.Column(type: "INT", nullable: true), + Added = table.Column(type: "TIMESTAMP", nullable: false), + ExpiresAt = table.Column(type: "TIMESTAMP", nullable: true), + StatusName = table.Column(type: "NVARCHAR2(50)", maxLength: 50, nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_CAPReceivedMessage", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "dept", + columns: table => new + { + Id = table.Column(type: "BIGINT", nullable: false), + Name = table.Column(type: "NVARCHAR2(100)", maxLength: 100, nullable: false), + Remark = table.Column(type: "NVARCHAR2(500)", maxLength: 500, nullable: false), + ParentId = table.Column(type: "BIGINT", nullable: false), + Status = table.Column(type: "INT", nullable: false), + CreatedAt = table.Column(type: "DATETIME WITH TIME ZONE", nullable: false), + IsDeleted = table.Column(type: "BIT", nullable: false), + DeletedAt = table.Column(type: "DATETIME WITH TIME ZONE", nullable: false), + UpdateTime = table.Column(type: "DATETIME WITH TIME ZONE", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_dept", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "role", + columns: table => new + { + Id = table.Column(type: "CHAR(36)", nullable: false), + Name = table.Column(type: "NVARCHAR2(50)", maxLength: 50, nullable: false), + Description = table.Column(type: "NVARCHAR2(200)", maxLength: 200, nullable: false), + CreatedAt = table.Column(type: "DATETIME WITH TIME ZONE", nullable: false), + IsActive = table.Column(type: "BIT", nullable: false), + IsDeleted = table.Column(type: "BIT", nullable: false), + DeletedAt = table.Column(type: "DATETIME WITH TIME ZONE", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_role", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "user", + columns: table => new + { + Id = table.Column(type: "BIGINT", nullable: false), + Name = table.Column(type: "NVARCHAR2(50)", maxLength: 50, nullable: false), + Email = table.Column(type: "NVARCHAR2(100)", maxLength: 100, nullable: false), + Phone = table.Column(type: "NVARCHAR2(20)", maxLength: 20, nullable: false), + RealName = table.Column(type: "NVARCHAR2(50)", maxLength: 50, nullable: false), + Status = table.Column(type: "INT", nullable: false), + PasswordHash = table.Column(type: "NVARCHAR2(255)", maxLength: 255, nullable: false), + IsActive = table.Column(type: "BIT", nullable: false), + CreatedAt = table.Column(type: "DATETIME WITH TIME ZONE", nullable: false), + LastLoginTime = table.Column(type: "DATETIME WITH TIME ZONE", nullable: true), + UpdateTime = table.Column(type: "DATETIME WITH TIME ZONE", nullable: false), + IsDeleted = table.Column(type: "BIT", nullable: false), + DeletedAt = table.Column(type: "DATETIME WITH TIME ZONE", nullable: false), + Gender = table.Column(type: "NVARCHAR2(10)", maxLength: 10, nullable: false), + Age = table.Column(type: "INT", nullable: false), + BirthDate = table.Column(type: "DATETIME WITH TIME ZONE", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_user", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "role_permission", + columns: table => new + { + RoleId = table.Column(type: "CHAR(36)", nullable: false), + PermissionCode = table.Column(type: "NVARCHAR2(100)", maxLength: 100, nullable: false), + PermissionName = table.Column(type: "NVARCHAR2(100)", maxLength: 100, nullable: false), + PermissionDescription = table.Column(type: "NVARCHAR2(200)", maxLength: 200, nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_role_permission", x => new { x.RoleId, x.PermissionCode }); + table.ForeignKey( + name: "FK_role_permission_role_RoleId", + column: x => x.RoleId, + principalTable: "role", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "user_dept", + columns: table => new + { + UserId = table.Column(type: "BIGINT", nullable: false), + DeptId = table.Column(type: "BIGINT", nullable: false), + DeptName = table.Column(type: "NVARCHAR2(100)", maxLength: 100, nullable: false), + AssignedAt = table.Column(type: "DATETIME WITH TIME ZONE", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_user_dept", x => x.UserId); + table.ForeignKey( + name: "FK_user_dept_user_UserId", + column: x => x.UserId, + principalTable: "user", + principalColumn: "Id"); + }); + + migrationBuilder.CreateTable( + name: "user_refresh_token", + columns: table => new + { + Id = table.Column(type: "BIGINT", nullable: false), + UserId = table.Column(type: "BIGINT", nullable: false), + Token = table.Column(type: "NVARCHAR2(500)", maxLength: 500, nullable: false), + CreatedTime = table.Column(type: "DATETIME WITH TIME ZONE", nullable: false), + ExpiresTime = table.Column(type: "DATETIME WITH TIME ZONE", nullable: false), + IsUsed = table.Column(type: "BIT", nullable: false), + IsRevoked = table.Column(type: "BIT", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_user_refresh_token", x => x.Id); + table.ForeignKey( + name: "FK_user_refresh_token_user_UserId", + column: x => x.UserId, + principalTable: "user", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "user_role", + columns: table => new + { + UserId = table.Column(type: "BIGINT", nullable: false), + RoleId = table.Column(type: "CHAR(36)", nullable: false), + RoleName = table.Column(type: "NVARCHAR2(50)", maxLength: 50, nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_user_role", x => new { x.UserId, x.RoleId }); + table.ForeignKey( + name: "FK_user_role_user_UserId", + column: x => x.UserId, + principalTable: "user", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_ExpiresAt_StatusName", + table: "CAPPublishedMessage", + columns: new[] { "ExpiresAt", "StatusName" }); + + migrationBuilder.CreateIndex( + name: "IX_Version_ExpiresAt_StatusName", + table: "CAPPublishedMessage", + columns: new[] { "Version", "ExpiresAt", "StatusName" }); + + migrationBuilder.CreateIndex( + name: "IX_ExpiresAt_StatusName1", + table: "CAPReceivedMessage", + columns: new[] { "ExpiresAt", "StatusName" }); + + migrationBuilder.CreateIndex( + name: "IX_Version_ExpiresAt_StatusName1", + table: "CAPReceivedMessage", + columns: new[] { "Version", "ExpiresAt", "StatusName" }); + + migrationBuilder.CreateIndex( + name: "IX_dept_IsDeleted", + table: "dept", + column: "IsDeleted"); + + migrationBuilder.CreateIndex( + name: "IX_dept_ParentId", + table: "dept", + column: "ParentId"); + + migrationBuilder.CreateIndex( + name: "IX_dept_Status", + table: "dept", + column: "Status"); + + migrationBuilder.CreateIndex( + name: "IX_role_Name", + table: "role", + column: "Name", + unique: true); + + migrationBuilder.CreateIndex( + name: "IX_user_Email", + table: "user", + column: "Email"); + + migrationBuilder.CreateIndex( + name: "IX_user_Name", + table: "user", + column: "Name"); + + migrationBuilder.CreateIndex( + name: "IX_user_dept_DeptId", + table: "user_dept", + column: "DeptId"); + + migrationBuilder.CreateIndex( + name: "IX_user_dept_UserId", + table: "user_dept", + column: "UserId"); + + migrationBuilder.CreateIndex( + name: "IX_user_refresh_token_UserId", + table: "user_refresh_token", + column: "UserId"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "CAPLock"); + + migrationBuilder.DropTable( + name: "CAPPublishedMessage"); + + migrationBuilder.DropTable( + name: "CAPReceivedMessage"); + + migrationBuilder.DropTable( + name: "dept"); + + migrationBuilder.DropTable( + name: "role_permission"); + + migrationBuilder.DropTable( + name: "user_dept"); + + migrationBuilder.DropTable( + name: "user_refresh_token"); + + migrationBuilder.DropTable( + name: "user_role"); + + migrationBuilder.DropTable( + name: "role"); + + migrationBuilder.DropTable( + name: "user"); + } + } +} diff --git a/template/src/ABC.Template.Infrastructure/MigrationsAll/DMDB-net10.0-admin/ApplicationDbContextModelSnapshot.cs b/template/src/ABC.Template.Infrastructure/MigrationsAll/DMDB-net10.0-admin/ApplicationDbContextModelSnapshot.cs new file mode 100644 index 00000000..b9696fbd --- /dev/null +++ b/template/src/ABC.Template.Infrastructure/MigrationsAll/DMDB-net10.0-admin/ApplicationDbContextModelSnapshot.cs @@ -0,0 +1,430 @@ +// +using System; +using ABC.Template.Infrastructure; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace ABC.Template.Infrastructure.Migrations +{ + [DbContext(typeof(ApplicationDbContext))] + partial class ApplicationDbContextModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("Dm:ValueGenerationStrategy", DmValueGenerationStrategy.IdentityColumn) + .HasAnnotation("ProductVersion", "9.0.1") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.DeptAggregate.Dept", b => + { + b.Property("Id") + .HasColumnType("BIGINT"); + + b.Property("CreatedAt") + .HasColumnType("DATETIME WITH TIME ZONE"); + + b.Property("DeletedAt") + .HasColumnType("DATETIME WITH TIME ZONE"); + + b.Property("IsDeleted") + .HasColumnType("BIT"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("NVARCHAR2(100)"); + + b.Property("ParentId") + .HasColumnType("BIGINT"); + + b.Property("Remark") + .IsRequired() + .HasMaxLength(500) + .HasColumnType("NVARCHAR2(500)"); + + b.Property("Status") + .HasColumnType("INT"); + + b.Property("UpdateTime") + .HasColumnType("DATETIME WITH TIME ZONE"); + + b.HasKey("Id"); + + b.HasIndex("IsDeleted"); + + b.HasIndex("ParentId"); + + b.HasIndex("Status"); + + b.ToTable("dept", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.Role", b => + { + b.Property("Id") + .HasColumnType("CHAR(36)"); + + b.Property("CreatedAt") + .HasColumnType("DATETIME WITH TIME ZONE"); + + b.Property("DeletedAt") + .HasColumnType("DATETIME WITH TIME ZONE"); + + b.Property("Description") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("NVARCHAR2(200)"); + + b.Property("IsActive") + .HasColumnType("BIT"); + + b.Property("IsDeleted") + .HasColumnType("BIT"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("NVARCHAR2(50)"); + + b.HasKey("Id"); + + b.HasIndex("Name") + .IsUnique(); + + b.ToTable("role", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.RolePermission", b => + { + b.Property("RoleId") + .HasColumnType("CHAR(36)"); + + b.Property("PermissionCode") + .HasMaxLength(100) + .HasColumnType("NVARCHAR2(100)"); + + b.Property("PermissionDescription") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("NVARCHAR2(200)"); + + b.Property("PermissionName") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("NVARCHAR2(100)"); + + b.HasKey("RoleId", "PermissionCode"); + + b.ToTable("role_permission", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.User", b => + { + b.Property("Id") + .HasColumnType("BIGINT"); + + b.Property("Age") + .HasColumnType("INT"); + + b.Property("BirthDate") + .HasColumnType("DATETIME WITH TIME ZONE"); + + b.Property("CreatedAt") + .HasColumnType("DATETIME WITH TIME ZONE"); + + b.Property("DeletedAt") + .HasColumnType("DATETIME WITH TIME ZONE"); + + b.Property("Email") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("NVARCHAR2(100)"); + + b.Property("Gender") + .IsRequired() + .HasMaxLength(10) + .HasColumnType("NVARCHAR2(10)"); + + b.Property("IsActive") + .HasColumnType("BIT"); + + b.Property("IsDeleted") + .HasColumnType("BIT"); + + b.Property("LastLoginTime") + .HasColumnType("DATETIME WITH TIME ZONE"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("NVARCHAR2(50)"); + + b.Property("PasswordHash") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("NVARCHAR2(255)"); + + b.Property("Phone") + .IsRequired() + .HasMaxLength(20) + .HasColumnType("NVARCHAR2(20)"); + + b.Property("RealName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("NVARCHAR2(50)"); + + b.Property("Status") + .HasColumnType("INT"); + + b.Property("UpdateTime") + .HasColumnType("DATETIME WITH TIME ZONE"); + + b.HasKey("Id"); + + b.HasIndex("Email"); + + b.HasIndex("Name"); + + b.ToTable("user", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserDept", b => + { + b.Property("UserId") + .HasColumnType("BIGINT"); + + b.Property("AssignedAt") + .HasColumnType("DATETIME WITH TIME ZONE"); + + b.Property("DeptId") + .HasColumnType("BIGINT"); + + b.Property("DeptName") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("NVARCHAR2(100)"); + + b.HasKey("UserId"); + + b.HasIndex("DeptId"); + + b.HasIndex("UserId"); + + b.ToTable("user_dept", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRefreshToken", b => + { + b.Property("Id") + .HasColumnType("BIGINT"); + + b.Property("CreatedTime") + .HasColumnType("DATETIME WITH TIME ZONE"); + + b.Property("ExpiresTime") + .HasColumnType("DATETIME WITH TIME ZONE"); + + b.Property("IsRevoked") + .HasColumnType("BIT"); + + b.Property("IsUsed") + .HasColumnType("BIT"); + + b.Property("Token") + .IsRequired() + .HasMaxLength(500) + .HasColumnType("NVARCHAR2(500)"); + + b.Property("UserId") + .HasColumnType("BIGINT"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("user_refresh_token", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRole", b => + { + b.Property("UserId") + .HasColumnType("BIGINT"); + + b.Property("RoleId") + .HasColumnType("CHAR(36)"); + + b.Property("RoleName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("NVARCHAR2(50)"); + + b.HasKey("UserId", "RoleId"); + + b.ToTable("user_role", (string)null); + }); + + modelBuilder.Entity("NetCorePal.Extensions.DistributedTransactions.CAP.Persistence.CapLock", b => + { + b.Property("Key") + .HasMaxLength(128) + .HasColumnType("NVARCHAR2(128)"); + + b.Property("Instance") + .HasMaxLength(256) + .HasColumnType("NVARCHAR2(256)"); + + b.Property("LastLockTime") + .HasColumnType("TIMESTAMP"); + + b.HasKey("Key"); + + b.ToTable("CAPLock", (string)null); + }); + + modelBuilder.Entity("NetCorePal.Extensions.DistributedTransactions.CAP.Persistence.PublishedMessage", b => + { + b.Property("Id") + .HasColumnType("BIGINT"); + + b.Property("Added") + .HasColumnType("TIMESTAMP"); + + b.Property("Content") + .HasColumnType("TEXT"); + + b.Property("ExpiresAt") + .HasColumnType("TIMESTAMP"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("NVARCHAR2(200)"); + + b.Property("Retries") + .HasColumnType("INT"); + + b.Property("StatusName") + .IsRequired() + .HasMaxLength(40) + .HasColumnType("NVARCHAR2(40)"); + + b.Property("Version") + .HasMaxLength(20) + .HasColumnType("NVARCHAR2(20)"); + + b.HasKey("Id"); + + b.HasIndex(new[] { "ExpiresAt", "StatusName" }, "IX_ExpiresAt_StatusName"); + + b.HasIndex(new[] { "Version", "ExpiresAt", "StatusName" }, "IX_Version_ExpiresAt_StatusName"); + + b.ToTable("CAPPublishedMessage", (string)null); + }); + + modelBuilder.Entity("NetCorePal.Extensions.DistributedTransactions.CAP.Persistence.ReceivedMessage", b => + { + b.Property("Id") + .HasColumnType("BIGINT"); + + b.Property("Added") + .HasColumnType("TIMESTAMP"); + + b.Property("Content") + .HasColumnType("TEXT"); + + b.Property("ExpiresAt") + .HasColumnType("TIMESTAMP"); + + b.Property("Group") + .HasMaxLength(200) + .HasColumnType("NVARCHAR2(200)"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(400) + .HasColumnType("NVARCHAR2(400)"); + + b.Property("Retries") + .HasColumnType("INT"); + + b.Property("StatusName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("NVARCHAR2(50)"); + + b.Property("Version") + .HasMaxLength(20) + .HasColumnType("NVARCHAR2(20)"); + + b.HasKey("Id"); + + b.HasIndex(new[] { "ExpiresAt", "StatusName" }, "IX_ExpiresAt_StatusName") + .HasDatabaseName("IX_ExpiresAt_StatusName1"); + + b.HasIndex(new[] { "Version", "ExpiresAt", "StatusName" }, "IX_Version_ExpiresAt_StatusName") + .HasDatabaseName("IX_Version_ExpiresAt_StatusName1"); + + b.ToTable("CAPReceivedMessage", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.RolePermission", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.RoleAggregate.Role", null) + .WithMany("Permissions") + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserDept", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.UserAggregate.User", null) + .WithOne("Dept") + .HasForeignKey("ABC.Template.Domain.AggregatesModel.UserAggregate.UserDept", "UserId") + .OnDelete(DeleteBehavior.ClientCascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRefreshToken", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.UserAggregate.User", null) + .WithMany("RefreshTokens") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRole", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.UserAggregate.User", null) + .WithMany("Roles") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.Role", b => + { + b.Navigation("Permissions"); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.User", b => + { + b.Navigation("Dept") + .IsRequired(); + + b.Navigation("RefreshTokens"); + + b.Navigation("Roles"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/template/src/ABC.Template.Infrastructure/MigrationsAll/DMDB-net10.0/20251225065235_Init.Designer.cs b/template/src/ABC.Template.Infrastructure/MigrationsAll/DMDB-net10.0/20260122055114_Init.Designer.cs similarity index 77% rename from template/src/ABC.Template.Infrastructure/MigrationsAll/DMDB-net10.0/20251225065235_Init.Designer.cs rename to template/src/ABC.Template.Infrastructure/MigrationsAll/DMDB-net10.0/20260122055114_Init.Designer.cs index a0f48b28..0c19ca2d 100644 --- a/template/src/ABC.Template.Infrastructure/MigrationsAll/DMDB-net10.0/20251225065235_Init.Designer.cs +++ b/template/src/ABC.Template.Infrastructure/MigrationsAll/DMDB-net10.0/20260122055114_Init.Designer.cs @@ -1,18 +1,18 @@ // using System; +using ABC.Template.Infrastructure; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using ABC.Template.Infrastructure; #nullable disable namespace ABC.Template.Infrastructure.Migrations { [DbContext(typeof(ApplicationDbContext))] - [Migration("20251225065235_Init")] + [Migration("20260122055114_Init")] partial class Init { /// @@ -127,47 +127,6 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.ToTable("CAPReceivedMessage", (string)null); }); - - modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.DeliverAggregate.DeliverRecord", b => - { - b.Property("Id") - .HasColumnType("CHAR(36)"); - - b.Property("OrderId") - .HasColumnType("CHAR(36)"); - - b.HasKey("Id"); - - b.ToTable("deliverrecord", (string)null); - }); - - modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.OrderAggregate.Order", b => - { - b.Property("Id") - .HasColumnType("CHAR(36)"); - - b.Property("Count") - .HasColumnType("INT"); - - b.Property("Name") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("NVARCHAR2(100)"); - - b.Property("Paid") - .HasColumnType("BIT"); - - b.Property("RowVersion") - .IsConcurrencyToken() - .HasColumnType("INT"); - - b.Property("UpdateTime") - .HasColumnType("DATETIME WITH TIME ZONE"); - - b.HasKey("Id"); - - b.ToTable("order", (string)null); - }); #pragma warning restore 612, 618 } } diff --git a/template/src/ABC.Template.Infrastructure/MigrationsAll/DMDB-net9.0/20251225065224_Init.cs b/template/src/ABC.Template.Infrastructure/MigrationsAll/DMDB-net10.0/20260122055114_Init.cs similarity index 75% rename from template/src/ABC.Template.Infrastructure/MigrationsAll/DMDB-net9.0/20251225065224_Init.cs rename to template/src/ABC.Template.Infrastructure/MigrationsAll/DMDB-net10.0/20260122055114_Init.cs index bdee868c..a7e91c5a 100644 --- a/template/src/ABC.Template.Infrastructure/MigrationsAll/DMDB-net9.0/20251225065224_Init.cs +++ b/template/src/ABC.Template.Infrastructure/MigrationsAll/DMDB-net10.0/20260122055114_Init.cs @@ -61,34 +61,6 @@ protected override void Up(MigrationBuilder migrationBuilder) table.PrimaryKey("PK_CAPReceivedMessage", x => x.Id); }); - migrationBuilder.CreateTable( - name: "deliverrecord", - columns: table => new - { - Id = table.Column(type: "CHAR(36)", nullable: false), - OrderId = table.Column(type: "CHAR(36)", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_deliverrecord", x => x.Id); - }); - - migrationBuilder.CreateTable( - name: "order", - columns: table => new - { - Id = table.Column(type: "CHAR(36)", nullable: false), - Paid = table.Column(type: "BIT", nullable: false), - Name = table.Column(type: "NVARCHAR2(100)", maxLength: 100, nullable: false), - Count = table.Column(type: "INT", nullable: false), - RowVersion = table.Column(type: "INT", nullable: false), - UpdateTime = table.Column(type: "DATETIME WITH TIME ZONE", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_order", x => x.Id); - }); - migrationBuilder.CreateIndex( name: "IX_ExpiresAt_StatusName", table: "CAPPublishedMessage", @@ -121,12 +93,6 @@ protected override void Down(MigrationBuilder migrationBuilder) migrationBuilder.DropTable( name: "CAPReceivedMessage"); - - migrationBuilder.DropTable( - name: "deliverrecord"); - - migrationBuilder.DropTable( - name: "order"); } } } diff --git a/template/src/ABC.Template.Infrastructure/MigrationsAll/DMDB-net10.0/ApplicationDbContextModelSnapshot.cs b/template/src/ABC.Template.Infrastructure/MigrationsAll/DMDB-net10.0/ApplicationDbContextModelSnapshot.cs index 15a914ec..4c9ac7d8 100644 --- a/template/src/ABC.Template.Infrastructure/MigrationsAll/DMDB-net10.0/ApplicationDbContextModelSnapshot.cs +++ b/template/src/ABC.Template.Infrastructure/MigrationsAll/DMDB-net10.0/ApplicationDbContextModelSnapshot.cs @@ -1,10 +1,10 @@ // using System; +using ABC.Template.Infrastructure; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using ABC.Template.Infrastructure; #nullable disable @@ -124,47 +124,6 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.ToTable("CAPReceivedMessage", (string)null); }); - - modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.DeliverAggregate.DeliverRecord", b => - { - b.Property("Id") - .HasColumnType("CHAR(36)"); - - b.Property("OrderId") - .HasColumnType("CHAR(36)"); - - b.HasKey("Id"); - - b.ToTable("deliverrecord", (string)null); - }); - - modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.OrderAggregate.Order", b => - { - b.Property("Id") - .HasColumnType("CHAR(36)"); - - b.Property("Count") - .HasColumnType("INT"); - - b.Property("Name") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("NVARCHAR2(100)"); - - b.Property("Paid") - .HasColumnType("BIT"); - - b.Property("RowVersion") - .IsConcurrencyToken() - .HasColumnType("INT"); - - b.Property("UpdateTime") - .HasColumnType("DATETIME WITH TIME ZONE"); - - b.HasKey("Id"); - - b.ToTable("order", (string)null); - }); #pragma warning restore 612, 618 } } diff --git a/template/src/ABC.Template.Infrastructure/MigrationsAll/DMDB-net8.0-admin/20260122055043_Init.Designer.cs b/template/src/ABC.Template.Infrastructure/MigrationsAll/DMDB-net8.0-admin/20260122055043_Init.Designer.cs new file mode 100644 index 00000000..1724eb19 --- /dev/null +++ b/template/src/ABC.Template.Infrastructure/MigrationsAll/DMDB-net8.0-admin/20260122055043_Init.Designer.cs @@ -0,0 +1,433 @@ +// +using System; +using ABC.Template.Infrastructure; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace ABC.Template.Infrastructure.Migrations +{ + [DbContext(typeof(ApplicationDbContext))] + [Migration("20260122055043_Init")] + partial class Init + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("Dm:ValueGenerationStrategy", DmValueGenerationStrategy.IdentityColumn) + .HasAnnotation("ProductVersion", "8.0.10") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.DeptAggregate.Dept", b => + { + b.Property("Id") + .HasColumnType("BIGINT"); + + b.Property("CreatedAt") + .HasColumnType("DATETIME WITH TIME ZONE"); + + b.Property("DeletedAt") + .HasColumnType("DATETIME WITH TIME ZONE"); + + b.Property("IsDeleted") + .HasColumnType("BIT"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("NVARCHAR2(100)"); + + b.Property("ParentId") + .HasColumnType("BIGINT"); + + b.Property("Remark") + .IsRequired() + .HasMaxLength(500) + .HasColumnType("NVARCHAR2(500)"); + + b.Property("Status") + .HasColumnType("INT"); + + b.Property("UpdateTime") + .HasColumnType("DATETIME WITH TIME ZONE"); + + b.HasKey("Id"); + + b.HasIndex("IsDeleted"); + + b.HasIndex("ParentId"); + + b.HasIndex("Status"); + + b.ToTable("dept", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.Role", b => + { + b.Property("Id") + .HasColumnType("CHAR(36)"); + + b.Property("CreatedAt") + .HasColumnType("DATETIME WITH TIME ZONE"); + + b.Property("DeletedAt") + .HasColumnType("DATETIME WITH TIME ZONE"); + + b.Property("Description") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("NVARCHAR2(200)"); + + b.Property("IsActive") + .HasColumnType("BIT"); + + b.Property("IsDeleted") + .HasColumnType("BIT"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("NVARCHAR2(50)"); + + b.HasKey("Id"); + + b.HasIndex("Name") + .IsUnique(); + + b.ToTable("role", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.RolePermission", b => + { + b.Property("RoleId") + .HasColumnType("CHAR(36)"); + + b.Property("PermissionCode") + .HasMaxLength(100) + .HasColumnType("NVARCHAR2(100)"); + + b.Property("PermissionDescription") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("NVARCHAR2(200)"); + + b.Property("PermissionName") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("NVARCHAR2(100)"); + + b.HasKey("RoleId", "PermissionCode"); + + b.ToTable("role_permission", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.User", b => + { + b.Property("Id") + .HasColumnType("BIGINT"); + + b.Property("Age") + .HasColumnType("INT"); + + b.Property("BirthDate") + .HasColumnType("DATETIME WITH TIME ZONE"); + + b.Property("CreatedAt") + .HasColumnType("DATETIME WITH TIME ZONE"); + + b.Property("DeletedAt") + .HasColumnType("DATETIME WITH TIME ZONE"); + + b.Property("Email") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("NVARCHAR2(100)"); + + b.Property("Gender") + .IsRequired() + .HasMaxLength(10) + .HasColumnType("NVARCHAR2(10)"); + + b.Property("IsActive") + .HasColumnType("BIT"); + + b.Property("IsDeleted") + .HasColumnType("BIT"); + + b.Property("LastLoginTime") + .HasColumnType("DATETIME WITH TIME ZONE"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("NVARCHAR2(50)"); + + b.Property("PasswordHash") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("NVARCHAR2(255)"); + + b.Property("Phone") + .IsRequired() + .HasMaxLength(20) + .HasColumnType("NVARCHAR2(20)"); + + b.Property("RealName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("NVARCHAR2(50)"); + + b.Property("Status") + .HasColumnType("INT"); + + b.Property("UpdateTime") + .HasColumnType("DATETIME WITH TIME ZONE"); + + b.HasKey("Id"); + + b.HasIndex("Email"); + + b.HasIndex("Name"); + + b.ToTable("user", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserDept", b => + { + b.Property("UserId") + .HasColumnType("BIGINT"); + + b.Property("AssignedAt") + .HasColumnType("DATETIME WITH TIME ZONE"); + + b.Property("DeptId") + .HasColumnType("BIGINT"); + + b.Property("DeptName") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("NVARCHAR2(100)"); + + b.HasKey("UserId"); + + b.HasIndex("DeptId"); + + b.HasIndex("UserId"); + + b.ToTable("user_dept", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRefreshToken", b => + { + b.Property("Id") + .HasColumnType("BIGINT"); + + b.Property("CreatedTime") + .HasColumnType("DATETIME WITH TIME ZONE"); + + b.Property("ExpiresTime") + .HasColumnType("DATETIME WITH TIME ZONE"); + + b.Property("IsRevoked") + .HasColumnType("BIT"); + + b.Property("IsUsed") + .HasColumnType("BIT"); + + b.Property("Token") + .IsRequired() + .HasMaxLength(500) + .HasColumnType("NVARCHAR2(500)"); + + b.Property("UserId") + .HasColumnType("BIGINT"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("user_refresh_token", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRole", b => + { + b.Property("UserId") + .HasColumnType("BIGINT"); + + b.Property("RoleId") + .HasColumnType("CHAR(36)"); + + b.Property("RoleName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("NVARCHAR2(50)"); + + b.HasKey("UserId", "RoleId"); + + b.ToTable("user_role", (string)null); + }); + + modelBuilder.Entity("NetCorePal.Extensions.DistributedTransactions.CAP.Persistence.CapLock", b => + { + b.Property("Key") + .HasMaxLength(128) + .HasColumnType("NVARCHAR2(128)"); + + b.Property("Instance") + .HasMaxLength(256) + .HasColumnType("NVARCHAR2(256)"); + + b.Property("LastLockTime") + .HasColumnType("TIMESTAMP"); + + b.HasKey("Key"); + + b.ToTable("CAPLock", (string)null); + }); + + modelBuilder.Entity("NetCorePal.Extensions.DistributedTransactions.CAP.Persistence.PublishedMessage", b => + { + b.Property("Id") + .HasColumnType("BIGINT"); + + b.Property("Added") + .HasColumnType("TIMESTAMP"); + + b.Property("Content") + .HasColumnType("TEXT"); + + b.Property("ExpiresAt") + .HasColumnType("TIMESTAMP"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("NVARCHAR2(200)"); + + b.Property("Retries") + .HasColumnType("INT"); + + b.Property("StatusName") + .IsRequired() + .HasMaxLength(40) + .HasColumnType("NVARCHAR2(40)"); + + b.Property("Version") + .HasMaxLength(20) + .HasColumnType("NVARCHAR2(20)"); + + b.HasKey("Id"); + + b.HasIndex(new[] { "ExpiresAt", "StatusName" }, "IX_ExpiresAt_StatusName"); + + b.HasIndex(new[] { "Version", "ExpiresAt", "StatusName" }, "IX_Version_ExpiresAt_StatusName"); + + b.ToTable("CAPPublishedMessage", (string)null); + }); + + modelBuilder.Entity("NetCorePal.Extensions.DistributedTransactions.CAP.Persistence.ReceivedMessage", b => + { + b.Property("Id") + .HasColumnType("BIGINT"); + + b.Property("Added") + .HasColumnType("TIMESTAMP"); + + b.Property("Content") + .HasColumnType("TEXT"); + + b.Property("ExpiresAt") + .HasColumnType("TIMESTAMP"); + + b.Property("Group") + .HasMaxLength(200) + .HasColumnType("NVARCHAR2(200)"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(400) + .HasColumnType("NVARCHAR2(400)"); + + b.Property("Retries") + .HasColumnType("INT"); + + b.Property("StatusName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("NVARCHAR2(50)"); + + b.Property("Version") + .HasMaxLength(20) + .HasColumnType("NVARCHAR2(20)"); + + b.HasKey("Id"); + + b.HasIndex(new[] { "ExpiresAt", "StatusName" }, "IX_ExpiresAt_StatusName") + .HasDatabaseName("IX_ExpiresAt_StatusName1"); + + b.HasIndex(new[] { "Version", "ExpiresAt", "StatusName" }, "IX_Version_ExpiresAt_StatusName") + .HasDatabaseName("IX_Version_ExpiresAt_StatusName1"); + + b.ToTable("CAPReceivedMessage", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.RolePermission", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.RoleAggregate.Role", null) + .WithMany("Permissions") + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserDept", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.UserAggregate.User", null) + .WithOne("Dept") + .HasForeignKey("ABC.Template.Domain.AggregatesModel.UserAggregate.UserDept", "UserId") + .OnDelete(DeleteBehavior.ClientCascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRefreshToken", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.UserAggregate.User", null) + .WithMany("RefreshTokens") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRole", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.UserAggregate.User", null) + .WithMany("Roles") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.Role", b => + { + b.Navigation("Permissions"); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.User", b => + { + b.Navigation("Dept") + .IsRequired(); + + b.Navigation("RefreshTokens"); + + b.Navigation("Roles"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/template/src/ABC.Template.Infrastructure/MigrationsAll/DMDB-net8.0-admin/20260122055043_Init.cs b/template/src/ABC.Template.Infrastructure/MigrationsAll/DMDB-net8.0-admin/20260122055043_Init.cs new file mode 100644 index 00000000..3e54f7ab --- /dev/null +++ b/template/src/ABC.Template.Infrastructure/MigrationsAll/DMDB-net8.0-admin/20260122055043_Init.cs @@ -0,0 +1,308 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace ABC.Template.Infrastructure.Migrations +{ + /// + public partial class Init : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "CAPLock", + columns: table => new + { + Key = table.Column(type: "NVARCHAR2(128)", maxLength: 128, nullable: false), + Instance = table.Column(type: "NVARCHAR2(256)", maxLength: 256, nullable: true), + LastLockTime = table.Column(type: "TIMESTAMP", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_CAPLock", x => x.Key); + }); + + migrationBuilder.CreateTable( + name: "CAPPublishedMessage", + columns: table => new + { + Id = table.Column(type: "BIGINT", nullable: false), + Version = table.Column(type: "NVARCHAR2(20)", maxLength: 20, nullable: true), + Name = table.Column(type: "NVARCHAR2(200)", maxLength: 200, nullable: false), + Content = table.Column(type: "TEXT", nullable: true), + Retries = table.Column(type: "INT", nullable: true), + Added = table.Column(type: "TIMESTAMP", nullable: false), + ExpiresAt = table.Column(type: "TIMESTAMP", nullable: true), + StatusName = table.Column(type: "NVARCHAR2(40)", maxLength: 40, nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_CAPPublishedMessage", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "CAPReceivedMessage", + columns: table => new + { + Id = table.Column(type: "BIGINT", nullable: false), + Version = table.Column(type: "NVARCHAR2(20)", maxLength: 20, nullable: true), + Name = table.Column(type: "NVARCHAR2(400)", maxLength: 400, nullable: false), + Group = table.Column(type: "NVARCHAR2(200)", maxLength: 200, nullable: true), + Content = table.Column(type: "TEXT", nullable: true), + Retries = table.Column(type: "INT", nullable: true), + Added = table.Column(type: "TIMESTAMP", nullable: false), + ExpiresAt = table.Column(type: "TIMESTAMP", nullable: true), + StatusName = table.Column(type: "NVARCHAR2(50)", maxLength: 50, nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_CAPReceivedMessage", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "dept", + columns: table => new + { + Id = table.Column(type: "BIGINT", nullable: false), + Name = table.Column(type: "NVARCHAR2(100)", maxLength: 100, nullable: false), + Remark = table.Column(type: "NVARCHAR2(500)", maxLength: 500, nullable: false), + ParentId = table.Column(type: "BIGINT", nullable: false), + Status = table.Column(type: "INT", nullable: false), + CreatedAt = table.Column(type: "DATETIME WITH TIME ZONE", nullable: false), + IsDeleted = table.Column(type: "BIT", nullable: false), + DeletedAt = table.Column(type: "DATETIME WITH TIME ZONE", nullable: false), + UpdateTime = table.Column(type: "DATETIME WITH TIME ZONE", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_dept", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "role", + columns: table => new + { + Id = table.Column(type: "CHAR(36)", nullable: false), + Name = table.Column(type: "NVARCHAR2(50)", maxLength: 50, nullable: false), + Description = table.Column(type: "NVARCHAR2(200)", maxLength: 200, nullable: false), + CreatedAt = table.Column(type: "DATETIME WITH TIME ZONE", nullable: false), + IsActive = table.Column(type: "BIT", nullable: false), + IsDeleted = table.Column(type: "BIT", nullable: false), + DeletedAt = table.Column(type: "DATETIME WITH TIME ZONE", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_role", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "user", + columns: table => new + { + Id = table.Column(type: "BIGINT", nullable: false), + Name = table.Column(type: "NVARCHAR2(50)", maxLength: 50, nullable: false), + Email = table.Column(type: "NVARCHAR2(100)", maxLength: 100, nullable: false), + Phone = table.Column(type: "NVARCHAR2(20)", maxLength: 20, nullable: false), + RealName = table.Column(type: "NVARCHAR2(50)", maxLength: 50, nullable: false), + Status = table.Column(type: "INT", nullable: false), + PasswordHash = table.Column(type: "NVARCHAR2(255)", maxLength: 255, nullable: false), + IsActive = table.Column(type: "BIT", nullable: false), + CreatedAt = table.Column(type: "DATETIME WITH TIME ZONE", nullable: false), + LastLoginTime = table.Column(type: "DATETIME WITH TIME ZONE", nullable: true), + UpdateTime = table.Column(type: "DATETIME WITH TIME ZONE", nullable: false), + IsDeleted = table.Column(type: "BIT", nullable: false), + DeletedAt = table.Column(type: "DATETIME WITH TIME ZONE", nullable: false), + Gender = table.Column(type: "NVARCHAR2(10)", maxLength: 10, nullable: false), + Age = table.Column(type: "INT", nullable: false), + BirthDate = table.Column(type: "DATETIME WITH TIME ZONE", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_user", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "role_permission", + columns: table => new + { + RoleId = table.Column(type: "CHAR(36)", nullable: false), + PermissionCode = table.Column(type: "NVARCHAR2(100)", maxLength: 100, nullable: false), + PermissionName = table.Column(type: "NVARCHAR2(100)", maxLength: 100, nullable: false), + PermissionDescription = table.Column(type: "NVARCHAR2(200)", maxLength: 200, nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_role_permission", x => new { x.RoleId, x.PermissionCode }); + table.ForeignKey( + name: "FK_role_permission_role_RoleId", + column: x => x.RoleId, + principalTable: "role", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "user_dept", + columns: table => new + { + UserId = table.Column(type: "BIGINT", nullable: false), + DeptId = table.Column(type: "BIGINT", nullable: false), + DeptName = table.Column(type: "NVARCHAR2(100)", maxLength: 100, nullable: false), + AssignedAt = table.Column(type: "DATETIME WITH TIME ZONE", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_user_dept", x => x.UserId); + table.ForeignKey( + name: "FK_user_dept_user_UserId", + column: x => x.UserId, + principalTable: "user", + principalColumn: "Id"); + }); + + migrationBuilder.CreateTable( + name: "user_refresh_token", + columns: table => new + { + Id = table.Column(type: "BIGINT", nullable: false), + UserId = table.Column(type: "BIGINT", nullable: false), + Token = table.Column(type: "NVARCHAR2(500)", maxLength: 500, nullable: false), + CreatedTime = table.Column(type: "DATETIME WITH TIME ZONE", nullable: false), + ExpiresTime = table.Column(type: "DATETIME WITH TIME ZONE", nullable: false), + IsUsed = table.Column(type: "BIT", nullable: false), + IsRevoked = table.Column(type: "BIT", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_user_refresh_token", x => x.Id); + table.ForeignKey( + name: "FK_user_refresh_token_user_UserId", + column: x => x.UserId, + principalTable: "user", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "user_role", + columns: table => new + { + UserId = table.Column(type: "BIGINT", nullable: false), + RoleId = table.Column(type: "CHAR(36)", nullable: false), + RoleName = table.Column(type: "NVARCHAR2(50)", maxLength: 50, nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_user_role", x => new { x.UserId, x.RoleId }); + table.ForeignKey( + name: "FK_user_role_user_UserId", + column: x => x.UserId, + principalTable: "user", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_ExpiresAt_StatusName", + table: "CAPPublishedMessage", + columns: new[] { "ExpiresAt", "StatusName" }); + + migrationBuilder.CreateIndex( + name: "IX_Version_ExpiresAt_StatusName", + table: "CAPPublishedMessage", + columns: new[] { "Version", "ExpiresAt", "StatusName" }); + + migrationBuilder.CreateIndex( + name: "IX_ExpiresAt_StatusName1", + table: "CAPReceivedMessage", + columns: new[] { "ExpiresAt", "StatusName" }); + + migrationBuilder.CreateIndex( + name: "IX_Version_ExpiresAt_StatusName1", + table: "CAPReceivedMessage", + columns: new[] { "Version", "ExpiresAt", "StatusName" }); + + migrationBuilder.CreateIndex( + name: "IX_dept_IsDeleted", + table: "dept", + column: "IsDeleted"); + + migrationBuilder.CreateIndex( + name: "IX_dept_ParentId", + table: "dept", + column: "ParentId"); + + migrationBuilder.CreateIndex( + name: "IX_dept_Status", + table: "dept", + column: "Status"); + + migrationBuilder.CreateIndex( + name: "IX_role_Name", + table: "role", + column: "Name", + unique: true); + + migrationBuilder.CreateIndex( + name: "IX_user_Email", + table: "user", + column: "Email"); + + migrationBuilder.CreateIndex( + name: "IX_user_Name", + table: "user", + column: "Name"); + + migrationBuilder.CreateIndex( + name: "IX_user_dept_DeptId", + table: "user_dept", + column: "DeptId"); + + migrationBuilder.CreateIndex( + name: "IX_user_dept_UserId", + table: "user_dept", + column: "UserId"); + + migrationBuilder.CreateIndex( + name: "IX_user_refresh_token_UserId", + table: "user_refresh_token", + column: "UserId"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "CAPLock"); + + migrationBuilder.DropTable( + name: "CAPPublishedMessage"); + + migrationBuilder.DropTable( + name: "CAPReceivedMessage"); + + migrationBuilder.DropTable( + name: "dept"); + + migrationBuilder.DropTable( + name: "role_permission"); + + migrationBuilder.DropTable( + name: "user_dept"); + + migrationBuilder.DropTable( + name: "user_refresh_token"); + + migrationBuilder.DropTable( + name: "user_role"); + + migrationBuilder.DropTable( + name: "role"); + + migrationBuilder.DropTable( + name: "user"); + } + } +} diff --git a/template/src/ABC.Template.Infrastructure/MigrationsAll/DMDB-net8.0-admin/ApplicationDbContextModelSnapshot.cs b/template/src/ABC.Template.Infrastructure/MigrationsAll/DMDB-net8.0-admin/ApplicationDbContextModelSnapshot.cs new file mode 100644 index 00000000..13b94550 --- /dev/null +++ b/template/src/ABC.Template.Infrastructure/MigrationsAll/DMDB-net8.0-admin/ApplicationDbContextModelSnapshot.cs @@ -0,0 +1,430 @@ +// +using System; +using ABC.Template.Infrastructure; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace ABC.Template.Infrastructure.Migrations +{ + [DbContext(typeof(ApplicationDbContext))] + partial class ApplicationDbContextModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("Dm:ValueGenerationStrategy", DmValueGenerationStrategy.IdentityColumn) + .HasAnnotation("ProductVersion", "8.0.10") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.DeptAggregate.Dept", b => + { + b.Property("Id") + .HasColumnType("BIGINT"); + + b.Property("CreatedAt") + .HasColumnType("DATETIME WITH TIME ZONE"); + + b.Property("DeletedAt") + .HasColumnType("DATETIME WITH TIME ZONE"); + + b.Property("IsDeleted") + .HasColumnType("BIT"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("NVARCHAR2(100)"); + + b.Property("ParentId") + .HasColumnType("BIGINT"); + + b.Property("Remark") + .IsRequired() + .HasMaxLength(500) + .HasColumnType("NVARCHAR2(500)"); + + b.Property("Status") + .HasColumnType("INT"); + + b.Property("UpdateTime") + .HasColumnType("DATETIME WITH TIME ZONE"); + + b.HasKey("Id"); + + b.HasIndex("IsDeleted"); + + b.HasIndex("ParentId"); + + b.HasIndex("Status"); + + b.ToTable("dept", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.Role", b => + { + b.Property("Id") + .HasColumnType("CHAR(36)"); + + b.Property("CreatedAt") + .HasColumnType("DATETIME WITH TIME ZONE"); + + b.Property("DeletedAt") + .HasColumnType("DATETIME WITH TIME ZONE"); + + b.Property("Description") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("NVARCHAR2(200)"); + + b.Property("IsActive") + .HasColumnType("BIT"); + + b.Property("IsDeleted") + .HasColumnType("BIT"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("NVARCHAR2(50)"); + + b.HasKey("Id"); + + b.HasIndex("Name") + .IsUnique(); + + b.ToTable("role", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.RolePermission", b => + { + b.Property("RoleId") + .HasColumnType("CHAR(36)"); + + b.Property("PermissionCode") + .HasMaxLength(100) + .HasColumnType("NVARCHAR2(100)"); + + b.Property("PermissionDescription") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("NVARCHAR2(200)"); + + b.Property("PermissionName") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("NVARCHAR2(100)"); + + b.HasKey("RoleId", "PermissionCode"); + + b.ToTable("role_permission", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.User", b => + { + b.Property("Id") + .HasColumnType("BIGINT"); + + b.Property("Age") + .HasColumnType("INT"); + + b.Property("BirthDate") + .HasColumnType("DATETIME WITH TIME ZONE"); + + b.Property("CreatedAt") + .HasColumnType("DATETIME WITH TIME ZONE"); + + b.Property("DeletedAt") + .HasColumnType("DATETIME WITH TIME ZONE"); + + b.Property("Email") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("NVARCHAR2(100)"); + + b.Property("Gender") + .IsRequired() + .HasMaxLength(10) + .HasColumnType("NVARCHAR2(10)"); + + b.Property("IsActive") + .HasColumnType("BIT"); + + b.Property("IsDeleted") + .HasColumnType("BIT"); + + b.Property("LastLoginTime") + .HasColumnType("DATETIME WITH TIME ZONE"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("NVARCHAR2(50)"); + + b.Property("PasswordHash") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("NVARCHAR2(255)"); + + b.Property("Phone") + .IsRequired() + .HasMaxLength(20) + .HasColumnType("NVARCHAR2(20)"); + + b.Property("RealName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("NVARCHAR2(50)"); + + b.Property("Status") + .HasColumnType("INT"); + + b.Property("UpdateTime") + .HasColumnType("DATETIME WITH TIME ZONE"); + + b.HasKey("Id"); + + b.HasIndex("Email"); + + b.HasIndex("Name"); + + b.ToTable("user", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserDept", b => + { + b.Property("UserId") + .HasColumnType("BIGINT"); + + b.Property("AssignedAt") + .HasColumnType("DATETIME WITH TIME ZONE"); + + b.Property("DeptId") + .HasColumnType("BIGINT"); + + b.Property("DeptName") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("NVARCHAR2(100)"); + + b.HasKey("UserId"); + + b.HasIndex("DeptId"); + + b.HasIndex("UserId"); + + b.ToTable("user_dept", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRefreshToken", b => + { + b.Property("Id") + .HasColumnType("BIGINT"); + + b.Property("CreatedTime") + .HasColumnType("DATETIME WITH TIME ZONE"); + + b.Property("ExpiresTime") + .HasColumnType("DATETIME WITH TIME ZONE"); + + b.Property("IsRevoked") + .HasColumnType("BIT"); + + b.Property("IsUsed") + .HasColumnType("BIT"); + + b.Property("Token") + .IsRequired() + .HasMaxLength(500) + .HasColumnType("NVARCHAR2(500)"); + + b.Property("UserId") + .HasColumnType("BIGINT"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("user_refresh_token", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRole", b => + { + b.Property("UserId") + .HasColumnType("BIGINT"); + + b.Property("RoleId") + .HasColumnType("CHAR(36)"); + + b.Property("RoleName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("NVARCHAR2(50)"); + + b.HasKey("UserId", "RoleId"); + + b.ToTable("user_role", (string)null); + }); + + modelBuilder.Entity("NetCorePal.Extensions.DistributedTransactions.CAP.Persistence.CapLock", b => + { + b.Property("Key") + .HasMaxLength(128) + .HasColumnType("NVARCHAR2(128)"); + + b.Property("Instance") + .HasMaxLength(256) + .HasColumnType("NVARCHAR2(256)"); + + b.Property("LastLockTime") + .HasColumnType("TIMESTAMP"); + + b.HasKey("Key"); + + b.ToTable("CAPLock", (string)null); + }); + + modelBuilder.Entity("NetCorePal.Extensions.DistributedTransactions.CAP.Persistence.PublishedMessage", b => + { + b.Property("Id") + .HasColumnType("BIGINT"); + + b.Property("Added") + .HasColumnType("TIMESTAMP"); + + b.Property("Content") + .HasColumnType("TEXT"); + + b.Property("ExpiresAt") + .HasColumnType("TIMESTAMP"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("NVARCHAR2(200)"); + + b.Property("Retries") + .HasColumnType("INT"); + + b.Property("StatusName") + .IsRequired() + .HasMaxLength(40) + .HasColumnType("NVARCHAR2(40)"); + + b.Property("Version") + .HasMaxLength(20) + .HasColumnType("NVARCHAR2(20)"); + + b.HasKey("Id"); + + b.HasIndex(new[] { "ExpiresAt", "StatusName" }, "IX_ExpiresAt_StatusName"); + + b.HasIndex(new[] { "Version", "ExpiresAt", "StatusName" }, "IX_Version_ExpiresAt_StatusName"); + + b.ToTable("CAPPublishedMessage", (string)null); + }); + + modelBuilder.Entity("NetCorePal.Extensions.DistributedTransactions.CAP.Persistence.ReceivedMessage", b => + { + b.Property("Id") + .HasColumnType("BIGINT"); + + b.Property("Added") + .HasColumnType("TIMESTAMP"); + + b.Property("Content") + .HasColumnType("TEXT"); + + b.Property("ExpiresAt") + .HasColumnType("TIMESTAMP"); + + b.Property("Group") + .HasMaxLength(200) + .HasColumnType("NVARCHAR2(200)"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(400) + .HasColumnType("NVARCHAR2(400)"); + + b.Property("Retries") + .HasColumnType("INT"); + + b.Property("StatusName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("NVARCHAR2(50)"); + + b.Property("Version") + .HasMaxLength(20) + .HasColumnType("NVARCHAR2(20)"); + + b.HasKey("Id"); + + b.HasIndex(new[] { "ExpiresAt", "StatusName" }, "IX_ExpiresAt_StatusName") + .HasDatabaseName("IX_ExpiresAt_StatusName1"); + + b.HasIndex(new[] { "Version", "ExpiresAt", "StatusName" }, "IX_Version_ExpiresAt_StatusName") + .HasDatabaseName("IX_Version_ExpiresAt_StatusName1"); + + b.ToTable("CAPReceivedMessage", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.RolePermission", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.RoleAggregate.Role", null) + .WithMany("Permissions") + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserDept", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.UserAggregate.User", null) + .WithOne("Dept") + .HasForeignKey("ABC.Template.Domain.AggregatesModel.UserAggregate.UserDept", "UserId") + .OnDelete(DeleteBehavior.ClientCascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRefreshToken", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.UserAggregate.User", null) + .WithMany("RefreshTokens") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRole", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.UserAggregate.User", null) + .WithMany("Roles") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.Role", b => + { + b.Navigation("Permissions"); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.User", b => + { + b.Navigation("Dept") + .IsRequired(); + + b.Navigation("RefreshTokens"); + + b.Navigation("Roles"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/template/src/ABC.Template.Infrastructure/MigrationsAll/DMDB-net8.0/20251225065214_Init.Designer.cs b/template/src/ABC.Template.Infrastructure/MigrationsAll/DMDB-net8.0/20260122055033_Init.Designer.cs similarity index 77% rename from template/src/ABC.Template.Infrastructure/MigrationsAll/DMDB-net8.0/20251225065214_Init.Designer.cs rename to template/src/ABC.Template.Infrastructure/MigrationsAll/DMDB-net8.0/20260122055033_Init.Designer.cs index bf69bbdd..81ab56df 100644 --- a/template/src/ABC.Template.Infrastructure/MigrationsAll/DMDB-net8.0/20251225065214_Init.Designer.cs +++ b/template/src/ABC.Template.Infrastructure/MigrationsAll/DMDB-net8.0/20260122055033_Init.Designer.cs @@ -1,18 +1,18 @@ // using System; +using ABC.Template.Infrastructure; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using ABC.Template.Infrastructure; #nullable disable namespace ABC.Template.Infrastructure.Migrations { [DbContext(typeof(ApplicationDbContext))] - [Migration("20251225065214_Init")] + [Migration("20260122055033_Init")] partial class Init { /// @@ -127,47 +127,6 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.ToTable("CAPReceivedMessage", (string)null); }); - - modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.DeliverAggregate.DeliverRecord", b => - { - b.Property("Id") - .HasColumnType("CHAR(36)"); - - b.Property("OrderId") - .HasColumnType("CHAR(36)"); - - b.HasKey("Id"); - - b.ToTable("deliverrecord", (string)null); - }); - - modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.OrderAggregate.Order", b => - { - b.Property("Id") - .HasColumnType("CHAR(36)"); - - b.Property("Count") - .HasColumnType("INT"); - - b.Property("Name") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("NVARCHAR2(100)"); - - b.Property("Paid") - .HasColumnType("BIT"); - - b.Property("RowVersion") - .IsConcurrencyToken() - .HasColumnType("INT"); - - b.Property("UpdateTime") - .HasColumnType("DATETIME WITH TIME ZONE"); - - b.HasKey("Id"); - - b.ToTable("order", (string)null); - }); #pragma warning restore 612, 618 } } diff --git a/template/src/ABC.Template.Infrastructure/MigrationsAll/DMDB-net10.0/20251225065235_Init.cs b/template/src/ABC.Template.Infrastructure/MigrationsAll/DMDB-net8.0/20260122055033_Init.cs similarity index 75% rename from template/src/ABC.Template.Infrastructure/MigrationsAll/DMDB-net10.0/20251225065235_Init.cs rename to template/src/ABC.Template.Infrastructure/MigrationsAll/DMDB-net8.0/20260122055033_Init.cs index bdee868c..a7e91c5a 100644 --- a/template/src/ABC.Template.Infrastructure/MigrationsAll/DMDB-net10.0/20251225065235_Init.cs +++ b/template/src/ABC.Template.Infrastructure/MigrationsAll/DMDB-net8.0/20260122055033_Init.cs @@ -61,34 +61,6 @@ protected override void Up(MigrationBuilder migrationBuilder) table.PrimaryKey("PK_CAPReceivedMessage", x => x.Id); }); - migrationBuilder.CreateTable( - name: "deliverrecord", - columns: table => new - { - Id = table.Column(type: "CHAR(36)", nullable: false), - OrderId = table.Column(type: "CHAR(36)", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_deliverrecord", x => x.Id); - }); - - migrationBuilder.CreateTable( - name: "order", - columns: table => new - { - Id = table.Column(type: "CHAR(36)", nullable: false), - Paid = table.Column(type: "BIT", nullable: false), - Name = table.Column(type: "NVARCHAR2(100)", maxLength: 100, nullable: false), - Count = table.Column(type: "INT", nullable: false), - RowVersion = table.Column(type: "INT", nullable: false), - UpdateTime = table.Column(type: "DATETIME WITH TIME ZONE", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_order", x => x.Id); - }); - migrationBuilder.CreateIndex( name: "IX_ExpiresAt_StatusName", table: "CAPPublishedMessage", @@ -121,12 +93,6 @@ protected override void Down(MigrationBuilder migrationBuilder) migrationBuilder.DropTable( name: "CAPReceivedMessage"); - - migrationBuilder.DropTable( - name: "deliverrecord"); - - migrationBuilder.DropTable( - name: "order"); } } } diff --git a/template/src/ABC.Template.Infrastructure/MigrationsAll/DMDB-net8.0/ApplicationDbContextModelSnapshot.cs b/template/src/ABC.Template.Infrastructure/MigrationsAll/DMDB-net8.0/ApplicationDbContextModelSnapshot.cs index 7d3ce7e8..c53a4bb9 100644 --- a/template/src/ABC.Template.Infrastructure/MigrationsAll/DMDB-net8.0/ApplicationDbContextModelSnapshot.cs +++ b/template/src/ABC.Template.Infrastructure/MigrationsAll/DMDB-net8.0/ApplicationDbContextModelSnapshot.cs @@ -1,10 +1,10 @@ // using System; +using ABC.Template.Infrastructure; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using ABC.Template.Infrastructure; #nullable disable @@ -124,47 +124,6 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.ToTable("CAPReceivedMessage", (string)null); }); - - modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.DeliverAggregate.DeliverRecord", b => - { - b.Property("Id") - .HasColumnType("CHAR(36)"); - - b.Property("OrderId") - .HasColumnType("CHAR(36)"); - - b.HasKey("Id"); - - b.ToTable("deliverrecord", (string)null); - }); - - modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.OrderAggregate.Order", b => - { - b.Property("Id") - .HasColumnType("CHAR(36)"); - - b.Property("Count") - .HasColumnType("INT"); - - b.Property("Name") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("NVARCHAR2(100)"); - - b.Property("Paid") - .HasColumnType("BIT"); - - b.Property("RowVersion") - .IsConcurrencyToken() - .HasColumnType("INT"); - - b.Property("UpdateTime") - .HasColumnType("DATETIME WITH TIME ZONE"); - - b.HasKey("Id"); - - b.ToTable("order", (string)null); - }); #pragma warning restore 612, 618 } } diff --git a/template/src/ABC.Template.Infrastructure/MigrationsAll/DMDB-net9.0-admin/20260122055103_Init.Designer.cs b/template/src/ABC.Template.Infrastructure/MigrationsAll/DMDB-net9.0-admin/20260122055103_Init.Designer.cs new file mode 100644 index 00000000..3b5012f5 --- /dev/null +++ b/template/src/ABC.Template.Infrastructure/MigrationsAll/DMDB-net9.0-admin/20260122055103_Init.Designer.cs @@ -0,0 +1,433 @@ +// +using System; +using ABC.Template.Infrastructure; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace ABC.Template.Infrastructure.Migrations +{ + [DbContext(typeof(ApplicationDbContext))] + [Migration("20260122055103_Init")] + partial class Init + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("Dm:ValueGenerationStrategy", DmValueGenerationStrategy.IdentityColumn) + .HasAnnotation("ProductVersion", "9.0.1") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.DeptAggregate.Dept", b => + { + b.Property("Id") + .HasColumnType("BIGINT"); + + b.Property("CreatedAt") + .HasColumnType("DATETIME WITH TIME ZONE"); + + b.Property("DeletedAt") + .HasColumnType("DATETIME WITH TIME ZONE"); + + b.Property("IsDeleted") + .HasColumnType("BIT"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("NVARCHAR2(100)"); + + b.Property("ParentId") + .HasColumnType("BIGINT"); + + b.Property("Remark") + .IsRequired() + .HasMaxLength(500) + .HasColumnType("NVARCHAR2(500)"); + + b.Property("Status") + .HasColumnType("INT"); + + b.Property("UpdateTime") + .HasColumnType("DATETIME WITH TIME ZONE"); + + b.HasKey("Id"); + + b.HasIndex("IsDeleted"); + + b.HasIndex("ParentId"); + + b.HasIndex("Status"); + + b.ToTable("dept", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.Role", b => + { + b.Property("Id") + .HasColumnType("CHAR(36)"); + + b.Property("CreatedAt") + .HasColumnType("DATETIME WITH TIME ZONE"); + + b.Property("DeletedAt") + .HasColumnType("DATETIME WITH TIME ZONE"); + + b.Property("Description") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("NVARCHAR2(200)"); + + b.Property("IsActive") + .HasColumnType("BIT"); + + b.Property("IsDeleted") + .HasColumnType("BIT"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("NVARCHAR2(50)"); + + b.HasKey("Id"); + + b.HasIndex("Name") + .IsUnique(); + + b.ToTable("role", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.RolePermission", b => + { + b.Property("RoleId") + .HasColumnType("CHAR(36)"); + + b.Property("PermissionCode") + .HasMaxLength(100) + .HasColumnType("NVARCHAR2(100)"); + + b.Property("PermissionDescription") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("NVARCHAR2(200)"); + + b.Property("PermissionName") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("NVARCHAR2(100)"); + + b.HasKey("RoleId", "PermissionCode"); + + b.ToTable("role_permission", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.User", b => + { + b.Property("Id") + .HasColumnType("BIGINT"); + + b.Property("Age") + .HasColumnType("INT"); + + b.Property("BirthDate") + .HasColumnType("DATETIME WITH TIME ZONE"); + + b.Property("CreatedAt") + .HasColumnType("DATETIME WITH TIME ZONE"); + + b.Property("DeletedAt") + .HasColumnType("DATETIME WITH TIME ZONE"); + + b.Property("Email") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("NVARCHAR2(100)"); + + b.Property("Gender") + .IsRequired() + .HasMaxLength(10) + .HasColumnType("NVARCHAR2(10)"); + + b.Property("IsActive") + .HasColumnType("BIT"); + + b.Property("IsDeleted") + .HasColumnType("BIT"); + + b.Property("LastLoginTime") + .HasColumnType("DATETIME WITH TIME ZONE"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("NVARCHAR2(50)"); + + b.Property("PasswordHash") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("NVARCHAR2(255)"); + + b.Property("Phone") + .IsRequired() + .HasMaxLength(20) + .HasColumnType("NVARCHAR2(20)"); + + b.Property("RealName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("NVARCHAR2(50)"); + + b.Property("Status") + .HasColumnType("INT"); + + b.Property("UpdateTime") + .HasColumnType("DATETIME WITH TIME ZONE"); + + b.HasKey("Id"); + + b.HasIndex("Email"); + + b.HasIndex("Name"); + + b.ToTable("user", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserDept", b => + { + b.Property("UserId") + .HasColumnType("BIGINT"); + + b.Property("AssignedAt") + .HasColumnType("DATETIME WITH TIME ZONE"); + + b.Property("DeptId") + .HasColumnType("BIGINT"); + + b.Property("DeptName") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("NVARCHAR2(100)"); + + b.HasKey("UserId"); + + b.HasIndex("DeptId"); + + b.HasIndex("UserId"); + + b.ToTable("user_dept", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRefreshToken", b => + { + b.Property("Id") + .HasColumnType("BIGINT"); + + b.Property("CreatedTime") + .HasColumnType("DATETIME WITH TIME ZONE"); + + b.Property("ExpiresTime") + .HasColumnType("DATETIME WITH TIME ZONE"); + + b.Property("IsRevoked") + .HasColumnType("BIT"); + + b.Property("IsUsed") + .HasColumnType("BIT"); + + b.Property("Token") + .IsRequired() + .HasMaxLength(500) + .HasColumnType("NVARCHAR2(500)"); + + b.Property("UserId") + .HasColumnType("BIGINT"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("user_refresh_token", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRole", b => + { + b.Property("UserId") + .HasColumnType("BIGINT"); + + b.Property("RoleId") + .HasColumnType("CHAR(36)"); + + b.Property("RoleName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("NVARCHAR2(50)"); + + b.HasKey("UserId", "RoleId"); + + b.ToTable("user_role", (string)null); + }); + + modelBuilder.Entity("NetCorePal.Extensions.DistributedTransactions.CAP.Persistence.CapLock", b => + { + b.Property("Key") + .HasMaxLength(128) + .HasColumnType("NVARCHAR2(128)"); + + b.Property("Instance") + .HasMaxLength(256) + .HasColumnType("NVARCHAR2(256)"); + + b.Property("LastLockTime") + .HasColumnType("TIMESTAMP"); + + b.HasKey("Key"); + + b.ToTable("CAPLock", (string)null); + }); + + modelBuilder.Entity("NetCorePal.Extensions.DistributedTransactions.CAP.Persistence.PublishedMessage", b => + { + b.Property("Id") + .HasColumnType("BIGINT"); + + b.Property("Added") + .HasColumnType("TIMESTAMP"); + + b.Property("Content") + .HasColumnType("TEXT"); + + b.Property("ExpiresAt") + .HasColumnType("TIMESTAMP"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("NVARCHAR2(200)"); + + b.Property("Retries") + .HasColumnType("INT"); + + b.Property("StatusName") + .IsRequired() + .HasMaxLength(40) + .HasColumnType("NVARCHAR2(40)"); + + b.Property("Version") + .HasMaxLength(20) + .HasColumnType("NVARCHAR2(20)"); + + b.HasKey("Id"); + + b.HasIndex(new[] { "ExpiresAt", "StatusName" }, "IX_ExpiresAt_StatusName"); + + b.HasIndex(new[] { "Version", "ExpiresAt", "StatusName" }, "IX_Version_ExpiresAt_StatusName"); + + b.ToTable("CAPPublishedMessage", (string)null); + }); + + modelBuilder.Entity("NetCorePal.Extensions.DistributedTransactions.CAP.Persistence.ReceivedMessage", b => + { + b.Property("Id") + .HasColumnType("BIGINT"); + + b.Property("Added") + .HasColumnType("TIMESTAMP"); + + b.Property("Content") + .HasColumnType("TEXT"); + + b.Property("ExpiresAt") + .HasColumnType("TIMESTAMP"); + + b.Property("Group") + .HasMaxLength(200) + .HasColumnType("NVARCHAR2(200)"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(400) + .HasColumnType("NVARCHAR2(400)"); + + b.Property("Retries") + .HasColumnType("INT"); + + b.Property("StatusName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("NVARCHAR2(50)"); + + b.Property("Version") + .HasMaxLength(20) + .HasColumnType("NVARCHAR2(20)"); + + b.HasKey("Id"); + + b.HasIndex(new[] { "ExpiresAt", "StatusName" }, "IX_ExpiresAt_StatusName") + .HasDatabaseName("IX_ExpiresAt_StatusName1"); + + b.HasIndex(new[] { "Version", "ExpiresAt", "StatusName" }, "IX_Version_ExpiresAt_StatusName") + .HasDatabaseName("IX_Version_ExpiresAt_StatusName1"); + + b.ToTable("CAPReceivedMessage", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.RolePermission", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.RoleAggregate.Role", null) + .WithMany("Permissions") + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserDept", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.UserAggregate.User", null) + .WithOne("Dept") + .HasForeignKey("ABC.Template.Domain.AggregatesModel.UserAggregate.UserDept", "UserId") + .OnDelete(DeleteBehavior.ClientCascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRefreshToken", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.UserAggregate.User", null) + .WithMany("RefreshTokens") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRole", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.UserAggregate.User", null) + .WithMany("Roles") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.Role", b => + { + b.Navigation("Permissions"); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.User", b => + { + b.Navigation("Dept") + .IsRequired(); + + b.Navigation("RefreshTokens"); + + b.Navigation("Roles"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/template/src/ABC.Template.Infrastructure/MigrationsAll/DMDB-net9.0-admin/20260122055103_Init.cs b/template/src/ABC.Template.Infrastructure/MigrationsAll/DMDB-net9.0-admin/20260122055103_Init.cs new file mode 100644 index 00000000..3e54f7ab --- /dev/null +++ b/template/src/ABC.Template.Infrastructure/MigrationsAll/DMDB-net9.0-admin/20260122055103_Init.cs @@ -0,0 +1,308 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace ABC.Template.Infrastructure.Migrations +{ + /// + public partial class Init : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "CAPLock", + columns: table => new + { + Key = table.Column(type: "NVARCHAR2(128)", maxLength: 128, nullable: false), + Instance = table.Column(type: "NVARCHAR2(256)", maxLength: 256, nullable: true), + LastLockTime = table.Column(type: "TIMESTAMP", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_CAPLock", x => x.Key); + }); + + migrationBuilder.CreateTable( + name: "CAPPublishedMessage", + columns: table => new + { + Id = table.Column(type: "BIGINT", nullable: false), + Version = table.Column(type: "NVARCHAR2(20)", maxLength: 20, nullable: true), + Name = table.Column(type: "NVARCHAR2(200)", maxLength: 200, nullable: false), + Content = table.Column(type: "TEXT", nullable: true), + Retries = table.Column(type: "INT", nullable: true), + Added = table.Column(type: "TIMESTAMP", nullable: false), + ExpiresAt = table.Column(type: "TIMESTAMP", nullable: true), + StatusName = table.Column(type: "NVARCHAR2(40)", maxLength: 40, nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_CAPPublishedMessage", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "CAPReceivedMessage", + columns: table => new + { + Id = table.Column(type: "BIGINT", nullable: false), + Version = table.Column(type: "NVARCHAR2(20)", maxLength: 20, nullable: true), + Name = table.Column(type: "NVARCHAR2(400)", maxLength: 400, nullable: false), + Group = table.Column(type: "NVARCHAR2(200)", maxLength: 200, nullable: true), + Content = table.Column(type: "TEXT", nullable: true), + Retries = table.Column(type: "INT", nullable: true), + Added = table.Column(type: "TIMESTAMP", nullable: false), + ExpiresAt = table.Column(type: "TIMESTAMP", nullable: true), + StatusName = table.Column(type: "NVARCHAR2(50)", maxLength: 50, nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_CAPReceivedMessage", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "dept", + columns: table => new + { + Id = table.Column(type: "BIGINT", nullable: false), + Name = table.Column(type: "NVARCHAR2(100)", maxLength: 100, nullable: false), + Remark = table.Column(type: "NVARCHAR2(500)", maxLength: 500, nullable: false), + ParentId = table.Column(type: "BIGINT", nullable: false), + Status = table.Column(type: "INT", nullable: false), + CreatedAt = table.Column(type: "DATETIME WITH TIME ZONE", nullable: false), + IsDeleted = table.Column(type: "BIT", nullable: false), + DeletedAt = table.Column(type: "DATETIME WITH TIME ZONE", nullable: false), + UpdateTime = table.Column(type: "DATETIME WITH TIME ZONE", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_dept", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "role", + columns: table => new + { + Id = table.Column(type: "CHAR(36)", nullable: false), + Name = table.Column(type: "NVARCHAR2(50)", maxLength: 50, nullable: false), + Description = table.Column(type: "NVARCHAR2(200)", maxLength: 200, nullable: false), + CreatedAt = table.Column(type: "DATETIME WITH TIME ZONE", nullable: false), + IsActive = table.Column(type: "BIT", nullable: false), + IsDeleted = table.Column(type: "BIT", nullable: false), + DeletedAt = table.Column(type: "DATETIME WITH TIME ZONE", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_role", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "user", + columns: table => new + { + Id = table.Column(type: "BIGINT", nullable: false), + Name = table.Column(type: "NVARCHAR2(50)", maxLength: 50, nullable: false), + Email = table.Column(type: "NVARCHAR2(100)", maxLength: 100, nullable: false), + Phone = table.Column(type: "NVARCHAR2(20)", maxLength: 20, nullable: false), + RealName = table.Column(type: "NVARCHAR2(50)", maxLength: 50, nullable: false), + Status = table.Column(type: "INT", nullable: false), + PasswordHash = table.Column(type: "NVARCHAR2(255)", maxLength: 255, nullable: false), + IsActive = table.Column(type: "BIT", nullable: false), + CreatedAt = table.Column(type: "DATETIME WITH TIME ZONE", nullable: false), + LastLoginTime = table.Column(type: "DATETIME WITH TIME ZONE", nullable: true), + UpdateTime = table.Column(type: "DATETIME WITH TIME ZONE", nullable: false), + IsDeleted = table.Column(type: "BIT", nullable: false), + DeletedAt = table.Column(type: "DATETIME WITH TIME ZONE", nullable: false), + Gender = table.Column(type: "NVARCHAR2(10)", maxLength: 10, nullable: false), + Age = table.Column(type: "INT", nullable: false), + BirthDate = table.Column(type: "DATETIME WITH TIME ZONE", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_user", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "role_permission", + columns: table => new + { + RoleId = table.Column(type: "CHAR(36)", nullable: false), + PermissionCode = table.Column(type: "NVARCHAR2(100)", maxLength: 100, nullable: false), + PermissionName = table.Column(type: "NVARCHAR2(100)", maxLength: 100, nullable: false), + PermissionDescription = table.Column(type: "NVARCHAR2(200)", maxLength: 200, nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_role_permission", x => new { x.RoleId, x.PermissionCode }); + table.ForeignKey( + name: "FK_role_permission_role_RoleId", + column: x => x.RoleId, + principalTable: "role", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "user_dept", + columns: table => new + { + UserId = table.Column(type: "BIGINT", nullable: false), + DeptId = table.Column(type: "BIGINT", nullable: false), + DeptName = table.Column(type: "NVARCHAR2(100)", maxLength: 100, nullable: false), + AssignedAt = table.Column(type: "DATETIME WITH TIME ZONE", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_user_dept", x => x.UserId); + table.ForeignKey( + name: "FK_user_dept_user_UserId", + column: x => x.UserId, + principalTable: "user", + principalColumn: "Id"); + }); + + migrationBuilder.CreateTable( + name: "user_refresh_token", + columns: table => new + { + Id = table.Column(type: "BIGINT", nullable: false), + UserId = table.Column(type: "BIGINT", nullable: false), + Token = table.Column(type: "NVARCHAR2(500)", maxLength: 500, nullable: false), + CreatedTime = table.Column(type: "DATETIME WITH TIME ZONE", nullable: false), + ExpiresTime = table.Column(type: "DATETIME WITH TIME ZONE", nullable: false), + IsUsed = table.Column(type: "BIT", nullable: false), + IsRevoked = table.Column(type: "BIT", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_user_refresh_token", x => x.Id); + table.ForeignKey( + name: "FK_user_refresh_token_user_UserId", + column: x => x.UserId, + principalTable: "user", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "user_role", + columns: table => new + { + UserId = table.Column(type: "BIGINT", nullable: false), + RoleId = table.Column(type: "CHAR(36)", nullable: false), + RoleName = table.Column(type: "NVARCHAR2(50)", maxLength: 50, nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_user_role", x => new { x.UserId, x.RoleId }); + table.ForeignKey( + name: "FK_user_role_user_UserId", + column: x => x.UserId, + principalTable: "user", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_ExpiresAt_StatusName", + table: "CAPPublishedMessage", + columns: new[] { "ExpiresAt", "StatusName" }); + + migrationBuilder.CreateIndex( + name: "IX_Version_ExpiresAt_StatusName", + table: "CAPPublishedMessage", + columns: new[] { "Version", "ExpiresAt", "StatusName" }); + + migrationBuilder.CreateIndex( + name: "IX_ExpiresAt_StatusName1", + table: "CAPReceivedMessage", + columns: new[] { "ExpiresAt", "StatusName" }); + + migrationBuilder.CreateIndex( + name: "IX_Version_ExpiresAt_StatusName1", + table: "CAPReceivedMessage", + columns: new[] { "Version", "ExpiresAt", "StatusName" }); + + migrationBuilder.CreateIndex( + name: "IX_dept_IsDeleted", + table: "dept", + column: "IsDeleted"); + + migrationBuilder.CreateIndex( + name: "IX_dept_ParentId", + table: "dept", + column: "ParentId"); + + migrationBuilder.CreateIndex( + name: "IX_dept_Status", + table: "dept", + column: "Status"); + + migrationBuilder.CreateIndex( + name: "IX_role_Name", + table: "role", + column: "Name", + unique: true); + + migrationBuilder.CreateIndex( + name: "IX_user_Email", + table: "user", + column: "Email"); + + migrationBuilder.CreateIndex( + name: "IX_user_Name", + table: "user", + column: "Name"); + + migrationBuilder.CreateIndex( + name: "IX_user_dept_DeptId", + table: "user_dept", + column: "DeptId"); + + migrationBuilder.CreateIndex( + name: "IX_user_dept_UserId", + table: "user_dept", + column: "UserId"); + + migrationBuilder.CreateIndex( + name: "IX_user_refresh_token_UserId", + table: "user_refresh_token", + column: "UserId"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "CAPLock"); + + migrationBuilder.DropTable( + name: "CAPPublishedMessage"); + + migrationBuilder.DropTable( + name: "CAPReceivedMessage"); + + migrationBuilder.DropTable( + name: "dept"); + + migrationBuilder.DropTable( + name: "role_permission"); + + migrationBuilder.DropTable( + name: "user_dept"); + + migrationBuilder.DropTable( + name: "user_refresh_token"); + + migrationBuilder.DropTable( + name: "user_role"); + + migrationBuilder.DropTable( + name: "role"); + + migrationBuilder.DropTable( + name: "user"); + } + } +} diff --git a/template/src/ABC.Template.Infrastructure/MigrationsAll/DMDB-net9.0-admin/ApplicationDbContextModelSnapshot.cs b/template/src/ABC.Template.Infrastructure/MigrationsAll/DMDB-net9.0-admin/ApplicationDbContextModelSnapshot.cs new file mode 100644 index 00000000..b9696fbd --- /dev/null +++ b/template/src/ABC.Template.Infrastructure/MigrationsAll/DMDB-net9.0-admin/ApplicationDbContextModelSnapshot.cs @@ -0,0 +1,430 @@ +// +using System; +using ABC.Template.Infrastructure; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace ABC.Template.Infrastructure.Migrations +{ + [DbContext(typeof(ApplicationDbContext))] + partial class ApplicationDbContextModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("Dm:ValueGenerationStrategy", DmValueGenerationStrategy.IdentityColumn) + .HasAnnotation("ProductVersion", "9.0.1") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.DeptAggregate.Dept", b => + { + b.Property("Id") + .HasColumnType("BIGINT"); + + b.Property("CreatedAt") + .HasColumnType("DATETIME WITH TIME ZONE"); + + b.Property("DeletedAt") + .HasColumnType("DATETIME WITH TIME ZONE"); + + b.Property("IsDeleted") + .HasColumnType("BIT"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("NVARCHAR2(100)"); + + b.Property("ParentId") + .HasColumnType("BIGINT"); + + b.Property("Remark") + .IsRequired() + .HasMaxLength(500) + .HasColumnType("NVARCHAR2(500)"); + + b.Property("Status") + .HasColumnType("INT"); + + b.Property("UpdateTime") + .HasColumnType("DATETIME WITH TIME ZONE"); + + b.HasKey("Id"); + + b.HasIndex("IsDeleted"); + + b.HasIndex("ParentId"); + + b.HasIndex("Status"); + + b.ToTable("dept", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.Role", b => + { + b.Property("Id") + .HasColumnType("CHAR(36)"); + + b.Property("CreatedAt") + .HasColumnType("DATETIME WITH TIME ZONE"); + + b.Property("DeletedAt") + .HasColumnType("DATETIME WITH TIME ZONE"); + + b.Property("Description") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("NVARCHAR2(200)"); + + b.Property("IsActive") + .HasColumnType("BIT"); + + b.Property("IsDeleted") + .HasColumnType("BIT"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("NVARCHAR2(50)"); + + b.HasKey("Id"); + + b.HasIndex("Name") + .IsUnique(); + + b.ToTable("role", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.RolePermission", b => + { + b.Property("RoleId") + .HasColumnType("CHAR(36)"); + + b.Property("PermissionCode") + .HasMaxLength(100) + .HasColumnType("NVARCHAR2(100)"); + + b.Property("PermissionDescription") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("NVARCHAR2(200)"); + + b.Property("PermissionName") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("NVARCHAR2(100)"); + + b.HasKey("RoleId", "PermissionCode"); + + b.ToTable("role_permission", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.User", b => + { + b.Property("Id") + .HasColumnType("BIGINT"); + + b.Property("Age") + .HasColumnType("INT"); + + b.Property("BirthDate") + .HasColumnType("DATETIME WITH TIME ZONE"); + + b.Property("CreatedAt") + .HasColumnType("DATETIME WITH TIME ZONE"); + + b.Property("DeletedAt") + .HasColumnType("DATETIME WITH TIME ZONE"); + + b.Property("Email") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("NVARCHAR2(100)"); + + b.Property("Gender") + .IsRequired() + .HasMaxLength(10) + .HasColumnType("NVARCHAR2(10)"); + + b.Property("IsActive") + .HasColumnType("BIT"); + + b.Property("IsDeleted") + .HasColumnType("BIT"); + + b.Property("LastLoginTime") + .HasColumnType("DATETIME WITH TIME ZONE"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("NVARCHAR2(50)"); + + b.Property("PasswordHash") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("NVARCHAR2(255)"); + + b.Property("Phone") + .IsRequired() + .HasMaxLength(20) + .HasColumnType("NVARCHAR2(20)"); + + b.Property("RealName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("NVARCHAR2(50)"); + + b.Property("Status") + .HasColumnType("INT"); + + b.Property("UpdateTime") + .HasColumnType("DATETIME WITH TIME ZONE"); + + b.HasKey("Id"); + + b.HasIndex("Email"); + + b.HasIndex("Name"); + + b.ToTable("user", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserDept", b => + { + b.Property("UserId") + .HasColumnType("BIGINT"); + + b.Property("AssignedAt") + .HasColumnType("DATETIME WITH TIME ZONE"); + + b.Property("DeptId") + .HasColumnType("BIGINT"); + + b.Property("DeptName") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("NVARCHAR2(100)"); + + b.HasKey("UserId"); + + b.HasIndex("DeptId"); + + b.HasIndex("UserId"); + + b.ToTable("user_dept", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRefreshToken", b => + { + b.Property("Id") + .HasColumnType("BIGINT"); + + b.Property("CreatedTime") + .HasColumnType("DATETIME WITH TIME ZONE"); + + b.Property("ExpiresTime") + .HasColumnType("DATETIME WITH TIME ZONE"); + + b.Property("IsRevoked") + .HasColumnType("BIT"); + + b.Property("IsUsed") + .HasColumnType("BIT"); + + b.Property("Token") + .IsRequired() + .HasMaxLength(500) + .HasColumnType("NVARCHAR2(500)"); + + b.Property("UserId") + .HasColumnType("BIGINT"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("user_refresh_token", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRole", b => + { + b.Property("UserId") + .HasColumnType("BIGINT"); + + b.Property("RoleId") + .HasColumnType("CHAR(36)"); + + b.Property("RoleName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("NVARCHAR2(50)"); + + b.HasKey("UserId", "RoleId"); + + b.ToTable("user_role", (string)null); + }); + + modelBuilder.Entity("NetCorePal.Extensions.DistributedTransactions.CAP.Persistence.CapLock", b => + { + b.Property("Key") + .HasMaxLength(128) + .HasColumnType("NVARCHAR2(128)"); + + b.Property("Instance") + .HasMaxLength(256) + .HasColumnType("NVARCHAR2(256)"); + + b.Property("LastLockTime") + .HasColumnType("TIMESTAMP"); + + b.HasKey("Key"); + + b.ToTable("CAPLock", (string)null); + }); + + modelBuilder.Entity("NetCorePal.Extensions.DistributedTransactions.CAP.Persistence.PublishedMessage", b => + { + b.Property("Id") + .HasColumnType("BIGINT"); + + b.Property("Added") + .HasColumnType("TIMESTAMP"); + + b.Property("Content") + .HasColumnType("TEXT"); + + b.Property("ExpiresAt") + .HasColumnType("TIMESTAMP"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("NVARCHAR2(200)"); + + b.Property("Retries") + .HasColumnType("INT"); + + b.Property("StatusName") + .IsRequired() + .HasMaxLength(40) + .HasColumnType("NVARCHAR2(40)"); + + b.Property("Version") + .HasMaxLength(20) + .HasColumnType("NVARCHAR2(20)"); + + b.HasKey("Id"); + + b.HasIndex(new[] { "ExpiresAt", "StatusName" }, "IX_ExpiresAt_StatusName"); + + b.HasIndex(new[] { "Version", "ExpiresAt", "StatusName" }, "IX_Version_ExpiresAt_StatusName"); + + b.ToTable("CAPPublishedMessage", (string)null); + }); + + modelBuilder.Entity("NetCorePal.Extensions.DistributedTransactions.CAP.Persistence.ReceivedMessage", b => + { + b.Property("Id") + .HasColumnType("BIGINT"); + + b.Property("Added") + .HasColumnType("TIMESTAMP"); + + b.Property("Content") + .HasColumnType("TEXT"); + + b.Property("ExpiresAt") + .HasColumnType("TIMESTAMP"); + + b.Property("Group") + .HasMaxLength(200) + .HasColumnType("NVARCHAR2(200)"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(400) + .HasColumnType("NVARCHAR2(400)"); + + b.Property("Retries") + .HasColumnType("INT"); + + b.Property("StatusName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("NVARCHAR2(50)"); + + b.Property("Version") + .HasMaxLength(20) + .HasColumnType("NVARCHAR2(20)"); + + b.HasKey("Id"); + + b.HasIndex(new[] { "ExpiresAt", "StatusName" }, "IX_ExpiresAt_StatusName") + .HasDatabaseName("IX_ExpiresAt_StatusName1"); + + b.HasIndex(new[] { "Version", "ExpiresAt", "StatusName" }, "IX_Version_ExpiresAt_StatusName") + .HasDatabaseName("IX_Version_ExpiresAt_StatusName1"); + + b.ToTable("CAPReceivedMessage", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.RolePermission", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.RoleAggregate.Role", null) + .WithMany("Permissions") + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserDept", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.UserAggregate.User", null) + .WithOne("Dept") + .HasForeignKey("ABC.Template.Domain.AggregatesModel.UserAggregate.UserDept", "UserId") + .OnDelete(DeleteBehavior.ClientCascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRefreshToken", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.UserAggregate.User", null) + .WithMany("RefreshTokens") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRole", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.UserAggregate.User", null) + .WithMany("Roles") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.Role", b => + { + b.Navigation("Permissions"); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.User", b => + { + b.Navigation("Dept") + .IsRequired(); + + b.Navigation("RefreshTokens"); + + b.Navigation("Roles"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/template/src/ABC.Template.Infrastructure/MigrationsAll/DMDB-net9.0/20251225065224_Init.Designer.cs b/template/src/ABC.Template.Infrastructure/MigrationsAll/DMDB-net9.0/20260122055053_Init.Designer.cs similarity index 77% rename from template/src/ABC.Template.Infrastructure/MigrationsAll/DMDB-net9.0/20251225065224_Init.Designer.cs rename to template/src/ABC.Template.Infrastructure/MigrationsAll/DMDB-net9.0/20260122055053_Init.Designer.cs index dc95021d..0fabb3b2 100644 --- a/template/src/ABC.Template.Infrastructure/MigrationsAll/DMDB-net9.0/20251225065224_Init.Designer.cs +++ b/template/src/ABC.Template.Infrastructure/MigrationsAll/DMDB-net9.0/20260122055053_Init.Designer.cs @@ -1,18 +1,18 @@ // using System; +using ABC.Template.Infrastructure; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using ABC.Template.Infrastructure; #nullable disable namespace ABC.Template.Infrastructure.Migrations { [DbContext(typeof(ApplicationDbContext))] - [Migration("20251225065224_Init")] + [Migration("20260122055053_Init")] partial class Init { /// @@ -127,47 +127,6 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.ToTable("CAPReceivedMessage", (string)null); }); - - modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.DeliverAggregate.DeliverRecord", b => - { - b.Property("Id") - .HasColumnType("CHAR(36)"); - - b.Property("OrderId") - .HasColumnType("CHAR(36)"); - - b.HasKey("Id"); - - b.ToTable("deliverrecord", (string)null); - }); - - modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.OrderAggregate.Order", b => - { - b.Property("Id") - .HasColumnType("CHAR(36)"); - - b.Property("Count") - .HasColumnType("INT"); - - b.Property("Name") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("NVARCHAR2(100)"); - - b.Property("Paid") - .HasColumnType("BIT"); - - b.Property("RowVersion") - .IsConcurrencyToken() - .HasColumnType("INT"); - - b.Property("UpdateTime") - .HasColumnType("DATETIME WITH TIME ZONE"); - - b.HasKey("Id"); - - b.ToTable("order", (string)null); - }); #pragma warning restore 612, 618 } } diff --git a/template/src/ABC.Template.Infrastructure/MigrationsAll/DMDB-net8.0/20251225065214_Init.cs b/template/src/ABC.Template.Infrastructure/MigrationsAll/DMDB-net9.0/20260122055053_Init.cs similarity index 75% rename from template/src/ABC.Template.Infrastructure/MigrationsAll/DMDB-net8.0/20251225065214_Init.cs rename to template/src/ABC.Template.Infrastructure/MigrationsAll/DMDB-net9.0/20260122055053_Init.cs index bdee868c..a7e91c5a 100644 --- a/template/src/ABC.Template.Infrastructure/MigrationsAll/DMDB-net8.0/20251225065214_Init.cs +++ b/template/src/ABC.Template.Infrastructure/MigrationsAll/DMDB-net9.0/20260122055053_Init.cs @@ -61,34 +61,6 @@ protected override void Up(MigrationBuilder migrationBuilder) table.PrimaryKey("PK_CAPReceivedMessage", x => x.Id); }); - migrationBuilder.CreateTable( - name: "deliverrecord", - columns: table => new - { - Id = table.Column(type: "CHAR(36)", nullable: false), - OrderId = table.Column(type: "CHAR(36)", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_deliverrecord", x => x.Id); - }); - - migrationBuilder.CreateTable( - name: "order", - columns: table => new - { - Id = table.Column(type: "CHAR(36)", nullable: false), - Paid = table.Column(type: "BIT", nullable: false), - Name = table.Column(type: "NVARCHAR2(100)", maxLength: 100, nullable: false), - Count = table.Column(type: "INT", nullable: false), - RowVersion = table.Column(type: "INT", nullable: false), - UpdateTime = table.Column(type: "DATETIME WITH TIME ZONE", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_order", x => x.Id); - }); - migrationBuilder.CreateIndex( name: "IX_ExpiresAt_StatusName", table: "CAPPublishedMessage", @@ -121,12 +93,6 @@ protected override void Down(MigrationBuilder migrationBuilder) migrationBuilder.DropTable( name: "CAPReceivedMessage"); - - migrationBuilder.DropTable( - name: "deliverrecord"); - - migrationBuilder.DropTable( - name: "order"); } } } diff --git a/template/src/ABC.Template.Infrastructure/MigrationsAll/DMDB-net9.0/ApplicationDbContextModelSnapshot.cs b/template/src/ABC.Template.Infrastructure/MigrationsAll/DMDB-net9.0/ApplicationDbContextModelSnapshot.cs index 15a914ec..4c9ac7d8 100644 --- a/template/src/ABC.Template.Infrastructure/MigrationsAll/DMDB-net9.0/ApplicationDbContextModelSnapshot.cs +++ b/template/src/ABC.Template.Infrastructure/MigrationsAll/DMDB-net9.0/ApplicationDbContextModelSnapshot.cs @@ -1,10 +1,10 @@ // using System; +using ABC.Template.Infrastructure; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using ABC.Template.Infrastructure; #nullable disable @@ -124,47 +124,6 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.ToTable("CAPReceivedMessage", (string)null); }); - - modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.DeliverAggregate.DeliverRecord", b => - { - b.Property("Id") - .HasColumnType("CHAR(36)"); - - b.Property("OrderId") - .HasColumnType("CHAR(36)"); - - b.HasKey("Id"); - - b.ToTable("deliverrecord", (string)null); - }); - - modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.OrderAggregate.Order", b => - { - b.Property("Id") - .HasColumnType("CHAR(36)"); - - b.Property("Count") - .HasColumnType("INT"); - - b.Property("Name") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("NVARCHAR2(100)"); - - b.Property("Paid") - .HasColumnType("BIT"); - - b.Property("RowVersion") - .IsConcurrencyToken() - .HasColumnType("INT"); - - b.Property("UpdateTime") - .HasColumnType("DATETIME WITH TIME ZONE"); - - b.HasKey("Id"); - - b.ToTable("order", (string)null); - }); #pragma warning restore 612, 618 } } diff --git a/template/src/ABC.Template.Infrastructure/MigrationsAll/GaussDB-net10.0-admin/20260122055024_Init.Designer.cs b/template/src/ABC.Template.Infrastructure/MigrationsAll/GaussDB-net10.0-admin/20260122055024_Init.Designer.cs new file mode 100644 index 00000000..929a7d82 --- /dev/null +++ b/template/src/ABC.Template.Infrastructure/MigrationsAll/GaussDB-net10.0-admin/20260122055024_Init.Designer.cs @@ -0,0 +1,434 @@ +// +using System; +using ABC.Template.Infrastructure; +using GaussDB.EntityFrameworkCore.PostgreSQL.Metadata; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace ABC.Template.Infrastructure.Migrations +{ + [DbContext(typeof(ApplicationDbContext))] + [Migration("20260122055024_Init")] + partial class Init + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "9.0.0") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + GaussDBModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.DeptAggregate.Dept", b => + { + b.Property("Id") + .HasColumnType("bigint"); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("DeletedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("character varying(100)"); + + b.Property("ParentId") + .HasColumnType("bigint"); + + b.Property("Remark") + .IsRequired() + .HasMaxLength(500) + .HasColumnType("character varying(500)"); + + b.Property("Status") + .HasColumnType("integer"); + + b.Property("UpdateTime") + .HasColumnType("timestamp with time zone"); + + b.HasKey("Id"); + + b.HasIndex("IsDeleted"); + + b.HasIndex("ParentId"); + + b.HasIndex("Status"); + + b.ToTable("dept", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.Role", b => + { + b.Property("Id") + .HasColumnType("uuid"); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("DeletedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("Description") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("character varying(200)"); + + b.Property("IsActive") + .HasColumnType("boolean"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("character varying(50)"); + + b.HasKey("Id"); + + b.HasIndex("Name") + .IsUnique(); + + b.ToTable("role", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.RolePermission", b => + { + b.Property("RoleId") + .HasColumnType("uuid"); + + b.Property("PermissionCode") + .HasMaxLength(100) + .HasColumnType("character varying(100)"); + + b.Property("PermissionDescription") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("character varying(200)"); + + b.Property("PermissionName") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("character varying(100)"); + + b.HasKey("RoleId", "PermissionCode"); + + b.ToTable("role_permission", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.User", b => + { + b.Property("Id") + .HasColumnType("bigint"); + + b.Property("Age") + .HasColumnType("integer"); + + b.Property("BirthDate") + .HasColumnType("timestamp with time zone"); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("DeletedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("Email") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("character varying(100)"); + + b.Property("Gender") + .IsRequired() + .HasMaxLength(10) + .HasColumnType("character varying(10)"); + + b.Property("IsActive") + .HasColumnType("boolean"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("LastLoginTime") + .HasColumnType("timestamp with time zone"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("character varying(50)"); + + b.Property("PasswordHash") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("character varying(255)"); + + b.Property("Phone") + .IsRequired() + .HasMaxLength(20) + .HasColumnType("character varying(20)"); + + b.Property("RealName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("character varying(50)"); + + b.Property("Status") + .HasColumnType("integer"); + + b.Property("UpdateTime") + .HasColumnType("timestamp with time zone"); + + b.HasKey("Id"); + + b.HasIndex("Email"); + + b.HasIndex("Name"); + + b.ToTable("user", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserDept", b => + { + b.Property("UserId") + .HasColumnType("bigint"); + + b.Property("AssignedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("DeptId") + .HasColumnType("bigint"); + + b.Property("DeptName") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("character varying(100)"); + + b.HasKey("UserId"); + + b.HasIndex("DeptId"); + + b.HasIndex("UserId"); + + b.ToTable("user_dept", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRefreshToken", b => + { + b.Property("Id") + .HasColumnType("bigint"); + + b.Property("CreatedTime") + .HasColumnType("timestamp with time zone"); + + b.Property("ExpiresTime") + .HasColumnType("timestamp with time zone"); + + b.Property("IsRevoked") + .HasColumnType("boolean"); + + b.Property("IsUsed") + .HasColumnType("boolean"); + + b.Property("Token") + .IsRequired() + .HasMaxLength(500) + .HasColumnType("character varying(500)"); + + b.Property("UserId") + .HasColumnType("bigint"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("user_refresh_token", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRole", b => + { + b.Property("UserId") + .HasColumnType("bigint"); + + b.Property("RoleId") + .HasColumnType("uuid"); + + b.Property("RoleName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("character varying(50)"); + + b.HasKey("UserId", "RoleId"); + + b.ToTable("user_role", (string)null); + }); + + modelBuilder.Entity("NetCorePal.Extensions.DistributedTransactions.CAP.Persistence.CapLock", b => + { + b.Property("Key") + .HasMaxLength(128) + .HasColumnType("character varying(128)"); + + b.Property("Instance") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.Property("LastLockTime") + .HasColumnType("TIMESTAMP"); + + b.HasKey("Key"); + + b.ToTable("CAPLock", (string)null); + }); + + modelBuilder.Entity("NetCorePal.Extensions.DistributedTransactions.CAP.Persistence.PublishedMessage", b => + { + b.Property("Id") + .HasColumnType("bigint"); + + b.Property("Added") + .HasColumnType("TIMESTAMP"); + + b.Property("Content") + .HasColumnType("TEXT"); + + b.Property("ExpiresAt") + .HasColumnType("TIMESTAMP"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("character varying(200)"); + + b.Property("Retries") + .HasColumnType("integer"); + + b.Property("StatusName") + .IsRequired() + .HasMaxLength(40) + .HasColumnType("character varying(40)"); + + b.Property("Version") + .HasMaxLength(20) + .HasColumnType("character varying(20)"); + + b.HasKey("Id"); + + b.HasIndex(new[] { "ExpiresAt", "StatusName" }, "IX_ExpiresAt_StatusName"); + + b.HasIndex(new[] { "Version", "ExpiresAt", "StatusName" }, "IX_Version_ExpiresAt_StatusName"); + + b.ToTable("CAPPublishedMessage", (string)null); + }); + + modelBuilder.Entity("NetCorePal.Extensions.DistributedTransactions.CAP.Persistence.ReceivedMessage", b => + { + b.Property("Id") + .HasColumnType("bigint"); + + b.Property("Added") + .HasColumnType("TIMESTAMP"); + + b.Property("Content") + .HasColumnType("TEXT"); + + b.Property("ExpiresAt") + .HasColumnType("TIMESTAMP"); + + b.Property("Group") + .HasMaxLength(200) + .HasColumnType("character varying(200)"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(400) + .HasColumnType("character varying(400)"); + + b.Property("Retries") + .HasColumnType("integer"); + + b.Property("StatusName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("character varying(50)"); + + b.Property("Version") + .HasMaxLength(20) + .HasColumnType("character varying(20)"); + + b.HasKey("Id"); + + b.HasIndex(new[] { "ExpiresAt", "StatusName" }, "IX_ExpiresAt_StatusName") + .HasDatabaseName("IX_ExpiresAt_StatusName1"); + + b.HasIndex(new[] { "Version", "ExpiresAt", "StatusName" }, "IX_Version_ExpiresAt_StatusName") + .HasDatabaseName("IX_Version_ExpiresAt_StatusName1"); + + b.ToTable("CAPReceivedMessage", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.RolePermission", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.RoleAggregate.Role", null) + .WithMany("Permissions") + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserDept", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.UserAggregate.User", null) + .WithOne("Dept") + .HasForeignKey("ABC.Template.Domain.AggregatesModel.UserAggregate.UserDept", "UserId") + .OnDelete(DeleteBehavior.ClientCascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRefreshToken", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.UserAggregate.User", null) + .WithMany("RefreshTokens") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRole", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.UserAggregate.User", null) + .WithMany("Roles") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.Role", b => + { + b.Navigation("Permissions"); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.User", b => + { + b.Navigation("Dept") + .IsRequired(); + + b.Navigation("RefreshTokens"); + + b.Navigation("Roles"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/template/src/ABC.Template.Infrastructure/MigrationsAll/GaussDB-net10.0-admin/20260122055024_Init.cs b/template/src/ABC.Template.Infrastructure/MigrationsAll/GaussDB-net10.0-admin/20260122055024_Init.cs new file mode 100644 index 00000000..408f44cd --- /dev/null +++ b/template/src/ABC.Template.Infrastructure/MigrationsAll/GaussDB-net10.0-admin/20260122055024_Init.cs @@ -0,0 +1,308 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace ABC.Template.Infrastructure.Migrations +{ + /// + public partial class Init : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "CAPLock", + columns: table => new + { + Key = table.Column(type: "character varying(128)", maxLength: 128, nullable: false), + Instance = table.Column(type: "character varying(256)", maxLength: 256, nullable: true), + LastLockTime = table.Column(type: "TIMESTAMP", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_CAPLock", x => x.Key); + }); + + migrationBuilder.CreateTable( + name: "CAPPublishedMessage", + columns: table => new + { + Id = table.Column(type: "bigint", nullable: false), + Version = table.Column(type: "character varying(20)", maxLength: 20, nullable: true), + Name = table.Column(type: "character varying(200)", maxLength: 200, nullable: false), + Content = table.Column(type: "TEXT", nullable: true), + Retries = table.Column(type: "integer", nullable: true), + Added = table.Column(type: "TIMESTAMP", nullable: false), + ExpiresAt = table.Column(type: "TIMESTAMP", nullable: true), + StatusName = table.Column(type: "character varying(40)", maxLength: 40, nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_CAPPublishedMessage", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "CAPReceivedMessage", + columns: table => new + { + Id = table.Column(type: "bigint", nullable: false), + Version = table.Column(type: "character varying(20)", maxLength: 20, nullable: true), + Name = table.Column(type: "character varying(400)", maxLength: 400, nullable: false), + Group = table.Column(type: "character varying(200)", maxLength: 200, nullable: true), + Content = table.Column(type: "TEXT", nullable: true), + Retries = table.Column(type: "integer", nullable: true), + Added = table.Column(type: "TIMESTAMP", nullable: false), + ExpiresAt = table.Column(type: "TIMESTAMP", nullable: true), + StatusName = table.Column(type: "character varying(50)", maxLength: 50, nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_CAPReceivedMessage", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "dept", + columns: table => new + { + Id = table.Column(type: "bigint", nullable: false), + Name = table.Column(type: "character varying(100)", maxLength: 100, nullable: false), + Remark = table.Column(type: "character varying(500)", maxLength: 500, nullable: false), + ParentId = table.Column(type: "bigint", nullable: false), + Status = table.Column(type: "integer", nullable: false), + CreatedAt = table.Column(type: "timestamp with time zone", nullable: false), + IsDeleted = table.Column(type: "boolean", nullable: false), + DeletedAt = table.Column(type: "timestamp with time zone", nullable: false), + UpdateTime = table.Column(type: "timestamp with time zone", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_dept", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "role", + columns: table => new + { + Id = table.Column(type: "uuid", nullable: false), + Name = table.Column(type: "character varying(50)", maxLength: 50, nullable: false), + Description = table.Column(type: "character varying(200)", maxLength: 200, nullable: false), + CreatedAt = table.Column(type: "timestamp with time zone", nullable: false), + IsActive = table.Column(type: "boolean", nullable: false), + IsDeleted = table.Column(type: "boolean", nullable: false), + DeletedAt = table.Column(type: "timestamp with time zone", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_role", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "user", + columns: table => new + { + Id = table.Column(type: "bigint", nullable: false), + Name = table.Column(type: "character varying(50)", maxLength: 50, nullable: false), + Email = table.Column(type: "character varying(100)", maxLength: 100, nullable: false), + Phone = table.Column(type: "character varying(20)", maxLength: 20, nullable: false), + RealName = table.Column(type: "character varying(50)", maxLength: 50, nullable: false), + Status = table.Column(type: "integer", nullable: false), + PasswordHash = table.Column(type: "character varying(255)", maxLength: 255, nullable: false), + IsActive = table.Column(type: "boolean", nullable: false), + CreatedAt = table.Column(type: "timestamp with time zone", nullable: false), + LastLoginTime = table.Column(type: "timestamp with time zone", nullable: true), + UpdateTime = table.Column(type: "timestamp with time zone", nullable: false), + IsDeleted = table.Column(type: "boolean", nullable: false), + DeletedAt = table.Column(type: "timestamp with time zone", nullable: false), + Gender = table.Column(type: "character varying(10)", maxLength: 10, nullable: false), + Age = table.Column(type: "integer", nullable: false), + BirthDate = table.Column(type: "timestamp with time zone", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_user", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "role_permission", + columns: table => new + { + RoleId = table.Column(type: "uuid", nullable: false), + PermissionCode = table.Column(type: "character varying(100)", maxLength: 100, nullable: false), + PermissionName = table.Column(type: "character varying(100)", maxLength: 100, nullable: false), + PermissionDescription = table.Column(type: "character varying(200)", maxLength: 200, nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_role_permission", x => new { x.RoleId, x.PermissionCode }); + table.ForeignKey( + name: "FK_role_permission_role_RoleId", + column: x => x.RoleId, + principalTable: "role", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "user_dept", + columns: table => new + { + UserId = table.Column(type: "bigint", nullable: false), + DeptId = table.Column(type: "bigint", nullable: false), + DeptName = table.Column(type: "character varying(100)", maxLength: 100, nullable: false), + AssignedAt = table.Column(type: "timestamp with time zone", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_user_dept", x => x.UserId); + table.ForeignKey( + name: "FK_user_dept_user_UserId", + column: x => x.UserId, + principalTable: "user", + principalColumn: "Id"); + }); + + migrationBuilder.CreateTable( + name: "user_refresh_token", + columns: table => new + { + Id = table.Column(type: "bigint", nullable: false), + UserId = table.Column(type: "bigint", nullable: false), + Token = table.Column(type: "character varying(500)", maxLength: 500, nullable: false), + CreatedTime = table.Column(type: "timestamp with time zone", nullable: false), + ExpiresTime = table.Column(type: "timestamp with time zone", nullable: false), + IsUsed = table.Column(type: "boolean", nullable: false), + IsRevoked = table.Column(type: "boolean", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_user_refresh_token", x => x.Id); + table.ForeignKey( + name: "FK_user_refresh_token_user_UserId", + column: x => x.UserId, + principalTable: "user", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "user_role", + columns: table => new + { + UserId = table.Column(type: "bigint", nullable: false), + RoleId = table.Column(type: "uuid", nullable: false), + RoleName = table.Column(type: "character varying(50)", maxLength: 50, nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_user_role", x => new { x.UserId, x.RoleId }); + table.ForeignKey( + name: "FK_user_role_user_UserId", + column: x => x.UserId, + principalTable: "user", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_ExpiresAt_StatusName", + table: "CAPPublishedMessage", + columns: new[] { "ExpiresAt", "StatusName" }); + + migrationBuilder.CreateIndex( + name: "IX_Version_ExpiresAt_StatusName", + table: "CAPPublishedMessage", + columns: new[] { "Version", "ExpiresAt", "StatusName" }); + + migrationBuilder.CreateIndex( + name: "IX_ExpiresAt_StatusName1", + table: "CAPReceivedMessage", + columns: new[] { "ExpiresAt", "StatusName" }); + + migrationBuilder.CreateIndex( + name: "IX_Version_ExpiresAt_StatusName1", + table: "CAPReceivedMessage", + columns: new[] { "Version", "ExpiresAt", "StatusName" }); + + migrationBuilder.CreateIndex( + name: "IX_dept_IsDeleted", + table: "dept", + column: "IsDeleted"); + + migrationBuilder.CreateIndex( + name: "IX_dept_ParentId", + table: "dept", + column: "ParentId"); + + migrationBuilder.CreateIndex( + name: "IX_dept_Status", + table: "dept", + column: "Status"); + + migrationBuilder.CreateIndex( + name: "IX_role_Name", + table: "role", + column: "Name", + unique: true); + + migrationBuilder.CreateIndex( + name: "IX_user_Email", + table: "user", + column: "Email"); + + migrationBuilder.CreateIndex( + name: "IX_user_Name", + table: "user", + column: "Name"); + + migrationBuilder.CreateIndex( + name: "IX_user_dept_DeptId", + table: "user_dept", + column: "DeptId"); + + migrationBuilder.CreateIndex( + name: "IX_user_dept_UserId", + table: "user_dept", + column: "UserId"); + + migrationBuilder.CreateIndex( + name: "IX_user_refresh_token_UserId", + table: "user_refresh_token", + column: "UserId"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "CAPLock"); + + migrationBuilder.DropTable( + name: "CAPPublishedMessage"); + + migrationBuilder.DropTable( + name: "CAPReceivedMessage"); + + migrationBuilder.DropTable( + name: "dept"); + + migrationBuilder.DropTable( + name: "role_permission"); + + migrationBuilder.DropTable( + name: "user_dept"); + + migrationBuilder.DropTable( + name: "user_refresh_token"); + + migrationBuilder.DropTable( + name: "user_role"); + + migrationBuilder.DropTable( + name: "role"); + + migrationBuilder.DropTable( + name: "user"); + } + } +} diff --git a/template/src/ABC.Template.Infrastructure/MigrationsAll/GaussDB-net10.0-admin/ApplicationDbContextModelSnapshot.cs b/template/src/ABC.Template.Infrastructure/MigrationsAll/GaussDB-net10.0-admin/ApplicationDbContextModelSnapshot.cs new file mode 100644 index 00000000..64dd485a --- /dev/null +++ b/template/src/ABC.Template.Infrastructure/MigrationsAll/GaussDB-net10.0-admin/ApplicationDbContextModelSnapshot.cs @@ -0,0 +1,431 @@ +// +using System; +using ABC.Template.Infrastructure; +using GaussDB.EntityFrameworkCore.PostgreSQL.Metadata; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace ABC.Template.Infrastructure.Migrations +{ + [DbContext(typeof(ApplicationDbContext))] + partial class ApplicationDbContextModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "9.0.0") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + GaussDBModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.DeptAggregate.Dept", b => + { + b.Property("Id") + .HasColumnType("bigint"); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("DeletedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("character varying(100)"); + + b.Property("ParentId") + .HasColumnType("bigint"); + + b.Property("Remark") + .IsRequired() + .HasMaxLength(500) + .HasColumnType("character varying(500)"); + + b.Property("Status") + .HasColumnType("integer"); + + b.Property("UpdateTime") + .HasColumnType("timestamp with time zone"); + + b.HasKey("Id"); + + b.HasIndex("IsDeleted"); + + b.HasIndex("ParentId"); + + b.HasIndex("Status"); + + b.ToTable("dept", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.Role", b => + { + b.Property("Id") + .HasColumnType("uuid"); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("DeletedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("Description") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("character varying(200)"); + + b.Property("IsActive") + .HasColumnType("boolean"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("character varying(50)"); + + b.HasKey("Id"); + + b.HasIndex("Name") + .IsUnique(); + + b.ToTable("role", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.RolePermission", b => + { + b.Property("RoleId") + .HasColumnType("uuid"); + + b.Property("PermissionCode") + .HasMaxLength(100) + .HasColumnType("character varying(100)"); + + b.Property("PermissionDescription") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("character varying(200)"); + + b.Property("PermissionName") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("character varying(100)"); + + b.HasKey("RoleId", "PermissionCode"); + + b.ToTable("role_permission", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.User", b => + { + b.Property("Id") + .HasColumnType("bigint"); + + b.Property("Age") + .HasColumnType("integer"); + + b.Property("BirthDate") + .HasColumnType("timestamp with time zone"); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("DeletedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("Email") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("character varying(100)"); + + b.Property("Gender") + .IsRequired() + .HasMaxLength(10) + .HasColumnType("character varying(10)"); + + b.Property("IsActive") + .HasColumnType("boolean"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("LastLoginTime") + .HasColumnType("timestamp with time zone"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("character varying(50)"); + + b.Property("PasswordHash") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("character varying(255)"); + + b.Property("Phone") + .IsRequired() + .HasMaxLength(20) + .HasColumnType("character varying(20)"); + + b.Property("RealName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("character varying(50)"); + + b.Property("Status") + .HasColumnType("integer"); + + b.Property("UpdateTime") + .HasColumnType("timestamp with time zone"); + + b.HasKey("Id"); + + b.HasIndex("Email"); + + b.HasIndex("Name"); + + b.ToTable("user", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserDept", b => + { + b.Property("UserId") + .HasColumnType("bigint"); + + b.Property("AssignedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("DeptId") + .HasColumnType("bigint"); + + b.Property("DeptName") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("character varying(100)"); + + b.HasKey("UserId"); + + b.HasIndex("DeptId"); + + b.HasIndex("UserId"); + + b.ToTable("user_dept", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRefreshToken", b => + { + b.Property("Id") + .HasColumnType("bigint"); + + b.Property("CreatedTime") + .HasColumnType("timestamp with time zone"); + + b.Property("ExpiresTime") + .HasColumnType("timestamp with time zone"); + + b.Property("IsRevoked") + .HasColumnType("boolean"); + + b.Property("IsUsed") + .HasColumnType("boolean"); + + b.Property("Token") + .IsRequired() + .HasMaxLength(500) + .HasColumnType("character varying(500)"); + + b.Property("UserId") + .HasColumnType("bigint"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("user_refresh_token", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRole", b => + { + b.Property("UserId") + .HasColumnType("bigint"); + + b.Property("RoleId") + .HasColumnType("uuid"); + + b.Property("RoleName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("character varying(50)"); + + b.HasKey("UserId", "RoleId"); + + b.ToTable("user_role", (string)null); + }); + + modelBuilder.Entity("NetCorePal.Extensions.DistributedTransactions.CAP.Persistence.CapLock", b => + { + b.Property("Key") + .HasMaxLength(128) + .HasColumnType("character varying(128)"); + + b.Property("Instance") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.Property("LastLockTime") + .HasColumnType("TIMESTAMP"); + + b.HasKey("Key"); + + b.ToTable("CAPLock", (string)null); + }); + + modelBuilder.Entity("NetCorePal.Extensions.DistributedTransactions.CAP.Persistence.PublishedMessage", b => + { + b.Property("Id") + .HasColumnType("bigint"); + + b.Property("Added") + .HasColumnType("TIMESTAMP"); + + b.Property("Content") + .HasColumnType("TEXT"); + + b.Property("ExpiresAt") + .HasColumnType("TIMESTAMP"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("character varying(200)"); + + b.Property("Retries") + .HasColumnType("integer"); + + b.Property("StatusName") + .IsRequired() + .HasMaxLength(40) + .HasColumnType("character varying(40)"); + + b.Property("Version") + .HasMaxLength(20) + .HasColumnType("character varying(20)"); + + b.HasKey("Id"); + + b.HasIndex(new[] { "ExpiresAt", "StatusName" }, "IX_ExpiresAt_StatusName"); + + b.HasIndex(new[] { "Version", "ExpiresAt", "StatusName" }, "IX_Version_ExpiresAt_StatusName"); + + b.ToTable("CAPPublishedMessage", (string)null); + }); + + modelBuilder.Entity("NetCorePal.Extensions.DistributedTransactions.CAP.Persistence.ReceivedMessage", b => + { + b.Property("Id") + .HasColumnType("bigint"); + + b.Property("Added") + .HasColumnType("TIMESTAMP"); + + b.Property("Content") + .HasColumnType("TEXT"); + + b.Property("ExpiresAt") + .HasColumnType("TIMESTAMP"); + + b.Property("Group") + .HasMaxLength(200) + .HasColumnType("character varying(200)"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(400) + .HasColumnType("character varying(400)"); + + b.Property("Retries") + .HasColumnType("integer"); + + b.Property("StatusName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("character varying(50)"); + + b.Property("Version") + .HasMaxLength(20) + .HasColumnType("character varying(20)"); + + b.HasKey("Id"); + + b.HasIndex(new[] { "ExpiresAt", "StatusName" }, "IX_ExpiresAt_StatusName") + .HasDatabaseName("IX_ExpiresAt_StatusName1"); + + b.HasIndex(new[] { "Version", "ExpiresAt", "StatusName" }, "IX_Version_ExpiresAt_StatusName") + .HasDatabaseName("IX_Version_ExpiresAt_StatusName1"); + + b.ToTable("CAPReceivedMessage", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.RolePermission", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.RoleAggregate.Role", null) + .WithMany("Permissions") + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserDept", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.UserAggregate.User", null) + .WithOne("Dept") + .HasForeignKey("ABC.Template.Domain.AggregatesModel.UserAggregate.UserDept", "UserId") + .OnDelete(DeleteBehavior.ClientCascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRefreshToken", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.UserAggregate.User", null) + .WithMany("RefreshTokens") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRole", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.UserAggregate.User", null) + .WithMany("Roles") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.Role", b => + { + b.Navigation("Permissions"); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.User", b => + { + b.Navigation("Dept") + .IsRequired(); + + b.Navigation("RefreshTokens"); + + b.Navigation("Roles"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/template/src/ABC.Template.Infrastructure/MigrationsAll/GaussDB-net9.0/20251225065156_Init.Designer.cs b/template/src/ABC.Template.Infrastructure/MigrationsAll/GaussDB-net10.0/20260122055012_Init.Designer.cs similarity index 77% rename from template/src/ABC.Template.Infrastructure/MigrationsAll/GaussDB-net9.0/20251225065156_Init.Designer.cs rename to template/src/ABC.Template.Infrastructure/MigrationsAll/GaussDB-net10.0/20260122055012_Init.Designer.cs index 0d7a87e8..66ee51e2 100644 --- a/template/src/ABC.Template.Infrastructure/MigrationsAll/GaussDB-net9.0/20251225065156_Init.Designer.cs +++ b/template/src/ABC.Template.Infrastructure/MigrationsAll/GaussDB-net10.0/20260122055012_Init.Designer.cs @@ -1,18 +1,18 @@ // using System; +using ABC.Template.Infrastructure; using GaussDB.EntityFrameworkCore.PostgreSQL.Metadata; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using ABC.Template.Infrastructure; #nullable disable namespace ABC.Template.Infrastructure.Migrations { [DbContext(typeof(ApplicationDbContext))] - [Migration("20251225065156_Init")] + [Migration("20260122055012_Init")] partial class Init { /// @@ -128,47 +128,6 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.ToTable("CAPReceivedMessage", (string)null); }); - - modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.DeliverAggregate.DeliverRecord", b => - { - b.Property("Id") - .HasColumnType("uuid"); - - b.Property("OrderId") - .HasColumnType("uuid"); - - b.HasKey("Id"); - - b.ToTable("deliverrecord", (string)null); - }); - - modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.OrderAggregate.Order", b => - { - b.Property("Id") - .HasColumnType("uuid"); - - b.Property("Count") - .HasColumnType("integer"); - - b.Property("Name") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("character varying(100)"); - - b.Property("Paid") - .HasColumnType("boolean"); - - b.Property("RowVersion") - .IsConcurrencyToken() - .HasColumnType("integer"); - - b.Property("UpdateTime") - .HasColumnType("timestamp with time zone"); - - b.HasKey("Id"); - - b.ToTable("order", (string)null); - }); #pragma warning restore 612, 618 } } diff --git a/template/src/ABC.Template.Infrastructure/MigrationsAll/GaussDB-net8.0/20251225065148_Init.cs b/template/src/ABC.Template.Infrastructure/MigrationsAll/GaussDB-net10.0/20260122055012_Init.cs similarity index 75% rename from template/src/ABC.Template.Infrastructure/MigrationsAll/GaussDB-net8.0/20251225065148_Init.cs rename to template/src/ABC.Template.Infrastructure/MigrationsAll/GaussDB-net10.0/20260122055012_Init.cs index 145ea585..53c8065f 100644 --- a/template/src/ABC.Template.Infrastructure/MigrationsAll/GaussDB-net8.0/20251225065148_Init.cs +++ b/template/src/ABC.Template.Infrastructure/MigrationsAll/GaussDB-net10.0/20260122055012_Init.cs @@ -61,34 +61,6 @@ protected override void Up(MigrationBuilder migrationBuilder) table.PrimaryKey("PK_CAPReceivedMessage", x => x.Id); }); - migrationBuilder.CreateTable( - name: "deliverrecord", - columns: table => new - { - Id = table.Column(type: "uuid", nullable: false), - OrderId = table.Column(type: "uuid", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_deliverrecord", x => x.Id); - }); - - migrationBuilder.CreateTable( - name: "order", - columns: table => new - { - Id = table.Column(type: "uuid", nullable: false), - Paid = table.Column(type: "boolean", nullable: false), - Name = table.Column(type: "character varying(100)", maxLength: 100, nullable: false), - Count = table.Column(type: "integer", nullable: false), - RowVersion = table.Column(type: "integer", nullable: false), - UpdateTime = table.Column(type: "timestamp with time zone", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_order", x => x.Id); - }); - migrationBuilder.CreateIndex( name: "IX_ExpiresAt_StatusName", table: "CAPPublishedMessage", @@ -121,12 +93,6 @@ protected override void Down(MigrationBuilder migrationBuilder) migrationBuilder.DropTable( name: "CAPReceivedMessage"); - - migrationBuilder.DropTable( - name: "deliverrecord"); - - migrationBuilder.DropTable( - name: "order"); } } } diff --git a/template/src/ABC.Template.Infrastructure/MigrationsAll/GaussDB-net10.0/ApplicationDbContextModelSnapshot.cs b/template/src/ABC.Template.Infrastructure/MigrationsAll/GaussDB-net10.0/ApplicationDbContextModelSnapshot.cs index caf3d84b..c02070c2 100644 --- a/template/src/ABC.Template.Infrastructure/MigrationsAll/GaussDB-net10.0/ApplicationDbContextModelSnapshot.cs +++ b/template/src/ABC.Template.Infrastructure/MigrationsAll/GaussDB-net10.0/ApplicationDbContextModelSnapshot.cs @@ -1,10 +1,10 @@ // using System; +using ABC.Template.Infrastructure; using GaussDB.EntityFrameworkCore.PostgreSQL.Metadata; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using ABC.Template.Infrastructure; #nullable disable @@ -125,47 +125,6 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.ToTable("CAPReceivedMessage", (string)null); }); - - modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.DeliverAggregate.DeliverRecord", b => - { - b.Property("Id") - .HasColumnType("uuid"); - - b.Property("OrderId") - .HasColumnType("uuid"); - - b.HasKey("Id"); - - b.ToTable("deliverrecord", (string)null); - }); - - modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.OrderAggregate.Order", b => - { - b.Property("Id") - .HasColumnType("uuid"); - - b.Property("Count") - .HasColumnType("integer"); - - b.Property("Name") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("character varying(100)"); - - b.Property("Paid") - .HasColumnType("boolean"); - - b.Property("RowVersion") - .IsConcurrencyToken() - .HasColumnType("integer"); - - b.Property("UpdateTime") - .HasColumnType("timestamp with time zone"); - - b.HasKey("Id"); - - b.ToTable("order", (string)null); - }); #pragma warning restore 612, 618 } } diff --git a/template/src/ABC.Template.Infrastructure/MigrationsAll/GaussDB-net8.0-admin/20260122054941_Init.Designer.cs b/template/src/ABC.Template.Infrastructure/MigrationsAll/GaussDB-net8.0-admin/20260122054941_Init.Designer.cs new file mode 100644 index 00000000..9fc55e94 --- /dev/null +++ b/template/src/ABC.Template.Infrastructure/MigrationsAll/GaussDB-net8.0-admin/20260122054941_Init.Designer.cs @@ -0,0 +1,434 @@ +// +using System; +using ABC.Template.Infrastructure; +using GaussDB.EntityFrameworkCore.PostgreSQL.Metadata; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace ABC.Template.Infrastructure.Migrations +{ + [DbContext(typeof(ApplicationDbContext))] + [Migration("20260122054941_Init")] + partial class Init + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "8.0.10") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + GaussDBModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.DeptAggregate.Dept", b => + { + b.Property("Id") + .HasColumnType("bigint"); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("DeletedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("character varying(100)"); + + b.Property("ParentId") + .HasColumnType("bigint"); + + b.Property("Remark") + .IsRequired() + .HasMaxLength(500) + .HasColumnType("character varying(500)"); + + b.Property("Status") + .HasColumnType("integer"); + + b.Property("UpdateTime") + .HasColumnType("timestamp with time zone"); + + b.HasKey("Id"); + + b.HasIndex("IsDeleted"); + + b.HasIndex("ParentId"); + + b.HasIndex("Status"); + + b.ToTable("dept", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.Role", b => + { + b.Property("Id") + .HasColumnType("uuid"); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("DeletedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("Description") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("character varying(200)"); + + b.Property("IsActive") + .HasColumnType("boolean"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("character varying(50)"); + + b.HasKey("Id"); + + b.HasIndex("Name") + .IsUnique(); + + b.ToTable("role", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.RolePermission", b => + { + b.Property("RoleId") + .HasColumnType("uuid"); + + b.Property("PermissionCode") + .HasMaxLength(100) + .HasColumnType("character varying(100)"); + + b.Property("PermissionDescription") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("character varying(200)"); + + b.Property("PermissionName") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("character varying(100)"); + + b.HasKey("RoleId", "PermissionCode"); + + b.ToTable("role_permission", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.User", b => + { + b.Property("Id") + .HasColumnType("bigint"); + + b.Property("Age") + .HasColumnType("integer"); + + b.Property("BirthDate") + .HasColumnType("timestamp with time zone"); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("DeletedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("Email") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("character varying(100)"); + + b.Property("Gender") + .IsRequired() + .HasMaxLength(10) + .HasColumnType("character varying(10)"); + + b.Property("IsActive") + .HasColumnType("boolean"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("LastLoginTime") + .HasColumnType("timestamp with time zone"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("character varying(50)"); + + b.Property("PasswordHash") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("character varying(255)"); + + b.Property("Phone") + .IsRequired() + .HasMaxLength(20) + .HasColumnType("character varying(20)"); + + b.Property("RealName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("character varying(50)"); + + b.Property("Status") + .HasColumnType("integer"); + + b.Property("UpdateTime") + .HasColumnType("timestamp with time zone"); + + b.HasKey("Id"); + + b.HasIndex("Email"); + + b.HasIndex("Name"); + + b.ToTable("user", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserDept", b => + { + b.Property("UserId") + .HasColumnType("bigint"); + + b.Property("AssignedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("DeptId") + .HasColumnType("bigint"); + + b.Property("DeptName") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("character varying(100)"); + + b.HasKey("UserId"); + + b.HasIndex("DeptId"); + + b.HasIndex("UserId"); + + b.ToTable("user_dept", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRefreshToken", b => + { + b.Property("Id") + .HasColumnType("bigint"); + + b.Property("CreatedTime") + .HasColumnType("timestamp with time zone"); + + b.Property("ExpiresTime") + .HasColumnType("timestamp with time zone"); + + b.Property("IsRevoked") + .HasColumnType("boolean"); + + b.Property("IsUsed") + .HasColumnType("boolean"); + + b.Property("Token") + .IsRequired() + .HasMaxLength(500) + .HasColumnType("character varying(500)"); + + b.Property("UserId") + .HasColumnType("bigint"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("user_refresh_token", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRole", b => + { + b.Property("UserId") + .HasColumnType("bigint"); + + b.Property("RoleId") + .HasColumnType("uuid"); + + b.Property("RoleName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("character varying(50)"); + + b.HasKey("UserId", "RoleId"); + + b.ToTable("user_role", (string)null); + }); + + modelBuilder.Entity("NetCorePal.Extensions.DistributedTransactions.CAP.Persistence.CapLock", b => + { + b.Property("Key") + .HasMaxLength(128) + .HasColumnType("character varying(128)"); + + b.Property("Instance") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.Property("LastLockTime") + .HasColumnType("TIMESTAMP"); + + b.HasKey("Key"); + + b.ToTable("CAPLock", (string)null); + }); + + modelBuilder.Entity("NetCorePal.Extensions.DistributedTransactions.CAP.Persistence.PublishedMessage", b => + { + b.Property("Id") + .HasColumnType("bigint"); + + b.Property("Added") + .HasColumnType("TIMESTAMP"); + + b.Property("Content") + .HasColumnType("TEXT"); + + b.Property("ExpiresAt") + .HasColumnType("TIMESTAMP"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("character varying(200)"); + + b.Property("Retries") + .HasColumnType("integer"); + + b.Property("StatusName") + .IsRequired() + .HasMaxLength(40) + .HasColumnType("character varying(40)"); + + b.Property("Version") + .HasMaxLength(20) + .HasColumnType("character varying(20)"); + + b.HasKey("Id"); + + b.HasIndex(new[] { "ExpiresAt", "StatusName" }, "IX_ExpiresAt_StatusName"); + + b.HasIndex(new[] { "Version", "ExpiresAt", "StatusName" }, "IX_Version_ExpiresAt_StatusName"); + + b.ToTable("CAPPublishedMessage", (string)null); + }); + + modelBuilder.Entity("NetCorePal.Extensions.DistributedTransactions.CAP.Persistence.ReceivedMessage", b => + { + b.Property("Id") + .HasColumnType("bigint"); + + b.Property("Added") + .HasColumnType("TIMESTAMP"); + + b.Property("Content") + .HasColumnType("TEXT"); + + b.Property("ExpiresAt") + .HasColumnType("TIMESTAMP"); + + b.Property("Group") + .HasMaxLength(200) + .HasColumnType("character varying(200)"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(400) + .HasColumnType("character varying(400)"); + + b.Property("Retries") + .HasColumnType("integer"); + + b.Property("StatusName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("character varying(50)"); + + b.Property("Version") + .HasMaxLength(20) + .HasColumnType("character varying(20)"); + + b.HasKey("Id"); + + b.HasIndex(new[] { "ExpiresAt", "StatusName" }, "IX_ExpiresAt_StatusName") + .HasDatabaseName("IX_ExpiresAt_StatusName1"); + + b.HasIndex(new[] { "Version", "ExpiresAt", "StatusName" }, "IX_Version_ExpiresAt_StatusName") + .HasDatabaseName("IX_Version_ExpiresAt_StatusName1"); + + b.ToTable("CAPReceivedMessage", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.RolePermission", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.RoleAggregate.Role", null) + .WithMany("Permissions") + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserDept", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.UserAggregate.User", null) + .WithOne("Dept") + .HasForeignKey("ABC.Template.Domain.AggregatesModel.UserAggregate.UserDept", "UserId") + .OnDelete(DeleteBehavior.ClientCascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRefreshToken", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.UserAggregate.User", null) + .WithMany("RefreshTokens") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRole", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.UserAggregate.User", null) + .WithMany("Roles") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.Role", b => + { + b.Navigation("Permissions"); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.User", b => + { + b.Navigation("Dept") + .IsRequired(); + + b.Navigation("RefreshTokens"); + + b.Navigation("Roles"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/template/src/ABC.Template.Infrastructure/MigrationsAll/GaussDB-net8.0-admin/20260122054941_Init.cs b/template/src/ABC.Template.Infrastructure/MigrationsAll/GaussDB-net8.0-admin/20260122054941_Init.cs new file mode 100644 index 00000000..408f44cd --- /dev/null +++ b/template/src/ABC.Template.Infrastructure/MigrationsAll/GaussDB-net8.0-admin/20260122054941_Init.cs @@ -0,0 +1,308 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace ABC.Template.Infrastructure.Migrations +{ + /// + public partial class Init : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "CAPLock", + columns: table => new + { + Key = table.Column(type: "character varying(128)", maxLength: 128, nullable: false), + Instance = table.Column(type: "character varying(256)", maxLength: 256, nullable: true), + LastLockTime = table.Column(type: "TIMESTAMP", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_CAPLock", x => x.Key); + }); + + migrationBuilder.CreateTable( + name: "CAPPublishedMessage", + columns: table => new + { + Id = table.Column(type: "bigint", nullable: false), + Version = table.Column(type: "character varying(20)", maxLength: 20, nullable: true), + Name = table.Column(type: "character varying(200)", maxLength: 200, nullable: false), + Content = table.Column(type: "TEXT", nullable: true), + Retries = table.Column(type: "integer", nullable: true), + Added = table.Column(type: "TIMESTAMP", nullable: false), + ExpiresAt = table.Column(type: "TIMESTAMP", nullable: true), + StatusName = table.Column(type: "character varying(40)", maxLength: 40, nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_CAPPublishedMessage", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "CAPReceivedMessage", + columns: table => new + { + Id = table.Column(type: "bigint", nullable: false), + Version = table.Column(type: "character varying(20)", maxLength: 20, nullable: true), + Name = table.Column(type: "character varying(400)", maxLength: 400, nullable: false), + Group = table.Column(type: "character varying(200)", maxLength: 200, nullable: true), + Content = table.Column(type: "TEXT", nullable: true), + Retries = table.Column(type: "integer", nullable: true), + Added = table.Column(type: "TIMESTAMP", nullable: false), + ExpiresAt = table.Column(type: "TIMESTAMP", nullable: true), + StatusName = table.Column(type: "character varying(50)", maxLength: 50, nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_CAPReceivedMessage", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "dept", + columns: table => new + { + Id = table.Column(type: "bigint", nullable: false), + Name = table.Column(type: "character varying(100)", maxLength: 100, nullable: false), + Remark = table.Column(type: "character varying(500)", maxLength: 500, nullable: false), + ParentId = table.Column(type: "bigint", nullable: false), + Status = table.Column(type: "integer", nullable: false), + CreatedAt = table.Column(type: "timestamp with time zone", nullable: false), + IsDeleted = table.Column(type: "boolean", nullable: false), + DeletedAt = table.Column(type: "timestamp with time zone", nullable: false), + UpdateTime = table.Column(type: "timestamp with time zone", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_dept", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "role", + columns: table => new + { + Id = table.Column(type: "uuid", nullable: false), + Name = table.Column(type: "character varying(50)", maxLength: 50, nullable: false), + Description = table.Column(type: "character varying(200)", maxLength: 200, nullable: false), + CreatedAt = table.Column(type: "timestamp with time zone", nullable: false), + IsActive = table.Column(type: "boolean", nullable: false), + IsDeleted = table.Column(type: "boolean", nullable: false), + DeletedAt = table.Column(type: "timestamp with time zone", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_role", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "user", + columns: table => new + { + Id = table.Column(type: "bigint", nullable: false), + Name = table.Column(type: "character varying(50)", maxLength: 50, nullable: false), + Email = table.Column(type: "character varying(100)", maxLength: 100, nullable: false), + Phone = table.Column(type: "character varying(20)", maxLength: 20, nullable: false), + RealName = table.Column(type: "character varying(50)", maxLength: 50, nullable: false), + Status = table.Column(type: "integer", nullable: false), + PasswordHash = table.Column(type: "character varying(255)", maxLength: 255, nullable: false), + IsActive = table.Column(type: "boolean", nullable: false), + CreatedAt = table.Column(type: "timestamp with time zone", nullable: false), + LastLoginTime = table.Column(type: "timestamp with time zone", nullable: true), + UpdateTime = table.Column(type: "timestamp with time zone", nullable: false), + IsDeleted = table.Column(type: "boolean", nullable: false), + DeletedAt = table.Column(type: "timestamp with time zone", nullable: false), + Gender = table.Column(type: "character varying(10)", maxLength: 10, nullable: false), + Age = table.Column(type: "integer", nullable: false), + BirthDate = table.Column(type: "timestamp with time zone", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_user", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "role_permission", + columns: table => new + { + RoleId = table.Column(type: "uuid", nullable: false), + PermissionCode = table.Column(type: "character varying(100)", maxLength: 100, nullable: false), + PermissionName = table.Column(type: "character varying(100)", maxLength: 100, nullable: false), + PermissionDescription = table.Column(type: "character varying(200)", maxLength: 200, nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_role_permission", x => new { x.RoleId, x.PermissionCode }); + table.ForeignKey( + name: "FK_role_permission_role_RoleId", + column: x => x.RoleId, + principalTable: "role", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "user_dept", + columns: table => new + { + UserId = table.Column(type: "bigint", nullable: false), + DeptId = table.Column(type: "bigint", nullable: false), + DeptName = table.Column(type: "character varying(100)", maxLength: 100, nullable: false), + AssignedAt = table.Column(type: "timestamp with time zone", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_user_dept", x => x.UserId); + table.ForeignKey( + name: "FK_user_dept_user_UserId", + column: x => x.UserId, + principalTable: "user", + principalColumn: "Id"); + }); + + migrationBuilder.CreateTable( + name: "user_refresh_token", + columns: table => new + { + Id = table.Column(type: "bigint", nullable: false), + UserId = table.Column(type: "bigint", nullable: false), + Token = table.Column(type: "character varying(500)", maxLength: 500, nullable: false), + CreatedTime = table.Column(type: "timestamp with time zone", nullable: false), + ExpiresTime = table.Column(type: "timestamp with time zone", nullable: false), + IsUsed = table.Column(type: "boolean", nullable: false), + IsRevoked = table.Column(type: "boolean", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_user_refresh_token", x => x.Id); + table.ForeignKey( + name: "FK_user_refresh_token_user_UserId", + column: x => x.UserId, + principalTable: "user", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "user_role", + columns: table => new + { + UserId = table.Column(type: "bigint", nullable: false), + RoleId = table.Column(type: "uuid", nullable: false), + RoleName = table.Column(type: "character varying(50)", maxLength: 50, nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_user_role", x => new { x.UserId, x.RoleId }); + table.ForeignKey( + name: "FK_user_role_user_UserId", + column: x => x.UserId, + principalTable: "user", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_ExpiresAt_StatusName", + table: "CAPPublishedMessage", + columns: new[] { "ExpiresAt", "StatusName" }); + + migrationBuilder.CreateIndex( + name: "IX_Version_ExpiresAt_StatusName", + table: "CAPPublishedMessage", + columns: new[] { "Version", "ExpiresAt", "StatusName" }); + + migrationBuilder.CreateIndex( + name: "IX_ExpiresAt_StatusName1", + table: "CAPReceivedMessage", + columns: new[] { "ExpiresAt", "StatusName" }); + + migrationBuilder.CreateIndex( + name: "IX_Version_ExpiresAt_StatusName1", + table: "CAPReceivedMessage", + columns: new[] { "Version", "ExpiresAt", "StatusName" }); + + migrationBuilder.CreateIndex( + name: "IX_dept_IsDeleted", + table: "dept", + column: "IsDeleted"); + + migrationBuilder.CreateIndex( + name: "IX_dept_ParentId", + table: "dept", + column: "ParentId"); + + migrationBuilder.CreateIndex( + name: "IX_dept_Status", + table: "dept", + column: "Status"); + + migrationBuilder.CreateIndex( + name: "IX_role_Name", + table: "role", + column: "Name", + unique: true); + + migrationBuilder.CreateIndex( + name: "IX_user_Email", + table: "user", + column: "Email"); + + migrationBuilder.CreateIndex( + name: "IX_user_Name", + table: "user", + column: "Name"); + + migrationBuilder.CreateIndex( + name: "IX_user_dept_DeptId", + table: "user_dept", + column: "DeptId"); + + migrationBuilder.CreateIndex( + name: "IX_user_dept_UserId", + table: "user_dept", + column: "UserId"); + + migrationBuilder.CreateIndex( + name: "IX_user_refresh_token_UserId", + table: "user_refresh_token", + column: "UserId"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "CAPLock"); + + migrationBuilder.DropTable( + name: "CAPPublishedMessage"); + + migrationBuilder.DropTable( + name: "CAPReceivedMessage"); + + migrationBuilder.DropTable( + name: "dept"); + + migrationBuilder.DropTable( + name: "role_permission"); + + migrationBuilder.DropTable( + name: "user_dept"); + + migrationBuilder.DropTable( + name: "user_refresh_token"); + + migrationBuilder.DropTable( + name: "user_role"); + + migrationBuilder.DropTable( + name: "role"); + + migrationBuilder.DropTable( + name: "user"); + } + } +} diff --git a/template/src/ABC.Template.Infrastructure/MigrationsAll/GaussDB-net8.0-admin/ApplicationDbContextModelSnapshot.cs b/template/src/ABC.Template.Infrastructure/MigrationsAll/GaussDB-net8.0-admin/ApplicationDbContextModelSnapshot.cs new file mode 100644 index 00000000..b1b146f1 --- /dev/null +++ b/template/src/ABC.Template.Infrastructure/MigrationsAll/GaussDB-net8.0-admin/ApplicationDbContextModelSnapshot.cs @@ -0,0 +1,431 @@ +// +using System; +using ABC.Template.Infrastructure; +using GaussDB.EntityFrameworkCore.PostgreSQL.Metadata; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace ABC.Template.Infrastructure.Migrations +{ + [DbContext(typeof(ApplicationDbContext))] + partial class ApplicationDbContextModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "8.0.10") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + GaussDBModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.DeptAggregate.Dept", b => + { + b.Property("Id") + .HasColumnType("bigint"); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("DeletedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("character varying(100)"); + + b.Property("ParentId") + .HasColumnType("bigint"); + + b.Property("Remark") + .IsRequired() + .HasMaxLength(500) + .HasColumnType("character varying(500)"); + + b.Property("Status") + .HasColumnType("integer"); + + b.Property("UpdateTime") + .HasColumnType("timestamp with time zone"); + + b.HasKey("Id"); + + b.HasIndex("IsDeleted"); + + b.HasIndex("ParentId"); + + b.HasIndex("Status"); + + b.ToTable("dept", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.Role", b => + { + b.Property("Id") + .HasColumnType("uuid"); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("DeletedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("Description") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("character varying(200)"); + + b.Property("IsActive") + .HasColumnType("boolean"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("character varying(50)"); + + b.HasKey("Id"); + + b.HasIndex("Name") + .IsUnique(); + + b.ToTable("role", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.RolePermission", b => + { + b.Property("RoleId") + .HasColumnType("uuid"); + + b.Property("PermissionCode") + .HasMaxLength(100) + .HasColumnType("character varying(100)"); + + b.Property("PermissionDescription") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("character varying(200)"); + + b.Property("PermissionName") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("character varying(100)"); + + b.HasKey("RoleId", "PermissionCode"); + + b.ToTable("role_permission", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.User", b => + { + b.Property("Id") + .HasColumnType("bigint"); + + b.Property("Age") + .HasColumnType("integer"); + + b.Property("BirthDate") + .HasColumnType("timestamp with time zone"); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("DeletedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("Email") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("character varying(100)"); + + b.Property("Gender") + .IsRequired() + .HasMaxLength(10) + .HasColumnType("character varying(10)"); + + b.Property("IsActive") + .HasColumnType("boolean"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("LastLoginTime") + .HasColumnType("timestamp with time zone"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("character varying(50)"); + + b.Property("PasswordHash") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("character varying(255)"); + + b.Property("Phone") + .IsRequired() + .HasMaxLength(20) + .HasColumnType("character varying(20)"); + + b.Property("RealName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("character varying(50)"); + + b.Property("Status") + .HasColumnType("integer"); + + b.Property("UpdateTime") + .HasColumnType("timestamp with time zone"); + + b.HasKey("Id"); + + b.HasIndex("Email"); + + b.HasIndex("Name"); + + b.ToTable("user", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserDept", b => + { + b.Property("UserId") + .HasColumnType("bigint"); + + b.Property("AssignedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("DeptId") + .HasColumnType("bigint"); + + b.Property("DeptName") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("character varying(100)"); + + b.HasKey("UserId"); + + b.HasIndex("DeptId"); + + b.HasIndex("UserId"); + + b.ToTable("user_dept", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRefreshToken", b => + { + b.Property("Id") + .HasColumnType("bigint"); + + b.Property("CreatedTime") + .HasColumnType("timestamp with time zone"); + + b.Property("ExpiresTime") + .HasColumnType("timestamp with time zone"); + + b.Property("IsRevoked") + .HasColumnType("boolean"); + + b.Property("IsUsed") + .HasColumnType("boolean"); + + b.Property("Token") + .IsRequired() + .HasMaxLength(500) + .HasColumnType("character varying(500)"); + + b.Property("UserId") + .HasColumnType("bigint"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("user_refresh_token", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRole", b => + { + b.Property("UserId") + .HasColumnType("bigint"); + + b.Property("RoleId") + .HasColumnType("uuid"); + + b.Property("RoleName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("character varying(50)"); + + b.HasKey("UserId", "RoleId"); + + b.ToTable("user_role", (string)null); + }); + + modelBuilder.Entity("NetCorePal.Extensions.DistributedTransactions.CAP.Persistence.CapLock", b => + { + b.Property("Key") + .HasMaxLength(128) + .HasColumnType("character varying(128)"); + + b.Property("Instance") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.Property("LastLockTime") + .HasColumnType("TIMESTAMP"); + + b.HasKey("Key"); + + b.ToTable("CAPLock", (string)null); + }); + + modelBuilder.Entity("NetCorePal.Extensions.DistributedTransactions.CAP.Persistence.PublishedMessage", b => + { + b.Property("Id") + .HasColumnType("bigint"); + + b.Property("Added") + .HasColumnType("TIMESTAMP"); + + b.Property("Content") + .HasColumnType("TEXT"); + + b.Property("ExpiresAt") + .HasColumnType("TIMESTAMP"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("character varying(200)"); + + b.Property("Retries") + .HasColumnType("integer"); + + b.Property("StatusName") + .IsRequired() + .HasMaxLength(40) + .HasColumnType("character varying(40)"); + + b.Property("Version") + .HasMaxLength(20) + .HasColumnType("character varying(20)"); + + b.HasKey("Id"); + + b.HasIndex(new[] { "ExpiresAt", "StatusName" }, "IX_ExpiresAt_StatusName"); + + b.HasIndex(new[] { "Version", "ExpiresAt", "StatusName" }, "IX_Version_ExpiresAt_StatusName"); + + b.ToTable("CAPPublishedMessage", (string)null); + }); + + modelBuilder.Entity("NetCorePal.Extensions.DistributedTransactions.CAP.Persistence.ReceivedMessage", b => + { + b.Property("Id") + .HasColumnType("bigint"); + + b.Property("Added") + .HasColumnType("TIMESTAMP"); + + b.Property("Content") + .HasColumnType("TEXT"); + + b.Property("ExpiresAt") + .HasColumnType("TIMESTAMP"); + + b.Property("Group") + .HasMaxLength(200) + .HasColumnType("character varying(200)"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(400) + .HasColumnType("character varying(400)"); + + b.Property("Retries") + .HasColumnType("integer"); + + b.Property("StatusName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("character varying(50)"); + + b.Property("Version") + .HasMaxLength(20) + .HasColumnType("character varying(20)"); + + b.HasKey("Id"); + + b.HasIndex(new[] { "ExpiresAt", "StatusName" }, "IX_ExpiresAt_StatusName") + .HasDatabaseName("IX_ExpiresAt_StatusName1"); + + b.HasIndex(new[] { "Version", "ExpiresAt", "StatusName" }, "IX_Version_ExpiresAt_StatusName") + .HasDatabaseName("IX_Version_ExpiresAt_StatusName1"); + + b.ToTable("CAPReceivedMessage", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.RolePermission", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.RoleAggregate.Role", null) + .WithMany("Permissions") + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserDept", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.UserAggregate.User", null) + .WithOne("Dept") + .HasForeignKey("ABC.Template.Domain.AggregatesModel.UserAggregate.UserDept", "UserId") + .OnDelete(DeleteBehavior.ClientCascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRefreshToken", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.UserAggregate.User", null) + .WithMany("RefreshTokens") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRole", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.UserAggregate.User", null) + .WithMany("Roles") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.Role", b => + { + b.Navigation("Permissions"); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.User", b => + { + b.Navigation("Dept") + .IsRequired(); + + b.Navigation("RefreshTokens"); + + b.Navigation("Roles"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/template/src/ABC.Template.Infrastructure/MigrationsAll/GaussDB-net8.0/20251225065148_Init.Designer.cs b/template/src/ABC.Template.Infrastructure/MigrationsAll/GaussDB-net8.0/20260122054926_Init.Designer.cs similarity index 77% rename from template/src/ABC.Template.Infrastructure/MigrationsAll/GaussDB-net8.0/20251225065148_Init.Designer.cs rename to template/src/ABC.Template.Infrastructure/MigrationsAll/GaussDB-net8.0/20260122054926_Init.Designer.cs index fd51b55b..0f273453 100644 --- a/template/src/ABC.Template.Infrastructure/MigrationsAll/GaussDB-net8.0/20251225065148_Init.Designer.cs +++ b/template/src/ABC.Template.Infrastructure/MigrationsAll/GaussDB-net8.0/20260122054926_Init.Designer.cs @@ -1,18 +1,18 @@ // using System; +using ABC.Template.Infrastructure; using GaussDB.EntityFrameworkCore.PostgreSQL.Metadata; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using ABC.Template.Infrastructure; #nullable disable namespace ABC.Template.Infrastructure.Migrations { [DbContext(typeof(ApplicationDbContext))] - [Migration("20251225065148_Init")] + [Migration("20260122054926_Init")] partial class Init { /// @@ -128,47 +128,6 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.ToTable("CAPReceivedMessage", (string)null); }); - - modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.DeliverAggregate.DeliverRecord", b => - { - b.Property("Id") - .HasColumnType("uuid"); - - b.Property("OrderId") - .HasColumnType("uuid"); - - b.HasKey("Id"); - - b.ToTable("deliverrecord", (string)null); - }); - - modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.OrderAggregate.Order", b => - { - b.Property("Id") - .HasColumnType("uuid"); - - b.Property("Count") - .HasColumnType("integer"); - - b.Property("Name") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("character varying(100)"); - - b.Property("Paid") - .HasColumnType("boolean"); - - b.Property("RowVersion") - .IsConcurrencyToken() - .HasColumnType("integer"); - - b.Property("UpdateTime") - .HasColumnType("timestamp with time zone"); - - b.HasKey("Id"); - - b.ToTable("order", (string)null); - }); #pragma warning restore 612, 618 } } diff --git a/template/src/ABC.Template.Infrastructure/MigrationsAll/GaussDB-net9.0/20251225065156_Init.cs b/template/src/ABC.Template.Infrastructure/MigrationsAll/GaussDB-net8.0/20260122054926_Init.cs similarity index 75% rename from template/src/ABC.Template.Infrastructure/MigrationsAll/GaussDB-net9.0/20251225065156_Init.cs rename to template/src/ABC.Template.Infrastructure/MigrationsAll/GaussDB-net8.0/20260122054926_Init.cs index 145ea585..53c8065f 100644 --- a/template/src/ABC.Template.Infrastructure/MigrationsAll/GaussDB-net9.0/20251225065156_Init.cs +++ b/template/src/ABC.Template.Infrastructure/MigrationsAll/GaussDB-net8.0/20260122054926_Init.cs @@ -61,34 +61,6 @@ protected override void Up(MigrationBuilder migrationBuilder) table.PrimaryKey("PK_CAPReceivedMessage", x => x.Id); }); - migrationBuilder.CreateTable( - name: "deliverrecord", - columns: table => new - { - Id = table.Column(type: "uuid", nullable: false), - OrderId = table.Column(type: "uuid", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_deliverrecord", x => x.Id); - }); - - migrationBuilder.CreateTable( - name: "order", - columns: table => new - { - Id = table.Column(type: "uuid", nullable: false), - Paid = table.Column(type: "boolean", nullable: false), - Name = table.Column(type: "character varying(100)", maxLength: 100, nullable: false), - Count = table.Column(type: "integer", nullable: false), - RowVersion = table.Column(type: "integer", nullable: false), - UpdateTime = table.Column(type: "timestamp with time zone", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_order", x => x.Id); - }); - migrationBuilder.CreateIndex( name: "IX_ExpiresAt_StatusName", table: "CAPPublishedMessage", @@ -121,12 +93,6 @@ protected override void Down(MigrationBuilder migrationBuilder) migrationBuilder.DropTable( name: "CAPReceivedMessage"); - - migrationBuilder.DropTable( - name: "deliverrecord"); - - migrationBuilder.DropTable( - name: "order"); } } } diff --git a/template/src/ABC.Template.Infrastructure/MigrationsAll/GaussDB-net8.0/ApplicationDbContextModelSnapshot.cs b/template/src/ABC.Template.Infrastructure/MigrationsAll/GaussDB-net8.0/ApplicationDbContextModelSnapshot.cs index 2c24e7d4..e26b0d9d 100644 --- a/template/src/ABC.Template.Infrastructure/MigrationsAll/GaussDB-net8.0/ApplicationDbContextModelSnapshot.cs +++ b/template/src/ABC.Template.Infrastructure/MigrationsAll/GaussDB-net8.0/ApplicationDbContextModelSnapshot.cs @@ -1,10 +1,10 @@ // using System; +using ABC.Template.Infrastructure; using GaussDB.EntityFrameworkCore.PostgreSQL.Metadata; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using ABC.Template.Infrastructure; #nullable disable @@ -125,47 +125,6 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.ToTable("CAPReceivedMessage", (string)null); }); - - modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.DeliverAggregate.DeliverRecord", b => - { - b.Property("Id") - .HasColumnType("uuid"); - - b.Property("OrderId") - .HasColumnType("uuid"); - - b.HasKey("Id"); - - b.ToTable("deliverrecord", (string)null); - }); - - modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.OrderAggregate.Order", b => - { - b.Property("Id") - .HasColumnType("uuid"); - - b.Property("Count") - .HasColumnType("integer"); - - b.Property("Name") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("character varying(100)"); - - b.Property("Paid") - .HasColumnType("boolean"); - - b.Property("RowVersion") - .IsConcurrencyToken() - .HasColumnType("integer"); - - b.Property("UpdateTime") - .HasColumnType("timestamp with time zone"); - - b.HasKey("Id"); - - b.ToTable("order", (string)null); - }); #pragma warning restore 612, 618 } } diff --git a/template/src/ABC.Template.Infrastructure/MigrationsAll/GaussDB-net9.0-admin/20260122055001_Init.Designer.cs b/template/src/ABC.Template.Infrastructure/MigrationsAll/GaussDB-net9.0-admin/20260122055001_Init.Designer.cs new file mode 100644 index 00000000..8b28fbb6 --- /dev/null +++ b/template/src/ABC.Template.Infrastructure/MigrationsAll/GaussDB-net9.0-admin/20260122055001_Init.Designer.cs @@ -0,0 +1,434 @@ +// +using System; +using ABC.Template.Infrastructure; +using GaussDB.EntityFrameworkCore.PostgreSQL.Metadata; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace ABC.Template.Infrastructure.Migrations +{ + [DbContext(typeof(ApplicationDbContext))] + [Migration("20260122055001_Init")] + partial class Init + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "9.0.0") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + GaussDBModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.DeptAggregate.Dept", b => + { + b.Property("Id") + .HasColumnType("bigint"); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("DeletedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("character varying(100)"); + + b.Property("ParentId") + .HasColumnType("bigint"); + + b.Property("Remark") + .IsRequired() + .HasMaxLength(500) + .HasColumnType("character varying(500)"); + + b.Property("Status") + .HasColumnType("integer"); + + b.Property("UpdateTime") + .HasColumnType("timestamp with time zone"); + + b.HasKey("Id"); + + b.HasIndex("IsDeleted"); + + b.HasIndex("ParentId"); + + b.HasIndex("Status"); + + b.ToTable("dept", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.Role", b => + { + b.Property("Id") + .HasColumnType("uuid"); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("DeletedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("Description") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("character varying(200)"); + + b.Property("IsActive") + .HasColumnType("boolean"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("character varying(50)"); + + b.HasKey("Id"); + + b.HasIndex("Name") + .IsUnique(); + + b.ToTable("role", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.RolePermission", b => + { + b.Property("RoleId") + .HasColumnType("uuid"); + + b.Property("PermissionCode") + .HasMaxLength(100) + .HasColumnType("character varying(100)"); + + b.Property("PermissionDescription") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("character varying(200)"); + + b.Property("PermissionName") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("character varying(100)"); + + b.HasKey("RoleId", "PermissionCode"); + + b.ToTable("role_permission", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.User", b => + { + b.Property("Id") + .HasColumnType("bigint"); + + b.Property("Age") + .HasColumnType("integer"); + + b.Property("BirthDate") + .HasColumnType("timestamp with time zone"); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("DeletedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("Email") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("character varying(100)"); + + b.Property("Gender") + .IsRequired() + .HasMaxLength(10) + .HasColumnType("character varying(10)"); + + b.Property("IsActive") + .HasColumnType("boolean"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("LastLoginTime") + .HasColumnType("timestamp with time zone"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("character varying(50)"); + + b.Property("PasswordHash") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("character varying(255)"); + + b.Property("Phone") + .IsRequired() + .HasMaxLength(20) + .HasColumnType("character varying(20)"); + + b.Property("RealName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("character varying(50)"); + + b.Property("Status") + .HasColumnType("integer"); + + b.Property("UpdateTime") + .HasColumnType("timestamp with time zone"); + + b.HasKey("Id"); + + b.HasIndex("Email"); + + b.HasIndex("Name"); + + b.ToTable("user", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserDept", b => + { + b.Property("UserId") + .HasColumnType("bigint"); + + b.Property("AssignedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("DeptId") + .HasColumnType("bigint"); + + b.Property("DeptName") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("character varying(100)"); + + b.HasKey("UserId"); + + b.HasIndex("DeptId"); + + b.HasIndex("UserId"); + + b.ToTable("user_dept", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRefreshToken", b => + { + b.Property("Id") + .HasColumnType("bigint"); + + b.Property("CreatedTime") + .HasColumnType("timestamp with time zone"); + + b.Property("ExpiresTime") + .HasColumnType("timestamp with time zone"); + + b.Property("IsRevoked") + .HasColumnType("boolean"); + + b.Property("IsUsed") + .HasColumnType("boolean"); + + b.Property("Token") + .IsRequired() + .HasMaxLength(500) + .HasColumnType("character varying(500)"); + + b.Property("UserId") + .HasColumnType("bigint"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("user_refresh_token", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRole", b => + { + b.Property("UserId") + .HasColumnType("bigint"); + + b.Property("RoleId") + .HasColumnType("uuid"); + + b.Property("RoleName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("character varying(50)"); + + b.HasKey("UserId", "RoleId"); + + b.ToTable("user_role", (string)null); + }); + + modelBuilder.Entity("NetCorePal.Extensions.DistributedTransactions.CAP.Persistence.CapLock", b => + { + b.Property("Key") + .HasMaxLength(128) + .HasColumnType("character varying(128)"); + + b.Property("Instance") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.Property("LastLockTime") + .HasColumnType("TIMESTAMP"); + + b.HasKey("Key"); + + b.ToTable("CAPLock", (string)null); + }); + + modelBuilder.Entity("NetCorePal.Extensions.DistributedTransactions.CAP.Persistence.PublishedMessage", b => + { + b.Property("Id") + .HasColumnType("bigint"); + + b.Property("Added") + .HasColumnType("TIMESTAMP"); + + b.Property("Content") + .HasColumnType("TEXT"); + + b.Property("ExpiresAt") + .HasColumnType("TIMESTAMP"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("character varying(200)"); + + b.Property("Retries") + .HasColumnType("integer"); + + b.Property("StatusName") + .IsRequired() + .HasMaxLength(40) + .HasColumnType("character varying(40)"); + + b.Property("Version") + .HasMaxLength(20) + .HasColumnType("character varying(20)"); + + b.HasKey("Id"); + + b.HasIndex(new[] { "ExpiresAt", "StatusName" }, "IX_ExpiresAt_StatusName"); + + b.HasIndex(new[] { "Version", "ExpiresAt", "StatusName" }, "IX_Version_ExpiresAt_StatusName"); + + b.ToTable("CAPPublishedMessage", (string)null); + }); + + modelBuilder.Entity("NetCorePal.Extensions.DistributedTransactions.CAP.Persistence.ReceivedMessage", b => + { + b.Property("Id") + .HasColumnType("bigint"); + + b.Property("Added") + .HasColumnType("TIMESTAMP"); + + b.Property("Content") + .HasColumnType("TEXT"); + + b.Property("ExpiresAt") + .HasColumnType("TIMESTAMP"); + + b.Property("Group") + .HasMaxLength(200) + .HasColumnType("character varying(200)"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(400) + .HasColumnType("character varying(400)"); + + b.Property("Retries") + .HasColumnType("integer"); + + b.Property("StatusName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("character varying(50)"); + + b.Property("Version") + .HasMaxLength(20) + .HasColumnType("character varying(20)"); + + b.HasKey("Id"); + + b.HasIndex(new[] { "ExpiresAt", "StatusName" }, "IX_ExpiresAt_StatusName") + .HasDatabaseName("IX_ExpiresAt_StatusName1"); + + b.HasIndex(new[] { "Version", "ExpiresAt", "StatusName" }, "IX_Version_ExpiresAt_StatusName") + .HasDatabaseName("IX_Version_ExpiresAt_StatusName1"); + + b.ToTable("CAPReceivedMessage", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.RolePermission", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.RoleAggregate.Role", null) + .WithMany("Permissions") + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserDept", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.UserAggregate.User", null) + .WithOne("Dept") + .HasForeignKey("ABC.Template.Domain.AggregatesModel.UserAggregate.UserDept", "UserId") + .OnDelete(DeleteBehavior.ClientCascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRefreshToken", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.UserAggregate.User", null) + .WithMany("RefreshTokens") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRole", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.UserAggregate.User", null) + .WithMany("Roles") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.Role", b => + { + b.Navigation("Permissions"); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.User", b => + { + b.Navigation("Dept") + .IsRequired(); + + b.Navigation("RefreshTokens"); + + b.Navigation("Roles"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/template/src/ABC.Template.Infrastructure/MigrationsAll/GaussDB-net9.0-admin/20260122055001_Init.cs b/template/src/ABC.Template.Infrastructure/MigrationsAll/GaussDB-net9.0-admin/20260122055001_Init.cs new file mode 100644 index 00000000..408f44cd --- /dev/null +++ b/template/src/ABC.Template.Infrastructure/MigrationsAll/GaussDB-net9.0-admin/20260122055001_Init.cs @@ -0,0 +1,308 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace ABC.Template.Infrastructure.Migrations +{ + /// + public partial class Init : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "CAPLock", + columns: table => new + { + Key = table.Column(type: "character varying(128)", maxLength: 128, nullable: false), + Instance = table.Column(type: "character varying(256)", maxLength: 256, nullable: true), + LastLockTime = table.Column(type: "TIMESTAMP", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_CAPLock", x => x.Key); + }); + + migrationBuilder.CreateTable( + name: "CAPPublishedMessage", + columns: table => new + { + Id = table.Column(type: "bigint", nullable: false), + Version = table.Column(type: "character varying(20)", maxLength: 20, nullable: true), + Name = table.Column(type: "character varying(200)", maxLength: 200, nullable: false), + Content = table.Column(type: "TEXT", nullable: true), + Retries = table.Column(type: "integer", nullable: true), + Added = table.Column(type: "TIMESTAMP", nullable: false), + ExpiresAt = table.Column(type: "TIMESTAMP", nullable: true), + StatusName = table.Column(type: "character varying(40)", maxLength: 40, nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_CAPPublishedMessage", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "CAPReceivedMessage", + columns: table => new + { + Id = table.Column(type: "bigint", nullable: false), + Version = table.Column(type: "character varying(20)", maxLength: 20, nullable: true), + Name = table.Column(type: "character varying(400)", maxLength: 400, nullable: false), + Group = table.Column(type: "character varying(200)", maxLength: 200, nullable: true), + Content = table.Column(type: "TEXT", nullable: true), + Retries = table.Column(type: "integer", nullable: true), + Added = table.Column(type: "TIMESTAMP", nullable: false), + ExpiresAt = table.Column(type: "TIMESTAMP", nullable: true), + StatusName = table.Column(type: "character varying(50)", maxLength: 50, nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_CAPReceivedMessage", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "dept", + columns: table => new + { + Id = table.Column(type: "bigint", nullable: false), + Name = table.Column(type: "character varying(100)", maxLength: 100, nullable: false), + Remark = table.Column(type: "character varying(500)", maxLength: 500, nullable: false), + ParentId = table.Column(type: "bigint", nullable: false), + Status = table.Column(type: "integer", nullable: false), + CreatedAt = table.Column(type: "timestamp with time zone", nullable: false), + IsDeleted = table.Column(type: "boolean", nullable: false), + DeletedAt = table.Column(type: "timestamp with time zone", nullable: false), + UpdateTime = table.Column(type: "timestamp with time zone", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_dept", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "role", + columns: table => new + { + Id = table.Column(type: "uuid", nullable: false), + Name = table.Column(type: "character varying(50)", maxLength: 50, nullable: false), + Description = table.Column(type: "character varying(200)", maxLength: 200, nullable: false), + CreatedAt = table.Column(type: "timestamp with time zone", nullable: false), + IsActive = table.Column(type: "boolean", nullable: false), + IsDeleted = table.Column(type: "boolean", nullable: false), + DeletedAt = table.Column(type: "timestamp with time zone", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_role", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "user", + columns: table => new + { + Id = table.Column(type: "bigint", nullable: false), + Name = table.Column(type: "character varying(50)", maxLength: 50, nullable: false), + Email = table.Column(type: "character varying(100)", maxLength: 100, nullable: false), + Phone = table.Column(type: "character varying(20)", maxLength: 20, nullable: false), + RealName = table.Column(type: "character varying(50)", maxLength: 50, nullable: false), + Status = table.Column(type: "integer", nullable: false), + PasswordHash = table.Column(type: "character varying(255)", maxLength: 255, nullable: false), + IsActive = table.Column(type: "boolean", nullable: false), + CreatedAt = table.Column(type: "timestamp with time zone", nullable: false), + LastLoginTime = table.Column(type: "timestamp with time zone", nullable: true), + UpdateTime = table.Column(type: "timestamp with time zone", nullable: false), + IsDeleted = table.Column(type: "boolean", nullable: false), + DeletedAt = table.Column(type: "timestamp with time zone", nullable: false), + Gender = table.Column(type: "character varying(10)", maxLength: 10, nullable: false), + Age = table.Column(type: "integer", nullable: false), + BirthDate = table.Column(type: "timestamp with time zone", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_user", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "role_permission", + columns: table => new + { + RoleId = table.Column(type: "uuid", nullable: false), + PermissionCode = table.Column(type: "character varying(100)", maxLength: 100, nullable: false), + PermissionName = table.Column(type: "character varying(100)", maxLength: 100, nullable: false), + PermissionDescription = table.Column(type: "character varying(200)", maxLength: 200, nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_role_permission", x => new { x.RoleId, x.PermissionCode }); + table.ForeignKey( + name: "FK_role_permission_role_RoleId", + column: x => x.RoleId, + principalTable: "role", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "user_dept", + columns: table => new + { + UserId = table.Column(type: "bigint", nullable: false), + DeptId = table.Column(type: "bigint", nullable: false), + DeptName = table.Column(type: "character varying(100)", maxLength: 100, nullable: false), + AssignedAt = table.Column(type: "timestamp with time zone", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_user_dept", x => x.UserId); + table.ForeignKey( + name: "FK_user_dept_user_UserId", + column: x => x.UserId, + principalTable: "user", + principalColumn: "Id"); + }); + + migrationBuilder.CreateTable( + name: "user_refresh_token", + columns: table => new + { + Id = table.Column(type: "bigint", nullable: false), + UserId = table.Column(type: "bigint", nullable: false), + Token = table.Column(type: "character varying(500)", maxLength: 500, nullable: false), + CreatedTime = table.Column(type: "timestamp with time zone", nullable: false), + ExpiresTime = table.Column(type: "timestamp with time zone", nullable: false), + IsUsed = table.Column(type: "boolean", nullable: false), + IsRevoked = table.Column(type: "boolean", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_user_refresh_token", x => x.Id); + table.ForeignKey( + name: "FK_user_refresh_token_user_UserId", + column: x => x.UserId, + principalTable: "user", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "user_role", + columns: table => new + { + UserId = table.Column(type: "bigint", nullable: false), + RoleId = table.Column(type: "uuid", nullable: false), + RoleName = table.Column(type: "character varying(50)", maxLength: 50, nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_user_role", x => new { x.UserId, x.RoleId }); + table.ForeignKey( + name: "FK_user_role_user_UserId", + column: x => x.UserId, + principalTable: "user", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_ExpiresAt_StatusName", + table: "CAPPublishedMessage", + columns: new[] { "ExpiresAt", "StatusName" }); + + migrationBuilder.CreateIndex( + name: "IX_Version_ExpiresAt_StatusName", + table: "CAPPublishedMessage", + columns: new[] { "Version", "ExpiresAt", "StatusName" }); + + migrationBuilder.CreateIndex( + name: "IX_ExpiresAt_StatusName1", + table: "CAPReceivedMessage", + columns: new[] { "ExpiresAt", "StatusName" }); + + migrationBuilder.CreateIndex( + name: "IX_Version_ExpiresAt_StatusName1", + table: "CAPReceivedMessage", + columns: new[] { "Version", "ExpiresAt", "StatusName" }); + + migrationBuilder.CreateIndex( + name: "IX_dept_IsDeleted", + table: "dept", + column: "IsDeleted"); + + migrationBuilder.CreateIndex( + name: "IX_dept_ParentId", + table: "dept", + column: "ParentId"); + + migrationBuilder.CreateIndex( + name: "IX_dept_Status", + table: "dept", + column: "Status"); + + migrationBuilder.CreateIndex( + name: "IX_role_Name", + table: "role", + column: "Name", + unique: true); + + migrationBuilder.CreateIndex( + name: "IX_user_Email", + table: "user", + column: "Email"); + + migrationBuilder.CreateIndex( + name: "IX_user_Name", + table: "user", + column: "Name"); + + migrationBuilder.CreateIndex( + name: "IX_user_dept_DeptId", + table: "user_dept", + column: "DeptId"); + + migrationBuilder.CreateIndex( + name: "IX_user_dept_UserId", + table: "user_dept", + column: "UserId"); + + migrationBuilder.CreateIndex( + name: "IX_user_refresh_token_UserId", + table: "user_refresh_token", + column: "UserId"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "CAPLock"); + + migrationBuilder.DropTable( + name: "CAPPublishedMessage"); + + migrationBuilder.DropTable( + name: "CAPReceivedMessage"); + + migrationBuilder.DropTable( + name: "dept"); + + migrationBuilder.DropTable( + name: "role_permission"); + + migrationBuilder.DropTable( + name: "user_dept"); + + migrationBuilder.DropTable( + name: "user_refresh_token"); + + migrationBuilder.DropTable( + name: "user_role"); + + migrationBuilder.DropTable( + name: "role"); + + migrationBuilder.DropTable( + name: "user"); + } + } +} diff --git a/template/src/ABC.Template.Infrastructure/MigrationsAll/GaussDB-net9.0-admin/ApplicationDbContextModelSnapshot.cs b/template/src/ABC.Template.Infrastructure/MigrationsAll/GaussDB-net9.0-admin/ApplicationDbContextModelSnapshot.cs new file mode 100644 index 00000000..64dd485a --- /dev/null +++ b/template/src/ABC.Template.Infrastructure/MigrationsAll/GaussDB-net9.0-admin/ApplicationDbContextModelSnapshot.cs @@ -0,0 +1,431 @@ +// +using System; +using ABC.Template.Infrastructure; +using GaussDB.EntityFrameworkCore.PostgreSQL.Metadata; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace ABC.Template.Infrastructure.Migrations +{ + [DbContext(typeof(ApplicationDbContext))] + partial class ApplicationDbContextModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "9.0.0") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + GaussDBModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.DeptAggregate.Dept", b => + { + b.Property("Id") + .HasColumnType("bigint"); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("DeletedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("character varying(100)"); + + b.Property("ParentId") + .HasColumnType("bigint"); + + b.Property("Remark") + .IsRequired() + .HasMaxLength(500) + .HasColumnType("character varying(500)"); + + b.Property("Status") + .HasColumnType("integer"); + + b.Property("UpdateTime") + .HasColumnType("timestamp with time zone"); + + b.HasKey("Id"); + + b.HasIndex("IsDeleted"); + + b.HasIndex("ParentId"); + + b.HasIndex("Status"); + + b.ToTable("dept", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.Role", b => + { + b.Property("Id") + .HasColumnType("uuid"); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("DeletedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("Description") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("character varying(200)"); + + b.Property("IsActive") + .HasColumnType("boolean"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("character varying(50)"); + + b.HasKey("Id"); + + b.HasIndex("Name") + .IsUnique(); + + b.ToTable("role", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.RolePermission", b => + { + b.Property("RoleId") + .HasColumnType("uuid"); + + b.Property("PermissionCode") + .HasMaxLength(100) + .HasColumnType("character varying(100)"); + + b.Property("PermissionDescription") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("character varying(200)"); + + b.Property("PermissionName") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("character varying(100)"); + + b.HasKey("RoleId", "PermissionCode"); + + b.ToTable("role_permission", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.User", b => + { + b.Property("Id") + .HasColumnType("bigint"); + + b.Property("Age") + .HasColumnType("integer"); + + b.Property("BirthDate") + .HasColumnType("timestamp with time zone"); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("DeletedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("Email") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("character varying(100)"); + + b.Property("Gender") + .IsRequired() + .HasMaxLength(10) + .HasColumnType("character varying(10)"); + + b.Property("IsActive") + .HasColumnType("boolean"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("LastLoginTime") + .HasColumnType("timestamp with time zone"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("character varying(50)"); + + b.Property("PasswordHash") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("character varying(255)"); + + b.Property("Phone") + .IsRequired() + .HasMaxLength(20) + .HasColumnType("character varying(20)"); + + b.Property("RealName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("character varying(50)"); + + b.Property("Status") + .HasColumnType("integer"); + + b.Property("UpdateTime") + .HasColumnType("timestamp with time zone"); + + b.HasKey("Id"); + + b.HasIndex("Email"); + + b.HasIndex("Name"); + + b.ToTable("user", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserDept", b => + { + b.Property("UserId") + .HasColumnType("bigint"); + + b.Property("AssignedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("DeptId") + .HasColumnType("bigint"); + + b.Property("DeptName") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("character varying(100)"); + + b.HasKey("UserId"); + + b.HasIndex("DeptId"); + + b.HasIndex("UserId"); + + b.ToTable("user_dept", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRefreshToken", b => + { + b.Property("Id") + .HasColumnType("bigint"); + + b.Property("CreatedTime") + .HasColumnType("timestamp with time zone"); + + b.Property("ExpiresTime") + .HasColumnType("timestamp with time zone"); + + b.Property("IsRevoked") + .HasColumnType("boolean"); + + b.Property("IsUsed") + .HasColumnType("boolean"); + + b.Property("Token") + .IsRequired() + .HasMaxLength(500) + .HasColumnType("character varying(500)"); + + b.Property("UserId") + .HasColumnType("bigint"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("user_refresh_token", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRole", b => + { + b.Property("UserId") + .HasColumnType("bigint"); + + b.Property("RoleId") + .HasColumnType("uuid"); + + b.Property("RoleName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("character varying(50)"); + + b.HasKey("UserId", "RoleId"); + + b.ToTable("user_role", (string)null); + }); + + modelBuilder.Entity("NetCorePal.Extensions.DistributedTransactions.CAP.Persistence.CapLock", b => + { + b.Property("Key") + .HasMaxLength(128) + .HasColumnType("character varying(128)"); + + b.Property("Instance") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.Property("LastLockTime") + .HasColumnType("TIMESTAMP"); + + b.HasKey("Key"); + + b.ToTable("CAPLock", (string)null); + }); + + modelBuilder.Entity("NetCorePal.Extensions.DistributedTransactions.CAP.Persistence.PublishedMessage", b => + { + b.Property("Id") + .HasColumnType("bigint"); + + b.Property("Added") + .HasColumnType("TIMESTAMP"); + + b.Property("Content") + .HasColumnType("TEXT"); + + b.Property("ExpiresAt") + .HasColumnType("TIMESTAMP"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("character varying(200)"); + + b.Property("Retries") + .HasColumnType("integer"); + + b.Property("StatusName") + .IsRequired() + .HasMaxLength(40) + .HasColumnType("character varying(40)"); + + b.Property("Version") + .HasMaxLength(20) + .HasColumnType("character varying(20)"); + + b.HasKey("Id"); + + b.HasIndex(new[] { "ExpiresAt", "StatusName" }, "IX_ExpiresAt_StatusName"); + + b.HasIndex(new[] { "Version", "ExpiresAt", "StatusName" }, "IX_Version_ExpiresAt_StatusName"); + + b.ToTable("CAPPublishedMessage", (string)null); + }); + + modelBuilder.Entity("NetCorePal.Extensions.DistributedTransactions.CAP.Persistence.ReceivedMessage", b => + { + b.Property("Id") + .HasColumnType("bigint"); + + b.Property("Added") + .HasColumnType("TIMESTAMP"); + + b.Property("Content") + .HasColumnType("TEXT"); + + b.Property("ExpiresAt") + .HasColumnType("TIMESTAMP"); + + b.Property("Group") + .HasMaxLength(200) + .HasColumnType("character varying(200)"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(400) + .HasColumnType("character varying(400)"); + + b.Property("Retries") + .HasColumnType("integer"); + + b.Property("StatusName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("character varying(50)"); + + b.Property("Version") + .HasMaxLength(20) + .HasColumnType("character varying(20)"); + + b.HasKey("Id"); + + b.HasIndex(new[] { "ExpiresAt", "StatusName" }, "IX_ExpiresAt_StatusName") + .HasDatabaseName("IX_ExpiresAt_StatusName1"); + + b.HasIndex(new[] { "Version", "ExpiresAt", "StatusName" }, "IX_Version_ExpiresAt_StatusName") + .HasDatabaseName("IX_Version_ExpiresAt_StatusName1"); + + b.ToTable("CAPReceivedMessage", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.RolePermission", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.RoleAggregate.Role", null) + .WithMany("Permissions") + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserDept", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.UserAggregate.User", null) + .WithOne("Dept") + .HasForeignKey("ABC.Template.Domain.AggregatesModel.UserAggregate.UserDept", "UserId") + .OnDelete(DeleteBehavior.ClientCascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRefreshToken", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.UserAggregate.User", null) + .WithMany("RefreshTokens") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRole", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.UserAggregate.User", null) + .WithMany("Roles") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.Role", b => + { + b.Navigation("Permissions"); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.User", b => + { + b.Navigation("Dept") + .IsRequired(); + + b.Navigation("RefreshTokens"); + + b.Navigation("Roles"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/template/src/ABC.Template.Infrastructure/MigrationsAll/GaussDB-net10.0/20251225065206_Init.Designer.cs b/template/src/ABC.Template.Infrastructure/MigrationsAll/GaussDB-net9.0/20260122054950_Init.Designer.cs similarity index 77% rename from template/src/ABC.Template.Infrastructure/MigrationsAll/GaussDB-net10.0/20251225065206_Init.Designer.cs rename to template/src/ABC.Template.Infrastructure/MigrationsAll/GaussDB-net9.0/20260122054950_Init.Designer.cs index ecac66bc..948d306a 100644 --- a/template/src/ABC.Template.Infrastructure/MigrationsAll/GaussDB-net10.0/20251225065206_Init.Designer.cs +++ b/template/src/ABC.Template.Infrastructure/MigrationsAll/GaussDB-net9.0/20260122054950_Init.Designer.cs @@ -1,18 +1,18 @@ // using System; +using ABC.Template.Infrastructure; using GaussDB.EntityFrameworkCore.PostgreSQL.Metadata; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using ABC.Template.Infrastructure; #nullable disable namespace ABC.Template.Infrastructure.Migrations { [DbContext(typeof(ApplicationDbContext))] - [Migration("20251225065206_Init")] + [Migration("20260122054950_Init")] partial class Init { /// @@ -128,47 +128,6 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.ToTable("CAPReceivedMessage", (string)null); }); - - modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.DeliverAggregate.DeliverRecord", b => - { - b.Property("Id") - .HasColumnType("uuid"); - - b.Property("OrderId") - .HasColumnType("uuid"); - - b.HasKey("Id"); - - b.ToTable("deliverrecord", (string)null); - }); - - modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.OrderAggregate.Order", b => - { - b.Property("Id") - .HasColumnType("uuid"); - - b.Property("Count") - .HasColumnType("integer"); - - b.Property("Name") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("character varying(100)"); - - b.Property("Paid") - .HasColumnType("boolean"); - - b.Property("RowVersion") - .IsConcurrencyToken() - .HasColumnType("integer"); - - b.Property("UpdateTime") - .HasColumnType("timestamp with time zone"); - - b.HasKey("Id"); - - b.ToTable("order", (string)null); - }); #pragma warning restore 612, 618 } } diff --git a/template/src/ABC.Template.Infrastructure/MigrationsAll/GaussDB-net10.0/20251225065206_Init.cs b/template/src/ABC.Template.Infrastructure/MigrationsAll/GaussDB-net9.0/20260122054950_Init.cs similarity index 75% rename from template/src/ABC.Template.Infrastructure/MigrationsAll/GaussDB-net10.0/20251225065206_Init.cs rename to template/src/ABC.Template.Infrastructure/MigrationsAll/GaussDB-net9.0/20260122054950_Init.cs index 145ea585..53c8065f 100644 --- a/template/src/ABC.Template.Infrastructure/MigrationsAll/GaussDB-net10.0/20251225065206_Init.cs +++ b/template/src/ABC.Template.Infrastructure/MigrationsAll/GaussDB-net9.0/20260122054950_Init.cs @@ -61,34 +61,6 @@ protected override void Up(MigrationBuilder migrationBuilder) table.PrimaryKey("PK_CAPReceivedMessage", x => x.Id); }); - migrationBuilder.CreateTable( - name: "deliverrecord", - columns: table => new - { - Id = table.Column(type: "uuid", nullable: false), - OrderId = table.Column(type: "uuid", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_deliverrecord", x => x.Id); - }); - - migrationBuilder.CreateTable( - name: "order", - columns: table => new - { - Id = table.Column(type: "uuid", nullable: false), - Paid = table.Column(type: "boolean", nullable: false), - Name = table.Column(type: "character varying(100)", maxLength: 100, nullable: false), - Count = table.Column(type: "integer", nullable: false), - RowVersion = table.Column(type: "integer", nullable: false), - UpdateTime = table.Column(type: "timestamp with time zone", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_order", x => x.Id); - }); - migrationBuilder.CreateIndex( name: "IX_ExpiresAt_StatusName", table: "CAPPublishedMessage", @@ -121,12 +93,6 @@ protected override void Down(MigrationBuilder migrationBuilder) migrationBuilder.DropTable( name: "CAPReceivedMessage"); - - migrationBuilder.DropTable( - name: "deliverrecord"); - - migrationBuilder.DropTable( - name: "order"); } } } diff --git a/template/src/ABC.Template.Infrastructure/MigrationsAll/GaussDB-net9.0/ApplicationDbContextModelSnapshot.cs b/template/src/ABC.Template.Infrastructure/MigrationsAll/GaussDB-net9.0/ApplicationDbContextModelSnapshot.cs index caf3d84b..c02070c2 100644 --- a/template/src/ABC.Template.Infrastructure/MigrationsAll/GaussDB-net9.0/ApplicationDbContextModelSnapshot.cs +++ b/template/src/ABC.Template.Infrastructure/MigrationsAll/GaussDB-net9.0/ApplicationDbContextModelSnapshot.cs @@ -1,10 +1,10 @@ // using System; +using ABC.Template.Infrastructure; using GaussDB.EntityFrameworkCore.PostgreSQL.Metadata; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using ABC.Template.Infrastructure; #nullable disable @@ -125,47 +125,6 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.ToTable("CAPReceivedMessage", (string)null); }); - - modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.DeliverAggregate.DeliverRecord", b => - { - b.Property("Id") - .HasColumnType("uuid"); - - b.Property("OrderId") - .HasColumnType("uuid"); - - b.HasKey("Id"); - - b.ToTable("deliverrecord", (string)null); - }); - - modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.OrderAggregate.Order", b => - { - b.Property("Id") - .HasColumnType("uuid"); - - b.Property("Count") - .HasColumnType("integer"); - - b.Property("Name") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("character varying(100)"); - - b.Property("Paid") - .HasColumnType("boolean"); - - b.Property("RowVersion") - .IsConcurrencyToken() - .HasColumnType("integer"); - - b.Property("UpdateTime") - .HasColumnType("timestamp with time zone"); - - b.HasKey("Id"); - - b.ToTable("order", (string)null); - }); #pragma warning restore 612, 618 } } diff --git a/template/src/ABC.Template.Infrastructure/MigrationsAll/MySql-net10.0-admin/20260122054504_Init.Designer.cs b/template/src/ABC.Template.Infrastructure/MigrationsAll/MySql-net10.0-admin/20260122054504_Init.Designer.cs new file mode 100644 index 00000000..4f76aa4d --- /dev/null +++ b/template/src/ABC.Template.Infrastructure/MigrationsAll/MySql-net10.0-admin/20260122054504_Init.Designer.cs @@ -0,0 +1,440 @@ +// +using System; +using ABC.Template.Infrastructure; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace ABC.Template.Infrastructure.Migrations +{ + [DbContext(typeof(ApplicationDbContext))] + [Migration("20260122054504_Init")] + partial class Init + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "9.0.0") + .HasAnnotation("Relational:MaxIdentifierLength", 64); + + MySqlModelBuilderExtensions.AutoIncrementColumns(modelBuilder); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.DeptAggregate.Dept", b => + { + b.Property("Id") + .HasColumnType("bigint"); + + b.Property("CreatedAt") + .HasColumnType("datetime(6)"); + + b.Property("DeletedAt") + .HasColumnType("datetime(6)"); + + b.Property("IsDeleted") + .HasColumnType("tinyint(1)"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("varchar(100)"); + + b.Property("ParentId") + .HasColumnType("bigint"); + + b.Property("Remark") + .IsRequired() + .HasMaxLength(500) + .HasColumnType("varchar(500)"); + + b.Property("Status") + .HasColumnType("int"); + + b.Property("UpdateTime") + .HasColumnType("datetime(6)"); + + b.HasKey("Id"); + + b.HasIndex("IsDeleted"); + + b.HasIndex("ParentId"); + + b.HasIndex("Status"); + + b.ToTable("dept", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.Role", b => + { + b.Property("Id") + .HasColumnType("char(36)"); + + b.Property("CreatedAt") + .HasColumnType("datetime(6)"); + + b.Property("DeletedAt") + .HasColumnType("datetime(6)"); + + b.Property("Description") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("varchar(200)"); + + b.Property("IsActive") + .HasColumnType("tinyint(1)"); + + b.Property("IsDeleted") + .HasColumnType("tinyint(1)"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("varchar(50)"); + + b.HasKey("Id"); + + b.HasIndex("Name") + .IsUnique(); + + b.ToTable("role", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.RolePermission", b => + { + b.Property("RoleId") + .HasColumnType("char(36)"); + + b.Property("PermissionCode") + .HasMaxLength(100) + .HasColumnType("varchar(100)"); + + b.Property("PermissionDescription") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("varchar(200)"); + + b.Property("PermissionName") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("varchar(100)"); + + b.HasKey("RoleId", "PermissionCode"); + + b.ToTable("role_permission", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.User", b => + { + b.Property("Id") + .HasColumnType("bigint"); + + b.Property("Age") + .HasColumnType("int"); + + b.Property("BirthDate") + .HasColumnType("datetime(6)"); + + b.Property("CreatedAt") + .HasColumnType("datetime(6)"); + + b.Property("DeletedAt") + .HasColumnType("datetime(6)"); + + b.Property("Email") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("varchar(100)"); + + b.Property("Gender") + .IsRequired() + .HasMaxLength(10) + .HasColumnType("varchar(10)"); + + b.Property("IsActive") + .HasColumnType("tinyint(1)"); + + b.Property("IsDeleted") + .HasColumnType("tinyint(1)"); + + b.Property("LastLoginTime") + .HasColumnType("datetime(6)"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("varchar(50)"); + + b.Property("PasswordHash") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("varchar(255)"); + + b.Property("Phone") + .IsRequired() + .HasMaxLength(20) + .HasColumnType("varchar(20)"); + + b.Property("RealName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("varchar(50)"); + + b.Property("Status") + .HasColumnType("int"); + + b.Property("UpdateTime") + .HasColumnType("datetime(6)"); + + b.HasKey("Id"); + + b.HasIndex("Email"); + + b.HasIndex("Name"); + + b.ToTable("user", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserDept", b => + { + b.Property("UserId") + .HasColumnType("bigint"); + + b.Property("AssignedAt") + .HasColumnType("datetime(6)"); + + b.Property("DeptId") + .HasColumnType("bigint"); + + b.Property("DeptName") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("varchar(100)"); + + b.HasKey("UserId"); + + b.HasIndex("DeptId"); + + b.HasIndex("UserId"); + + b.ToTable("user_dept", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRefreshToken", b => + { + b.Property("Id") + .HasColumnType("bigint"); + + b.Property("CreatedTime") + .HasColumnType("datetime(6)"); + + b.Property("ExpiresTime") + .HasColumnType("datetime(6)"); + + b.Property("IsRevoked") + .HasColumnType("tinyint(1)"); + + b.Property("IsUsed") + .HasColumnType("tinyint(1)"); + + b.Property("Token") + .IsRequired() + .HasMaxLength(500) + .HasColumnType("varchar(500)"); + + b.Property("UserId") + .HasColumnType("bigint"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("user_refresh_token", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRole", b => + { + b.Property("UserId") + .HasColumnType("bigint"); + + b.Property("RoleId") + .HasColumnType("char(36)"); + + b.Property("RoleName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("varchar(50)"); + + b.HasKey("UserId", "RoleId"); + + b.ToTable("user_role", (string)null); + }); + + modelBuilder.Entity("NetCorePal.Extensions.DistributedTransactions.CAP.Persistence.CapLock", b => + { + b.Property("Key") + .HasMaxLength(128) + .HasColumnType("varchar(128)"); + + b.Property("Instance") + .HasMaxLength(256) + .HasColumnType("varchar"); + + b.Property("LastLockTime") + .HasColumnType("DATETIME(6)"); + + b.HasKey("Key"); + + b.ToTable("CAPLock", (string)null); + }); + + modelBuilder.Entity("NetCorePal.Extensions.DistributedTransactions.CAP.Persistence.PublishedMessage", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property("Id")); + + b.Property("Added") + .HasColumnType("DATETIME(6)"); + + b.Property("Content") + .HasColumnType("longtext"); + + b.Property("ExpiresAt") + .HasColumnType("DATETIME(6)"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("varchar(200)"); + + b.Property("Retries") + .HasColumnType("int"); + + b.Property("StatusName") + .IsRequired() + .HasMaxLength(40) + .HasColumnType("varchar(40)"); + + b.Property("Version") + .HasMaxLength(20) + .HasColumnType("varchar(20)"); + + b.HasKey("Id"); + + b.HasIndex(new[] { "ExpiresAt", "StatusName" }, "IX_ExpiresAt_StatusName"); + + b.HasIndex(new[] { "Version", "ExpiresAt", "StatusName" }, "IX_Version_ExpiresAt_StatusName"); + + b.ToTable("CAPPublishedMessage", (string)null); + }); + + modelBuilder.Entity("NetCorePal.Extensions.DistributedTransactions.CAP.Persistence.ReceivedMessage", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property("Id")); + + b.Property("Added") + .HasColumnType("DATETIME(6)"); + + b.Property("Content") + .HasColumnType("longtext"); + + b.Property("ExpiresAt") + .HasColumnType("DATETIME(6)"); + + b.Property("Group") + .HasMaxLength(200) + .HasColumnType("varchar(200)"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(400) + .HasColumnType("varchar(400)"); + + b.Property("Retries") + .HasColumnType("int"); + + b.Property("StatusName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("varchar(50)"); + + b.Property("Version") + .HasMaxLength(20) + .HasColumnType("varchar(20)"); + + b.HasKey("Id"); + + b.HasIndex(new[] { "ExpiresAt", "StatusName" }, "IX_ExpiresAt_StatusName") + .HasDatabaseName("IX_ExpiresAt_StatusName1"); + + b.HasIndex(new[] { "Version", "ExpiresAt", "StatusName" }, "IX_Version_ExpiresAt_StatusName") + .HasDatabaseName("IX_Version_ExpiresAt_StatusName1"); + + b.ToTable("CAPReceivedMessage", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.RolePermission", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.RoleAggregate.Role", null) + .WithMany("Permissions") + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserDept", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.UserAggregate.User", null) + .WithOne("Dept") + .HasForeignKey("ABC.Template.Domain.AggregatesModel.UserAggregate.UserDept", "UserId") + .OnDelete(DeleteBehavior.ClientCascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRefreshToken", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.UserAggregate.User", null) + .WithMany("RefreshTokens") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRole", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.UserAggregate.User", null) + .WithMany("Roles") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.Role", b => + { + b.Navigation("Permissions"); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.User", b => + { + b.Navigation("Dept") + .IsRequired(); + + b.Navigation("RefreshTokens"); + + b.Navigation("Roles"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/template/src/ABC.Template.Infrastructure/MigrationsAll/MySql-net10.0-admin/20260122054504_Init.cs b/template/src/ABC.Template.Infrastructure/MigrationsAll/MySql-net10.0-admin/20260122054504_Init.cs new file mode 100644 index 00000000..290bfee7 --- /dev/null +++ b/template/src/ABC.Template.Infrastructure/MigrationsAll/MySql-net10.0-admin/20260122054504_Init.cs @@ -0,0 +1,351 @@ +using System; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace ABC.Template.Infrastructure.Migrations +{ + /// + public partial class Init : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AlterDatabase() + .Annotation("MySql:CharSet", "utf8mb4"); + + migrationBuilder.CreateTable( + name: "CAPLock", + columns: table => new + { + Key = table.Column(type: "varchar(128)", maxLength: 128, nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + Instance = table.Column(type: "varchar(256)", maxLength: 256, nullable: true) + .Annotation("MySql:CharSet", "utf8mb4"), + LastLockTime = table.Column(type: "DATETIME(6)", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_CAPLock", x => x.Key); + }) + .Annotation("MySql:CharSet", "utf8mb4"); + + migrationBuilder.CreateTable( + name: "CAPPublishedMessage", + columns: table => new + { + Id = table.Column(type: "bigint", nullable: false) + .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), + Version = table.Column(type: "varchar(20)", maxLength: 20, nullable: true) + .Annotation("MySql:CharSet", "utf8mb4"), + Name = table.Column(type: "varchar(200)", maxLength: 200, nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + Content = table.Column(type: "longtext", nullable: true) + .Annotation("MySql:CharSet", "utf8mb4"), + Retries = table.Column(type: "int", nullable: true), + Added = table.Column(type: "DATETIME(6)", nullable: false), + ExpiresAt = table.Column(type: "DATETIME(6)", nullable: true), + StatusName = table.Column(type: "varchar(40)", maxLength: 40, nullable: false) + .Annotation("MySql:CharSet", "utf8mb4") + }, + constraints: table => + { + table.PrimaryKey("PK_CAPPublishedMessage", x => x.Id); + }) + .Annotation("MySql:CharSet", "utf8mb4"); + + migrationBuilder.CreateTable( + name: "CAPReceivedMessage", + columns: table => new + { + Id = table.Column(type: "bigint", nullable: false) + .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), + Version = table.Column(type: "varchar(20)", maxLength: 20, nullable: true) + .Annotation("MySql:CharSet", "utf8mb4"), + Name = table.Column(type: "varchar(400)", maxLength: 400, nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + Group = table.Column(type: "varchar(200)", maxLength: 200, nullable: true) + .Annotation("MySql:CharSet", "utf8mb4"), + Content = table.Column(type: "longtext", nullable: true) + .Annotation("MySql:CharSet", "utf8mb4"), + Retries = table.Column(type: "int", nullable: true), + Added = table.Column(type: "DATETIME(6)", nullable: false), + ExpiresAt = table.Column(type: "DATETIME(6)", nullable: true), + StatusName = table.Column(type: "varchar(50)", maxLength: 50, nullable: false) + .Annotation("MySql:CharSet", "utf8mb4") + }, + constraints: table => + { + table.PrimaryKey("PK_CAPReceivedMessage", x => x.Id); + }) + .Annotation("MySql:CharSet", "utf8mb4"); + + migrationBuilder.CreateTable( + name: "dept", + columns: table => new + { + Id = table.Column(type: "bigint", nullable: false), + Name = table.Column(type: "varchar(100)", maxLength: 100, nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + Remark = table.Column(type: "varchar(500)", maxLength: 500, nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + ParentId = table.Column(type: "bigint", nullable: false), + Status = table.Column(type: "int", nullable: false), + CreatedAt = table.Column(type: "datetime(6)", nullable: false), + IsDeleted = table.Column(type: "tinyint(1)", nullable: false), + DeletedAt = table.Column(type: "datetime(6)", nullable: false), + UpdateTime = table.Column(type: "datetime(6)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_dept", x => x.Id); + }) + .Annotation("MySql:CharSet", "utf8mb4"); + + migrationBuilder.CreateTable( + name: "role", + columns: table => new + { + Id = table.Column(type: "char(36)", nullable: false, collation: "ascii_general_ci"), + Name = table.Column(type: "varchar(50)", maxLength: 50, nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + Description = table.Column(type: "varchar(200)", maxLength: 200, nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + CreatedAt = table.Column(type: "datetime(6)", nullable: false), + IsActive = table.Column(type: "tinyint(1)", nullable: false), + IsDeleted = table.Column(type: "tinyint(1)", nullable: false), + DeletedAt = table.Column(type: "datetime(6)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_role", x => x.Id); + }) + .Annotation("MySql:CharSet", "utf8mb4"); + + migrationBuilder.CreateTable( + name: "user", + columns: table => new + { + Id = table.Column(type: "bigint", nullable: false), + Name = table.Column(type: "varchar(50)", maxLength: 50, nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + Email = table.Column(type: "varchar(100)", maxLength: 100, nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + Phone = table.Column(type: "varchar(20)", maxLength: 20, nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + RealName = table.Column(type: "varchar(50)", maxLength: 50, nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + Status = table.Column(type: "int", nullable: false), + PasswordHash = table.Column(type: "varchar(255)", maxLength: 255, nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + IsActive = table.Column(type: "tinyint(1)", nullable: false), + CreatedAt = table.Column(type: "datetime(6)", nullable: false), + LastLoginTime = table.Column(type: "datetime(6)", nullable: true), + UpdateTime = table.Column(type: "datetime(6)", nullable: false), + IsDeleted = table.Column(type: "tinyint(1)", nullable: false), + DeletedAt = table.Column(type: "datetime(6)", nullable: false), + Gender = table.Column(type: "varchar(10)", maxLength: 10, nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + Age = table.Column(type: "int", nullable: false), + BirthDate = table.Column(type: "datetime(6)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_user", x => x.Id); + }) + .Annotation("MySql:CharSet", "utf8mb4"); + + migrationBuilder.CreateTable( + name: "role_permission", + columns: table => new + { + RoleId = table.Column(type: "char(36)", nullable: false, collation: "ascii_general_ci"), + PermissionCode = table.Column(type: "varchar(100)", maxLength: 100, nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + PermissionName = table.Column(type: "varchar(100)", maxLength: 100, nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + PermissionDescription = table.Column(type: "varchar(200)", maxLength: 200, nullable: false) + .Annotation("MySql:CharSet", "utf8mb4") + }, + constraints: table => + { + table.PrimaryKey("PK_role_permission", x => new { x.RoleId, x.PermissionCode }); + table.ForeignKey( + name: "FK_role_permission_role_RoleId", + column: x => x.RoleId, + principalTable: "role", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }) + .Annotation("MySql:CharSet", "utf8mb4"); + + migrationBuilder.CreateTable( + name: "user_dept", + columns: table => new + { + UserId = table.Column(type: "bigint", nullable: false), + DeptId = table.Column(type: "bigint", nullable: false), + DeptName = table.Column(type: "varchar(100)", maxLength: 100, nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + AssignedAt = table.Column(type: "datetime(6)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_user_dept", x => x.UserId); + table.ForeignKey( + name: "FK_user_dept_user_UserId", + column: x => x.UserId, + principalTable: "user", + principalColumn: "Id"); + }) + .Annotation("MySql:CharSet", "utf8mb4"); + + migrationBuilder.CreateTable( + name: "user_refresh_token", + columns: table => new + { + Id = table.Column(type: "bigint", nullable: false), + UserId = table.Column(type: "bigint", nullable: false), + Token = table.Column(type: "varchar(500)", maxLength: 500, nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + CreatedTime = table.Column(type: "datetime(6)", nullable: false), + ExpiresTime = table.Column(type: "datetime(6)", nullable: false), + IsUsed = table.Column(type: "tinyint(1)", nullable: false), + IsRevoked = table.Column(type: "tinyint(1)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_user_refresh_token", x => x.Id); + table.ForeignKey( + name: "FK_user_refresh_token_user_UserId", + column: x => x.UserId, + principalTable: "user", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }) + .Annotation("MySql:CharSet", "utf8mb4"); + + migrationBuilder.CreateTable( + name: "user_role", + columns: table => new + { + UserId = table.Column(type: "bigint", nullable: false), + RoleId = table.Column(type: "char(36)", nullable: false, collation: "ascii_general_ci"), + RoleName = table.Column(type: "varchar(50)", maxLength: 50, nullable: false) + .Annotation("MySql:CharSet", "utf8mb4") + }, + constraints: table => + { + table.PrimaryKey("PK_user_role", x => new { x.UserId, x.RoleId }); + table.ForeignKey( + name: "FK_user_role_user_UserId", + column: x => x.UserId, + principalTable: "user", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }) + .Annotation("MySql:CharSet", "utf8mb4"); + + migrationBuilder.CreateIndex( + name: "IX_ExpiresAt_StatusName", + table: "CAPPublishedMessage", + columns: new[] { "ExpiresAt", "StatusName" }); + + migrationBuilder.CreateIndex( + name: "IX_Version_ExpiresAt_StatusName", + table: "CAPPublishedMessage", + columns: new[] { "Version", "ExpiresAt", "StatusName" }); + + migrationBuilder.CreateIndex( + name: "IX_ExpiresAt_StatusName1", + table: "CAPReceivedMessage", + columns: new[] { "ExpiresAt", "StatusName" }); + + migrationBuilder.CreateIndex( + name: "IX_Version_ExpiresAt_StatusName1", + table: "CAPReceivedMessage", + columns: new[] { "Version", "ExpiresAt", "StatusName" }); + + migrationBuilder.CreateIndex( + name: "IX_dept_IsDeleted", + table: "dept", + column: "IsDeleted"); + + migrationBuilder.CreateIndex( + name: "IX_dept_ParentId", + table: "dept", + column: "ParentId"); + + migrationBuilder.CreateIndex( + name: "IX_dept_Status", + table: "dept", + column: "Status"); + + migrationBuilder.CreateIndex( + name: "IX_role_Name", + table: "role", + column: "Name", + unique: true); + + migrationBuilder.CreateIndex( + name: "IX_user_Email", + table: "user", + column: "Email"); + + migrationBuilder.CreateIndex( + name: "IX_user_Name", + table: "user", + column: "Name"); + + migrationBuilder.CreateIndex( + name: "IX_user_dept_DeptId", + table: "user_dept", + column: "DeptId"); + + migrationBuilder.CreateIndex( + name: "IX_user_dept_UserId", + table: "user_dept", + column: "UserId"); + + migrationBuilder.CreateIndex( + name: "IX_user_refresh_token_UserId", + table: "user_refresh_token", + column: "UserId"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "CAPLock"); + + migrationBuilder.DropTable( + name: "CAPPublishedMessage"); + + migrationBuilder.DropTable( + name: "CAPReceivedMessage"); + + migrationBuilder.DropTable( + name: "dept"); + + migrationBuilder.DropTable( + name: "role_permission"); + + migrationBuilder.DropTable( + name: "user_dept"); + + migrationBuilder.DropTable( + name: "user_refresh_token"); + + migrationBuilder.DropTable( + name: "user_role"); + + migrationBuilder.DropTable( + name: "role"); + + migrationBuilder.DropTable( + name: "user"); + } + } +} diff --git a/template/src/ABC.Template.Infrastructure/MigrationsAll/MySql-net10.0-admin/ApplicationDbContextModelSnapshot.cs b/template/src/ABC.Template.Infrastructure/MigrationsAll/MySql-net10.0-admin/ApplicationDbContextModelSnapshot.cs new file mode 100644 index 00000000..f0c1ec88 --- /dev/null +++ b/template/src/ABC.Template.Infrastructure/MigrationsAll/MySql-net10.0-admin/ApplicationDbContextModelSnapshot.cs @@ -0,0 +1,437 @@ +// +using System; +using ABC.Template.Infrastructure; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace ABC.Template.Infrastructure.Migrations +{ + [DbContext(typeof(ApplicationDbContext))] + partial class ApplicationDbContextModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "9.0.0") + .HasAnnotation("Relational:MaxIdentifierLength", 64); + + MySqlModelBuilderExtensions.AutoIncrementColumns(modelBuilder); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.DeptAggregate.Dept", b => + { + b.Property("Id") + .HasColumnType("bigint"); + + b.Property("CreatedAt") + .HasColumnType("datetime(6)"); + + b.Property("DeletedAt") + .HasColumnType("datetime(6)"); + + b.Property("IsDeleted") + .HasColumnType("tinyint(1)"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("varchar(100)"); + + b.Property("ParentId") + .HasColumnType("bigint"); + + b.Property("Remark") + .IsRequired() + .HasMaxLength(500) + .HasColumnType("varchar(500)"); + + b.Property("Status") + .HasColumnType("int"); + + b.Property("UpdateTime") + .HasColumnType("datetime(6)"); + + b.HasKey("Id"); + + b.HasIndex("IsDeleted"); + + b.HasIndex("ParentId"); + + b.HasIndex("Status"); + + b.ToTable("dept", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.Role", b => + { + b.Property("Id") + .HasColumnType("char(36)"); + + b.Property("CreatedAt") + .HasColumnType("datetime(6)"); + + b.Property("DeletedAt") + .HasColumnType("datetime(6)"); + + b.Property("Description") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("varchar(200)"); + + b.Property("IsActive") + .HasColumnType("tinyint(1)"); + + b.Property("IsDeleted") + .HasColumnType("tinyint(1)"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("varchar(50)"); + + b.HasKey("Id"); + + b.HasIndex("Name") + .IsUnique(); + + b.ToTable("role", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.RolePermission", b => + { + b.Property("RoleId") + .HasColumnType("char(36)"); + + b.Property("PermissionCode") + .HasMaxLength(100) + .HasColumnType("varchar(100)"); + + b.Property("PermissionDescription") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("varchar(200)"); + + b.Property("PermissionName") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("varchar(100)"); + + b.HasKey("RoleId", "PermissionCode"); + + b.ToTable("role_permission", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.User", b => + { + b.Property("Id") + .HasColumnType("bigint"); + + b.Property("Age") + .HasColumnType("int"); + + b.Property("BirthDate") + .HasColumnType("datetime(6)"); + + b.Property("CreatedAt") + .HasColumnType("datetime(6)"); + + b.Property("DeletedAt") + .HasColumnType("datetime(6)"); + + b.Property("Email") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("varchar(100)"); + + b.Property("Gender") + .IsRequired() + .HasMaxLength(10) + .HasColumnType("varchar(10)"); + + b.Property("IsActive") + .HasColumnType("tinyint(1)"); + + b.Property("IsDeleted") + .HasColumnType("tinyint(1)"); + + b.Property("LastLoginTime") + .HasColumnType("datetime(6)"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("varchar(50)"); + + b.Property("PasswordHash") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("varchar(255)"); + + b.Property("Phone") + .IsRequired() + .HasMaxLength(20) + .HasColumnType("varchar(20)"); + + b.Property("RealName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("varchar(50)"); + + b.Property("Status") + .HasColumnType("int"); + + b.Property("UpdateTime") + .HasColumnType("datetime(6)"); + + b.HasKey("Id"); + + b.HasIndex("Email"); + + b.HasIndex("Name"); + + b.ToTable("user", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserDept", b => + { + b.Property("UserId") + .HasColumnType("bigint"); + + b.Property("AssignedAt") + .HasColumnType("datetime(6)"); + + b.Property("DeptId") + .HasColumnType("bigint"); + + b.Property("DeptName") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("varchar(100)"); + + b.HasKey("UserId"); + + b.HasIndex("DeptId"); + + b.HasIndex("UserId"); + + b.ToTable("user_dept", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRefreshToken", b => + { + b.Property("Id") + .HasColumnType("bigint"); + + b.Property("CreatedTime") + .HasColumnType("datetime(6)"); + + b.Property("ExpiresTime") + .HasColumnType("datetime(6)"); + + b.Property("IsRevoked") + .HasColumnType("tinyint(1)"); + + b.Property("IsUsed") + .HasColumnType("tinyint(1)"); + + b.Property("Token") + .IsRequired() + .HasMaxLength(500) + .HasColumnType("varchar(500)"); + + b.Property("UserId") + .HasColumnType("bigint"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("user_refresh_token", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRole", b => + { + b.Property("UserId") + .HasColumnType("bigint"); + + b.Property("RoleId") + .HasColumnType("char(36)"); + + b.Property("RoleName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("varchar(50)"); + + b.HasKey("UserId", "RoleId"); + + b.ToTable("user_role", (string)null); + }); + + modelBuilder.Entity("NetCorePal.Extensions.DistributedTransactions.CAP.Persistence.CapLock", b => + { + b.Property("Key") + .HasMaxLength(128) + .HasColumnType("varchar(128)"); + + b.Property("Instance") + .HasMaxLength(256) + .HasColumnType("varchar"); + + b.Property("LastLockTime") + .HasColumnType("DATETIME(6)"); + + b.HasKey("Key"); + + b.ToTable("CAPLock", (string)null); + }); + + modelBuilder.Entity("NetCorePal.Extensions.DistributedTransactions.CAP.Persistence.PublishedMessage", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property("Id")); + + b.Property("Added") + .HasColumnType("DATETIME(6)"); + + b.Property("Content") + .HasColumnType("longtext"); + + b.Property("ExpiresAt") + .HasColumnType("DATETIME(6)"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("varchar(200)"); + + b.Property("Retries") + .HasColumnType("int"); + + b.Property("StatusName") + .IsRequired() + .HasMaxLength(40) + .HasColumnType("varchar(40)"); + + b.Property("Version") + .HasMaxLength(20) + .HasColumnType("varchar(20)"); + + b.HasKey("Id"); + + b.HasIndex(new[] { "ExpiresAt", "StatusName" }, "IX_ExpiresAt_StatusName"); + + b.HasIndex(new[] { "Version", "ExpiresAt", "StatusName" }, "IX_Version_ExpiresAt_StatusName"); + + b.ToTable("CAPPublishedMessage", (string)null); + }); + + modelBuilder.Entity("NetCorePal.Extensions.DistributedTransactions.CAP.Persistence.ReceivedMessage", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property("Id")); + + b.Property("Added") + .HasColumnType("DATETIME(6)"); + + b.Property("Content") + .HasColumnType("longtext"); + + b.Property("ExpiresAt") + .HasColumnType("DATETIME(6)"); + + b.Property("Group") + .HasMaxLength(200) + .HasColumnType("varchar(200)"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(400) + .HasColumnType("varchar(400)"); + + b.Property("Retries") + .HasColumnType("int"); + + b.Property("StatusName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("varchar(50)"); + + b.Property("Version") + .HasMaxLength(20) + .HasColumnType("varchar(20)"); + + b.HasKey("Id"); + + b.HasIndex(new[] { "ExpiresAt", "StatusName" }, "IX_ExpiresAt_StatusName") + .HasDatabaseName("IX_ExpiresAt_StatusName1"); + + b.HasIndex(new[] { "Version", "ExpiresAt", "StatusName" }, "IX_Version_ExpiresAt_StatusName") + .HasDatabaseName("IX_Version_ExpiresAt_StatusName1"); + + b.ToTable("CAPReceivedMessage", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.RolePermission", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.RoleAggregate.Role", null) + .WithMany("Permissions") + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserDept", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.UserAggregate.User", null) + .WithOne("Dept") + .HasForeignKey("ABC.Template.Domain.AggregatesModel.UserAggregate.UserDept", "UserId") + .OnDelete(DeleteBehavior.ClientCascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRefreshToken", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.UserAggregate.User", null) + .WithMany("RefreshTokens") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRole", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.UserAggregate.User", null) + .WithMany("Roles") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.Role", b => + { + b.Navigation("Permissions"); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.User", b => + { + b.Navigation("Dept") + .IsRequired(); + + b.Navigation("RefreshTokens"); + + b.Navigation("Roles"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/template/src/ABC.Template.Infrastructure/MigrationsAll/MySql-net9.0/20251225064958_Init.Designer.cs b/template/src/ABC.Template.Infrastructure/MigrationsAll/MySql-net10.0/20260122054453_Init.Designer.cs similarity index 78% rename from template/src/ABC.Template.Infrastructure/MigrationsAll/MySql-net9.0/20251225064958_Init.Designer.cs rename to template/src/ABC.Template.Infrastructure/MigrationsAll/MySql-net10.0/20260122054453_Init.Designer.cs index 79d9fd5e..f68394cf 100644 --- a/template/src/ABC.Template.Infrastructure/MigrationsAll/MySql-net9.0/20251225064958_Init.Designer.cs +++ b/template/src/ABC.Template.Infrastructure/MigrationsAll/MySql-net10.0/20260122054453_Init.Designer.cs @@ -1,18 +1,18 @@ // using System; +using ABC.Template.Infrastructure; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using ABC.Template.Infrastructure; #nullable disable namespace ABC.Template.Infrastructure.Migrations { [DbContext(typeof(ApplicationDbContext))] - [Migration("20251225064958_Init")] + [Migration("20260122054453_Init")] partial class Init { /// @@ -134,47 +134,6 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.ToTable("CAPReceivedMessage", (string)null); }); - - modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.DeliverAggregate.DeliverRecord", b => - { - b.Property("Id") - .HasColumnType("char(36)"); - - b.Property("OrderId") - .HasColumnType("char(36)"); - - b.HasKey("Id"); - - b.ToTable("deliverrecord", (string)null); - }); - - modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.OrderAggregate.Order", b => - { - b.Property("Id") - .HasColumnType("char(36)"); - - b.Property("Count") - .HasColumnType("int"); - - b.Property("Name") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("varchar(100)"); - - b.Property("Paid") - .HasColumnType("tinyint(1)"); - - b.Property("RowVersion") - .IsConcurrencyToken() - .HasColumnType("int"); - - b.Property("UpdateTime") - .HasColumnType("datetime(6)"); - - b.HasKey("Id"); - - b.ToTable("order", (string)null); - }); #pragma warning restore 612, 618 } } diff --git a/template/src/ABC.Template.Infrastructure/MigrationsAll/MySql-net8.0/20251225064948_Init.cs b/template/src/ABC.Template.Infrastructure/MigrationsAll/MySql-net10.0/20260122054453_Init.cs similarity index 76% rename from template/src/ABC.Template.Infrastructure/MigrationsAll/MySql-net8.0/20251225064948_Init.cs rename to template/src/ABC.Template.Infrastructure/MigrationsAll/MySql-net10.0/20260122054453_Init.cs index dc3a6e74..cab54e92 100644 --- a/template/src/ABC.Template.Infrastructure/MigrationsAll/MySql-net8.0/20251225064948_Init.cs +++ b/template/src/ABC.Template.Infrastructure/MigrationsAll/MySql-net10.0/20260122054453_Init.cs @@ -81,37 +81,6 @@ protected override void Up(MigrationBuilder migrationBuilder) }) .Annotation("MySql:CharSet", "utf8mb4"); - migrationBuilder.CreateTable( - name: "deliverrecord", - columns: table => new - { - Id = table.Column(type: "char(36)", nullable: false, collation: "ascii_general_ci"), - OrderId = table.Column(type: "char(36)", nullable: false, collation: "ascii_general_ci") - }, - constraints: table => - { - table.PrimaryKey("PK_deliverrecord", x => x.Id); - }) - .Annotation("MySql:CharSet", "utf8mb4"); - - migrationBuilder.CreateTable( - name: "order", - columns: table => new - { - Id = table.Column(type: "char(36)", nullable: false, collation: "ascii_general_ci"), - Paid = table.Column(type: "tinyint(1)", nullable: false), - Name = table.Column(type: "varchar(100)", maxLength: 100, nullable: false) - .Annotation("MySql:CharSet", "utf8mb4"), - Count = table.Column(type: "int", nullable: false), - RowVersion = table.Column(type: "int", nullable: false), - UpdateTime = table.Column(type: "datetime(6)", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_order", x => x.Id); - }) - .Annotation("MySql:CharSet", "utf8mb4"); - migrationBuilder.CreateIndex( name: "IX_ExpiresAt_StatusName", table: "CAPPublishedMessage", @@ -144,12 +113,6 @@ protected override void Down(MigrationBuilder migrationBuilder) migrationBuilder.DropTable( name: "CAPReceivedMessage"); - - migrationBuilder.DropTable( - name: "deliverrecord"); - - migrationBuilder.DropTable( - name: "order"); } } } diff --git a/template/src/ABC.Template.Infrastructure/MigrationsAll/MySql-net10.0/ApplicationDbContextModelSnapshot.cs b/template/src/ABC.Template.Infrastructure/MigrationsAll/MySql-net10.0/ApplicationDbContextModelSnapshot.cs index 99305034..b80e31bf 100644 --- a/template/src/ABC.Template.Infrastructure/MigrationsAll/MySql-net10.0/ApplicationDbContextModelSnapshot.cs +++ b/template/src/ABC.Template.Infrastructure/MigrationsAll/MySql-net10.0/ApplicationDbContextModelSnapshot.cs @@ -1,10 +1,10 @@ // using System; +using ABC.Template.Infrastructure; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using ABC.Template.Infrastructure; #nullable disable @@ -131,47 +131,6 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.ToTable("CAPReceivedMessage", (string)null); }); - - modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.DeliverAggregate.DeliverRecord", b => - { - b.Property("Id") - .HasColumnType("char(36)"); - - b.Property("OrderId") - .HasColumnType("char(36)"); - - b.HasKey("Id"); - - b.ToTable("deliverrecord", (string)null); - }); - - modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.OrderAggregate.Order", b => - { - b.Property("Id") - .HasColumnType("char(36)"); - - b.Property("Count") - .HasColumnType("int"); - - b.Property("Name") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("varchar(100)"); - - b.Property("Paid") - .HasColumnType("tinyint(1)"); - - b.Property("RowVersion") - .IsConcurrencyToken() - .HasColumnType("int"); - - b.Property("UpdateTime") - .HasColumnType("datetime(6)"); - - b.HasKey("Id"); - - b.ToTable("order", (string)null); - }); #pragma warning restore 612, 618 } } diff --git a/template/src/ABC.Template.Infrastructure/MigrationsAll/MySql-net8.0-admin/20260122054417_Init.Designer.cs b/template/src/ABC.Template.Infrastructure/MigrationsAll/MySql-net8.0-admin/20260122054417_Init.Designer.cs new file mode 100644 index 00000000..aa269430 --- /dev/null +++ b/template/src/ABC.Template.Infrastructure/MigrationsAll/MySql-net8.0-admin/20260122054417_Init.Designer.cs @@ -0,0 +1,433 @@ +// +using System; +using ABC.Template.Infrastructure; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace ABC.Template.Infrastructure.Migrations +{ + [DbContext(typeof(ApplicationDbContext))] + [Migration("20260122054417_Init")] + partial class Init + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "8.0.10") + .HasAnnotation("Relational:MaxIdentifierLength", 64); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.DeptAggregate.Dept", b => + { + b.Property("Id") + .HasColumnType("bigint"); + + b.Property("CreatedAt") + .HasColumnType("datetime(6)"); + + b.Property("DeletedAt") + .HasColumnType("datetime(6)"); + + b.Property("IsDeleted") + .HasColumnType("tinyint(1)"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("varchar(100)"); + + b.Property("ParentId") + .HasColumnType("bigint"); + + b.Property("Remark") + .IsRequired() + .HasMaxLength(500) + .HasColumnType("varchar(500)"); + + b.Property("Status") + .HasColumnType("int"); + + b.Property("UpdateTime") + .HasColumnType("datetime(6)"); + + b.HasKey("Id"); + + b.HasIndex("IsDeleted"); + + b.HasIndex("ParentId"); + + b.HasIndex("Status"); + + b.ToTable("dept", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.Role", b => + { + b.Property("Id") + .HasColumnType("char(36)"); + + b.Property("CreatedAt") + .HasColumnType("datetime(6)"); + + b.Property("DeletedAt") + .HasColumnType("datetime(6)"); + + b.Property("Description") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("varchar(200)"); + + b.Property("IsActive") + .HasColumnType("tinyint(1)"); + + b.Property("IsDeleted") + .HasColumnType("tinyint(1)"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("varchar(50)"); + + b.HasKey("Id"); + + b.HasIndex("Name") + .IsUnique(); + + b.ToTable("role", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.RolePermission", b => + { + b.Property("RoleId") + .HasColumnType("char(36)"); + + b.Property("PermissionCode") + .HasMaxLength(100) + .HasColumnType("varchar(100)"); + + b.Property("PermissionDescription") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("varchar(200)"); + + b.Property("PermissionName") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("varchar(100)"); + + b.HasKey("RoleId", "PermissionCode"); + + b.ToTable("role_permission", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.User", b => + { + b.Property("Id") + .HasColumnType("bigint"); + + b.Property("Age") + .HasColumnType("int"); + + b.Property("BirthDate") + .HasColumnType("datetime(6)"); + + b.Property("CreatedAt") + .HasColumnType("datetime(6)"); + + b.Property("DeletedAt") + .HasColumnType("datetime(6)"); + + b.Property("Email") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("varchar(100)"); + + b.Property("Gender") + .IsRequired() + .HasMaxLength(10) + .HasColumnType("varchar(10)"); + + b.Property("IsActive") + .HasColumnType("tinyint(1)"); + + b.Property("IsDeleted") + .HasColumnType("tinyint(1)"); + + b.Property("LastLoginTime") + .HasColumnType("datetime(6)"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("varchar(50)"); + + b.Property("PasswordHash") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("varchar(255)"); + + b.Property("Phone") + .IsRequired() + .HasMaxLength(20) + .HasColumnType("varchar(20)"); + + b.Property("RealName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("varchar(50)"); + + b.Property("Status") + .HasColumnType("int"); + + b.Property("UpdateTime") + .HasColumnType("datetime(6)"); + + b.HasKey("Id"); + + b.HasIndex("Email"); + + b.HasIndex("Name"); + + b.ToTable("user", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserDept", b => + { + b.Property("UserId") + .HasColumnType("bigint"); + + b.Property("AssignedAt") + .HasColumnType("datetime(6)"); + + b.Property("DeptId") + .HasColumnType("bigint"); + + b.Property("DeptName") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("varchar(100)"); + + b.HasKey("UserId"); + + b.HasIndex("DeptId"); + + b.HasIndex("UserId"); + + b.ToTable("user_dept", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRefreshToken", b => + { + b.Property("Id") + .HasColumnType("bigint"); + + b.Property("CreatedTime") + .HasColumnType("datetime(6)"); + + b.Property("ExpiresTime") + .HasColumnType("datetime(6)"); + + b.Property("IsRevoked") + .HasColumnType("tinyint(1)"); + + b.Property("IsUsed") + .HasColumnType("tinyint(1)"); + + b.Property("Token") + .IsRequired() + .HasMaxLength(500) + .HasColumnType("varchar(500)"); + + b.Property("UserId") + .HasColumnType("bigint"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("user_refresh_token", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRole", b => + { + b.Property("UserId") + .HasColumnType("bigint"); + + b.Property("RoleId") + .HasColumnType("char(36)"); + + b.Property("RoleName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("varchar(50)"); + + b.HasKey("UserId", "RoleId"); + + b.ToTable("user_role", (string)null); + }); + + modelBuilder.Entity("NetCorePal.Extensions.DistributedTransactions.CAP.Persistence.CapLock", b => + { + b.Property("Key") + .HasMaxLength(128) + .HasColumnType("varchar(128)"); + + b.Property("Instance") + .HasMaxLength(256) + .HasColumnType("varchar"); + + b.Property("LastLockTime") + .HasColumnType("DATETIME(6)"); + + b.HasKey("Key"); + + b.ToTable("CAPLock", (string)null); + }); + + modelBuilder.Entity("NetCorePal.Extensions.DistributedTransactions.CAP.Persistence.PublishedMessage", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + b.Property("Added") + .HasColumnType("DATETIME(6)"); + + b.Property("Content") + .HasColumnType("longtext"); + + b.Property("ExpiresAt") + .HasColumnType("DATETIME(6)"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("varchar(200)"); + + b.Property("Retries") + .HasColumnType("int"); + + b.Property("StatusName") + .IsRequired() + .HasMaxLength(40) + .HasColumnType("varchar(40)"); + + b.Property("Version") + .HasMaxLength(20) + .HasColumnType("varchar(20)"); + + b.HasKey("Id"); + + b.HasIndex(new[] { "ExpiresAt", "StatusName" }, "IX_ExpiresAt_StatusName"); + + b.HasIndex(new[] { "Version", "ExpiresAt", "StatusName" }, "IX_Version_ExpiresAt_StatusName"); + + b.ToTable("CAPPublishedMessage", (string)null); + }); + + modelBuilder.Entity("NetCorePal.Extensions.DistributedTransactions.CAP.Persistence.ReceivedMessage", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + b.Property("Added") + .HasColumnType("DATETIME(6)"); + + b.Property("Content") + .HasColumnType("longtext"); + + b.Property("ExpiresAt") + .HasColumnType("DATETIME(6)"); + + b.Property("Group") + .HasMaxLength(200) + .HasColumnType("varchar(200)"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(400) + .HasColumnType("varchar(400)"); + + b.Property("Retries") + .HasColumnType("int"); + + b.Property("StatusName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("varchar(50)"); + + b.Property("Version") + .HasMaxLength(20) + .HasColumnType("varchar(20)"); + + b.HasKey("Id"); + + b.HasIndex(new[] { "ExpiresAt", "StatusName" }, "IX_ExpiresAt_StatusName") + .HasDatabaseName("IX_ExpiresAt_StatusName1"); + + b.HasIndex(new[] { "Version", "ExpiresAt", "StatusName" }, "IX_Version_ExpiresAt_StatusName") + .HasDatabaseName("IX_Version_ExpiresAt_StatusName1"); + + b.ToTable("CAPReceivedMessage", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.RolePermission", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.RoleAggregate.Role", null) + .WithMany("Permissions") + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserDept", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.UserAggregate.User", null) + .WithOne("Dept") + .HasForeignKey("ABC.Template.Domain.AggregatesModel.UserAggregate.UserDept", "UserId") + .OnDelete(DeleteBehavior.ClientCascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRefreshToken", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.UserAggregate.User", null) + .WithMany("RefreshTokens") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRole", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.UserAggregate.User", null) + .WithMany("Roles") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.Role", b => + { + b.Navigation("Permissions"); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.User", b => + { + b.Navigation("Dept") + .IsRequired(); + + b.Navigation("RefreshTokens"); + + b.Navigation("Roles"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/template/src/ABC.Template.Infrastructure/MigrationsAll/MySql-net8.0-admin/20260122054417_Init.cs b/template/src/ABC.Template.Infrastructure/MigrationsAll/MySql-net8.0-admin/20260122054417_Init.cs new file mode 100644 index 00000000..290bfee7 --- /dev/null +++ b/template/src/ABC.Template.Infrastructure/MigrationsAll/MySql-net8.0-admin/20260122054417_Init.cs @@ -0,0 +1,351 @@ +using System; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace ABC.Template.Infrastructure.Migrations +{ + /// + public partial class Init : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AlterDatabase() + .Annotation("MySql:CharSet", "utf8mb4"); + + migrationBuilder.CreateTable( + name: "CAPLock", + columns: table => new + { + Key = table.Column(type: "varchar(128)", maxLength: 128, nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + Instance = table.Column(type: "varchar(256)", maxLength: 256, nullable: true) + .Annotation("MySql:CharSet", "utf8mb4"), + LastLockTime = table.Column(type: "DATETIME(6)", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_CAPLock", x => x.Key); + }) + .Annotation("MySql:CharSet", "utf8mb4"); + + migrationBuilder.CreateTable( + name: "CAPPublishedMessage", + columns: table => new + { + Id = table.Column(type: "bigint", nullable: false) + .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), + Version = table.Column(type: "varchar(20)", maxLength: 20, nullable: true) + .Annotation("MySql:CharSet", "utf8mb4"), + Name = table.Column(type: "varchar(200)", maxLength: 200, nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + Content = table.Column(type: "longtext", nullable: true) + .Annotation("MySql:CharSet", "utf8mb4"), + Retries = table.Column(type: "int", nullable: true), + Added = table.Column(type: "DATETIME(6)", nullable: false), + ExpiresAt = table.Column(type: "DATETIME(6)", nullable: true), + StatusName = table.Column(type: "varchar(40)", maxLength: 40, nullable: false) + .Annotation("MySql:CharSet", "utf8mb4") + }, + constraints: table => + { + table.PrimaryKey("PK_CAPPublishedMessage", x => x.Id); + }) + .Annotation("MySql:CharSet", "utf8mb4"); + + migrationBuilder.CreateTable( + name: "CAPReceivedMessage", + columns: table => new + { + Id = table.Column(type: "bigint", nullable: false) + .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), + Version = table.Column(type: "varchar(20)", maxLength: 20, nullable: true) + .Annotation("MySql:CharSet", "utf8mb4"), + Name = table.Column(type: "varchar(400)", maxLength: 400, nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + Group = table.Column(type: "varchar(200)", maxLength: 200, nullable: true) + .Annotation("MySql:CharSet", "utf8mb4"), + Content = table.Column(type: "longtext", nullable: true) + .Annotation("MySql:CharSet", "utf8mb4"), + Retries = table.Column(type: "int", nullable: true), + Added = table.Column(type: "DATETIME(6)", nullable: false), + ExpiresAt = table.Column(type: "DATETIME(6)", nullable: true), + StatusName = table.Column(type: "varchar(50)", maxLength: 50, nullable: false) + .Annotation("MySql:CharSet", "utf8mb4") + }, + constraints: table => + { + table.PrimaryKey("PK_CAPReceivedMessage", x => x.Id); + }) + .Annotation("MySql:CharSet", "utf8mb4"); + + migrationBuilder.CreateTable( + name: "dept", + columns: table => new + { + Id = table.Column(type: "bigint", nullable: false), + Name = table.Column(type: "varchar(100)", maxLength: 100, nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + Remark = table.Column(type: "varchar(500)", maxLength: 500, nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + ParentId = table.Column(type: "bigint", nullable: false), + Status = table.Column(type: "int", nullable: false), + CreatedAt = table.Column(type: "datetime(6)", nullable: false), + IsDeleted = table.Column(type: "tinyint(1)", nullable: false), + DeletedAt = table.Column(type: "datetime(6)", nullable: false), + UpdateTime = table.Column(type: "datetime(6)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_dept", x => x.Id); + }) + .Annotation("MySql:CharSet", "utf8mb4"); + + migrationBuilder.CreateTable( + name: "role", + columns: table => new + { + Id = table.Column(type: "char(36)", nullable: false, collation: "ascii_general_ci"), + Name = table.Column(type: "varchar(50)", maxLength: 50, nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + Description = table.Column(type: "varchar(200)", maxLength: 200, nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + CreatedAt = table.Column(type: "datetime(6)", nullable: false), + IsActive = table.Column(type: "tinyint(1)", nullable: false), + IsDeleted = table.Column(type: "tinyint(1)", nullable: false), + DeletedAt = table.Column(type: "datetime(6)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_role", x => x.Id); + }) + .Annotation("MySql:CharSet", "utf8mb4"); + + migrationBuilder.CreateTable( + name: "user", + columns: table => new + { + Id = table.Column(type: "bigint", nullable: false), + Name = table.Column(type: "varchar(50)", maxLength: 50, nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + Email = table.Column(type: "varchar(100)", maxLength: 100, nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + Phone = table.Column(type: "varchar(20)", maxLength: 20, nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + RealName = table.Column(type: "varchar(50)", maxLength: 50, nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + Status = table.Column(type: "int", nullable: false), + PasswordHash = table.Column(type: "varchar(255)", maxLength: 255, nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + IsActive = table.Column(type: "tinyint(1)", nullable: false), + CreatedAt = table.Column(type: "datetime(6)", nullable: false), + LastLoginTime = table.Column(type: "datetime(6)", nullable: true), + UpdateTime = table.Column(type: "datetime(6)", nullable: false), + IsDeleted = table.Column(type: "tinyint(1)", nullable: false), + DeletedAt = table.Column(type: "datetime(6)", nullable: false), + Gender = table.Column(type: "varchar(10)", maxLength: 10, nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + Age = table.Column(type: "int", nullable: false), + BirthDate = table.Column(type: "datetime(6)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_user", x => x.Id); + }) + .Annotation("MySql:CharSet", "utf8mb4"); + + migrationBuilder.CreateTable( + name: "role_permission", + columns: table => new + { + RoleId = table.Column(type: "char(36)", nullable: false, collation: "ascii_general_ci"), + PermissionCode = table.Column(type: "varchar(100)", maxLength: 100, nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + PermissionName = table.Column(type: "varchar(100)", maxLength: 100, nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + PermissionDescription = table.Column(type: "varchar(200)", maxLength: 200, nullable: false) + .Annotation("MySql:CharSet", "utf8mb4") + }, + constraints: table => + { + table.PrimaryKey("PK_role_permission", x => new { x.RoleId, x.PermissionCode }); + table.ForeignKey( + name: "FK_role_permission_role_RoleId", + column: x => x.RoleId, + principalTable: "role", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }) + .Annotation("MySql:CharSet", "utf8mb4"); + + migrationBuilder.CreateTable( + name: "user_dept", + columns: table => new + { + UserId = table.Column(type: "bigint", nullable: false), + DeptId = table.Column(type: "bigint", nullable: false), + DeptName = table.Column(type: "varchar(100)", maxLength: 100, nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + AssignedAt = table.Column(type: "datetime(6)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_user_dept", x => x.UserId); + table.ForeignKey( + name: "FK_user_dept_user_UserId", + column: x => x.UserId, + principalTable: "user", + principalColumn: "Id"); + }) + .Annotation("MySql:CharSet", "utf8mb4"); + + migrationBuilder.CreateTable( + name: "user_refresh_token", + columns: table => new + { + Id = table.Column(type: "bigint", nullable: false), + UserId = table.Column(type: "bigint", nullable: false), + Token = table.Column(type: "varchar(500)", maxLength: 500, nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + CreatedTime = table.Column(type: "datetime(6)", nullable: false), + ExpiresTime = table.Column(type: "datetime(6)", nullable: false), + IsUsed = table.Column(type: "tinyint(1)", nullable: false), + IsRevoked = table.Column(type: "tinyint(1)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_user_refresh_token", x => x.Id); + table.ForeignKey( + name: "FK_user_refresh_token_user_UserId", + column: x => x.UserId, + principalTable: "user", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }) + .Annotation("MySql:CharSet", "utf8mb4"); + + migrationBuilder.CreateTable( + name: "user_role", + columns: table => new + { + UserId = table.Column(type: "bigint", nullable: false), + RoleId = table.Column(type: "char(36)", nullable: false, collation: "ascii_general_ci"), + RoleName = table.Column(type: "varchar(50)", maxLength: 50, nullable: false) + .Annotation("MySql:CharSet", "utf8mb4") + }, + constraints: table => + { + table.PrimaryKey("PK_user_role", x => new { x.UserId, x.RoleId }); + table.ForeignKey( + name: "FK_user_role_user_UserId", + column: x => x.UserId, + principalTable: "user", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }) + .Annotation("MySql:CharSet", "utf8mb4"); + + migrationBuilder.CreateIndex( + name: "IX_ExpiresAt_StatusName", + table: "CAPPublishedMessage", + columns: new[] { "ExpiresAt", "StatusName" }); + + migrationBuilder.CreateIndex( + name: "IX_Version_ExpiresAt_StatusName", + table: "CAPPublishedMessage", + columns: new[] { "Version", "ExpiresAt", "StatusName" }); + + migrationBuilder.CreateIndex( + name: "IX_ExpiresAt_StatusName1", + table: "CAPReceivedMessage", + columns: new[] { "ExpiresAt", "StatusName" }); + + migrationBuilder.CreateIndex( + name: "IX_Version_ExpiresAt_StatusName1", + table: "CAPReceivedMessage", + columns: new[] { "Version", "ExpiresAt", "StatusName" }); + + migrationBuilder.CreateIndex( + name: "IX_dept_IsDeleted", + table: "dept", + column: "IsDeleted"); + + migrationBuilder.CreateIndex( + name: "IX_dept_ParentId", + table: "dept", + column: "ParentId"); + + migrationBuilder.CreateIndex( + name: "IX_dept_Status", + table: "dept", + column: "Status"); + + migrationBuilder.CreateIndex( + name: "IX_role_Name", + table: "role", + column: "Name", + unique: true); + + migrationBuilder.CreateIndex( + name: "IX_user_Email", + table: "user", + column: "Email"); + + migrationBuilder.CreateIndex( + name: "IX_user_Name", + table: "user", + column: "Name"); + + migrationBuilder.CreateIndex( + name: "IX_user_dept_DeptId", + table: "user_dept", + column: "DeptId"); + + migrationBuilder.CreateIndex( + name: "IX_user_dept_UserId", + table: "user_dept", + column: "UserId"); + + migrationBuilder.CreateIndex( + name: "IX_user_refresh_token_UserId", + table: "user_refresh_token", + column: "UserId"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "CAPLock"); + + migrationBuilder.DropTable( + name: "CAPPublishedMessage"); + + migrationBuilder.DropTable( + name: "CAPReceivedMessage"); + + migrationBuilder.DropTable( + name: "dept"); + + migrationBuilder.DropTable( + name: "role_permission"); + + migrationBuilder.DropTable( + name: "user_dept"); + + migrationBuilder.DropTable( + name: "user_refresh_token"); + + migrationBuilder.DropTable( + name: "user_role"); + + migrationBuilder.DropTable( + name: "role"); + + migrationBuilder.DropTable( + name: "user"); + } + } +} diff --git a/template/src/ABC.Template.Infrastructure/MigrationsAll/MySql-net8.0-admin/ApplicationDbContextModelSnapshot.cs b/template/src/ABC.Template.Infrastructure/MigrationsAll/MySql-net8.0-admin/ApplicationDbContextModelSnapshot.cs new file mode 100644 index 00000000..1933da2d --- /dev/null +++ b/template/src/ABC.Template.Infrastructure/MigrationsAll/MySql-net8.0-admin/ApplicationDbContextModelSnapshot.cs @@ -0,0 +1,430 @@ +// +using System; +using ABC.Template.Infrastructure; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace ABC.Template.Infrastructure.Migrations +{ + [DbContext(typeof(ApplicationDbContext))] + partial class ApplicationDbContextModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "8.0.10") + .HasAnnotation("Relational:MaxIdentifierLength", 64); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.DeptAggregate.Dept", b => + { + b.Property("Id") + .HasColumnType("bigint"); + + b.Property("CreatedAt") + .HasColumnType("datetime(6)"); + + b.Property("DeletedAt") + .HasColumnType("datetime(6)"); + + b.Property("IsDeleted") + .HasColumnType("tinyint(1)"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("varchar(100)"); + + b.Property("ParentId") + .HasColumnType("bigint"); + + b.Property("Remark") + .IsRequired() + .HasMaxLength(500) + .HasColumnType("varchar(500)"); + + b.Property("Status") + .HasColumnType("int"); + + b.Property("UpdateTime") + .HasColumnType("datetime(6)"); + + b.HasKey("Id"); + + b.HasIndex("IsDeleted"); + + b.HasIndex("ParentId"); + + b.HasIndex("Status"); + + b.ToTable("dept", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.Role", b => + { + b.Property("Id") + .HasColumnType("char(36)"); + + b.Property("CreatedAt") + .HasColumnType("datetime(6)"); + + b.Property("DeletedAt") + .HasColumnType("datetime(6)"); + + b.Property("Description") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("varchar(200)"); + + b.Property("IsActive") + .HasColumnType("tinyint(1)"); + + b.Property("IsDeleted") + .HasColumnType("tinyint(1)"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("varchar(50)"); + + b.HasKey("Id"); + + b.HasIndex("Name") + .IsUnique(); + + b.ToTable("role", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.RolePermission", b => + { + b.Property("RoleId") + .HasColumnType("char(36)"); + + b.Property("PermissionCode") + .HasMaxLength(100) + .HasColumnType("varchar(100)"); + + b.Property("PermissionDescription") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("varchar(200)"); + + b.Property("PermissionName") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("varchar(100)"); + + b.HasKey("RoleId", "PermissionCode"); + + b.ToTable("role_permission", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.User", b => + { + b.Property("Id") + .HasColumnType("bigint"); + + b.Property("Age") + .HasColumnType("int"); + + b.Property("BirthDate") + .HasColumnType("datetime(6)"); + + b.Property("CreatedAt") + .HasColumnType("datetime(6)"); + + b.Property("DeletedAt") + .HasColumnType("datetime(6)"); + + b.Property("Email") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("varchar(100)"); + + b.Property("Gender") + .IsRequired() + .HasMaxLength(10) + .HasColumnType("varchar(10)"); + + b.Property("IsActive") + .HasColumnType("tinyint(1)"); + + b.Property("IsDeleted") + .HasColumnType("tinyint(1)"); + + b.Property("LastLoginTime") + .HasColumnType("datetime(6)"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("varchar(50)"); + + b.Property("PasswordHash") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("varchar(255)"); + + b.Property("Phone") + .IsRequired() + .HasMaxLength(20) + .HasColumnType("varchar(20)"); + + b.Property("RealName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("varchar(50)"); + + b.Property("Status") + .HasColumnType("int"); + + b.Property("UpdateTime") + .HasColumnType("datetime(6)"); + + b.HasKey("Id"); + + b.HasIndex("Email"); + + b.HasIndex("Name"); + + b.ToTable("user", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserDept", b => + { + b.Property("UserId") + .HasColumnType("bigint"); + + b.Property("AssignedAt") + .HasColumnType("datetime(6)"); + + b.Property("DeptId") + .HasColumnType("bigint"); + + b.Property("DeptName") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("varchar(100)"); + + b.HasKey("UserId"); + + b.HasIndex("DeptId"); + + b.HasIndex("UserId"); + + b.ToTable("user_dept", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRefreshToken", b => + { + b.Property("Id") + .HasColumnType("bigint"); + + b.Property("CreatedTime") + .HasColumnType("datetime(6)"); + + b.Property("ExpiresTime") + .HasColumnType("datetime(6)"); + + b.Property("IsRevoked") + .HasColumnType("tinyint(1)"); + + b.Property("IsUsed") + .HasColumnType("tinyint(1)"); + + b.Property("Token") + .IsRequired() + .HasMaxLength(500) + .HasColumnType("varchar(500)"); + + b.Property("UserId") + .HasColumnType("bigint"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("user_refresh_token", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRole", b => + { + b.Property("UserId") + .HasColumnType("bigint"); + + b.Property("RoleId") + .HasColumnType("char(36)"); + + b.Property("RoleName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("varchar(50)"); + + b.HasKey("UserId", "RoleId"); + + b.ToTable("user_role", (string)null); + }); + + modelBuilder.Entity("NetCorePal.Extensions.DistributedTransactions.CAP.Persistence.CapLock", b => + { + b.Property("Key") + .HasMaxLength(128) + .HasColumnType("varchar(128)"); + + b.Property("Instance") + .HasMaxLength(256) + .HasColumnType("varchar"); + + b.Property("LastLockTime") + .HasColumnType("DATETIME(6)"); + + b.HasKey("Key"); + + b.ToTable("CAPLock", (string)null); + }); + + modelBuilder.Entity("NetCorePal.Extensions.DistributedTransactions.CAP.Persistence.PublishedMessage", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + b.Property("Added") + .HasColumnType("DATETIME(6)"); + + b.Property("Content") + .HasColumnType("longtext"); + + b.Property("ExpiresAt") + .HasColumnType("DATETIME(6)"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("varchar(200)"); + + b.Property("Retries") + .HasColumnType("int"); + + b.Property("StatusName") + .IsRequired() + .HasMaxLength(40) + .HasColumnType("varchar(40)"); + + b.Property("Version") + .HasMaxLength(20) + .HasColumnType("varchar(20)"); + + b.HasKey("Id"); + + b.HasIndex(new[] { "ExpiresAt", "StatusName" }, "IX_ExpiresAt_StatusName"); + + b.HasIndex(new[] { "Version", "ExpiresAt", "StatusName" }, "IX_Version_ExpiresAt_StatusName"); + + b.ToTable("CAPPublishedMessage", (string)null); + }); + + modelBuilder.Entity("NetCorePal.Extensions.DistributedTransactions.CAP.Persistence.ReceivedMessage", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + b.Property("Added") + .HasColumnType("DATETIME(6)"); + + b.Property("Content") + .HasColumnType("longtext"); + + b.Property("ExpiresAt") + .HasColumnType("DATETIME(6)"); + + b.Property("Group") + .HasMaxLength(200) + .HasColumnType("varchar(200)"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(400) + .HasColumnType("varchar(400)"); + + b.Property("Retries") + .HasColumnType("int"); + + b.Property("StatusName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("varchar(50)"); + + b.Property("Version") + .HasMaxLength(20) + .HasColumnType("varchar(20)"); + + b.HasKey("Id"); + + b.HasIndex(new[] { "ExpiresAt", "StatusName" }, "IX_ExpiresAt_StatusName") + .HasDatabaseName("IX_ExpiresAt_StatusName1"); + + b.HasIndex(new[] { "Version", "ExpiresAt", "StatusName" }, "IX_Version_ExpiresAt_StatusName") + .HasDatabaseName("IX_Version_ExpiresAt_StatusName1"); + + b.ToTable("CAPReceivedMessage", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.RolePermission", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.RoleAggregate.Role", null) + .WithMany("Permissions") + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserDept", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.UserAggregate.User", null) + .WithOne("Dept") + .HasForeignKey("ABC.Template.Domain.AggregatesModel.UserAggregate.UserDept", "UserId") + .OnDelete(DeleteBehavior.ClientCascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRefreshToken", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.UserAggregate.User", null) + .WithMany("RefreshTokens") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRole", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.UserAggregate.User", null) + .WithMany("Roles") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.Role", b => + { + b.Navigation("Permissions"); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.User", b => + { + b.Navigation("Dept") + .IsRequired(); + + b.Navigation("RefreshTokens"); + + b.Navigation("Roles"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/template/src/ABC.Template.Infrastructure/MigrationsAll/MySql-net8.0/20251225064948_Init.Designer.cs b/template/src/ABC.Template.Infrastructure/MigrationsAll/MySql-net8.0/20260122054408_Init.Designer.cs similarity index 76% rename from template/src/ABC.Template.Infrastructure/MigrationsAll/MySql-net8.0/20251225064948_Init.Designer.cs rename to template/src/ABC.Template.Infrastructure/MigrationsAll/MySql-net8.0/20260122054408_Init.Designer.cs index 3308d2b4..7cb992ac 100644 --- a/template/src/ABC.Template.Infrastructure/MigrationsAll/MySql-net8.0/20251225064948_Init.Designer.cs +++ b/template/src/ABC.Template.Infrastructure/MigrationsAll/MySql-net8.0/20260122054408_Init.Designer.cs @@ -1,17 +1,17 @@ // using System; +using ABC.Template.Infrastructure; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using ABC.Template.Infrastructure; #nullable disable namespace ABC.Template.Infrastructure.Migrations { [DbContext(typeof(ApplicationDbContext))] - [Migration("20251225064948_Init")] + [Migration("20260122054408_Init")] partial class Init { /// @@ -127,47 +127,6 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.ToTable("CAPReceivedMessage", (string)null); }); - - modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.DeliverAggregate.DeliverRecord", b => - { - b.Property("Id") - .HasColumnType("char(36)"); - - b.Property("OrderId") - .HasColumnType("char(36)"); - - b.HasKey("Id"); - - b.ToTable("deliverrecord", (string)null); - }); - - modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.OrderAggregate.Order", b => - { - b.Property("Id") - .HasColumnType("char(36)"); - - b.Property("Count") - .HasColumnType("int"); - - b.Property("Name") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("varchar(100)"); - - b.Property("Paid") - .HasColumnType("tinyint(1)"); - - b.Property("RowVersion") - .IsConcurrencyToken() - .HasColumnType("int"); - - b.Property("UpdateTime") - .HasColumnType("datetime(6)"); - - b.HasKey("Id"); - - b.ToTable("order", (string)null); - }); #pragma warning restore 612, 618 } } diff --git a/template/src/ABC.Template.Infrastructure/MigrationsAll/MySql-net9.0/20251225064958_Init.cs b/template/src/ABC.Template.Infrastructure/MigrationsAll/MySql-net8.0/20260122054408_Init.cs similarity index 76% rename from template/src/ABC.Template.Infrastructure/MigrationsAll/MySql-net9.0/20251225064958_Init.cs rename to template/src/ABC.Template.Infrastructure/MigrationsAll/MySql-net8.0/20260122054408_Init.cs index dc3a6e74..cab54e92 100644 --- a/template/src/ABC.Template.Infrastructure/MigrationsAll/MySql-net9.0/20251225064958_Init.cs +++ b/template/src/ABC.Template.Infrastructure/MigrationsAll/MySql-net8.0/20260122054408_Init.cs @@ -81,37 +81,6 @@ protected override void Up(MigrationBuilder migrationBuilder) }) .Annotation("MySql:CharSet", "utf8mb4"); - migrationBuilder.CreateTable( - name: "deliverrecord", - columns: table => new - { - Id = table.Column(type: "char(36)", nullable: false, collation: "ascii_general_ci"), - OrderId = table.Column(type: "char(36)", nullable: false, collation: "ascii_general_ci") - }, - constraints: table => - { - table.PrimaryKey("PK_deliverrecord", x => x.Id); - }) - .Annotation("MySql:CharSet", "utf8mb4"); - - migrationBuilder.CreateTable( - name: "order", - columns: table => new - { - Id = table.Column(type: "char(36)", nullable: false, collation: "ascii_general_ci"), - Paid = table.Column(type: "tinyint(1)", nullable: false), - Name = table.Column(type: "varchar(100)", maxLength: 100, nullable: false) - .Annotation("MySql:CharSet", "utf8mb4"), - Count = table.Column(type: "int", nullable: false), - RowVersion = table.Column(type: "int", nullable: false), - UpdateTime = table.Column(type: "datetime(6)", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_order", x => x.Id); - }) - .Annotation("MySql:CharSet", "utf8mb4"); - migrationBuilder.CreateIndex( name: "IX_ExpiresAt_StatusName", table: "CAPPublishedMessage", @@ -144,12 +113,6 @@ protected override void Down(MigrationBuilder migrationBuilder) migrationBuilder.DropTable( name: "CAPReceivedMessage"); - - migrationBuilder.DropTable( - name: "deliverrecord"); - - migrationBuilder.DropTable( - name: "order"); } } } diff --git a/template/src/ABC.Template.Infrastructure/MigrationsAll/MySql-net8.0/ApplicationDbContextModelSnapshot.cs b/template/src/ABC.Template.Infrastructure/MigrationsAll/MySql-net8.0/ApplicationDbContextModelSnapshot.cs index 4e52ce38..149a1383 100644 --- a/template/src/ABC.Template.Infrastructure/MigrationsAll/MySql-net8.0/ApplicationDbContextModelSnapshot.cs +++ b/template/src/ABC.Template.Infrastructure/MigrationsAll/MySql-net8.0/ApplicationDbContextModelSnapshot.cs @@ -1,9 +1,9 @@ // using System; +using ABC.Template.Infrastructure; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using ABC.Template.Infrastructure; #nullable disable @@ -124,47 +124,6 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.ToTable("CAPReceivedMessage", (string)null); }); - - modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.DeliverAggregate.DeliverRecord", b => - { - b.Property("Id") - .HasColumnType("char(36)"); - - b.Property("OrderId") - .HasColumnType("char(36)"); - - b.HasKey("Id"); - - b.ToTable("deliverrecord", (string)null); - }); - - modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.OrderAggregate.Order", b => - { - b.Property("Id") - .HasColumnType("char(36)"); - - b.Property("Count") - .HasColumnType("int"); - - b.Property("Name") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("varchar(100)"); - - b.Property("Paid") - .HasColumnType("tinyint(1)"); - - b.Property("RowVersion") - .IsConcurrencyToken() - .HasColumnType("int"); - - b.Property("UpdateTime") - .HasColumnType("datetime(6)"); - - b.HasKey("Id"); - - b.ToTable("order", (string)null); - }); #pragma warning restore 612, 618 } } diff --git a/template/src/ABC.Template.Infrastructure/MigrationsAll/MySql-net9.0-admin/20260122054439_Init.Designer.cs b/template/src/ABC.Template.Infrastructure/MigrationsAll/MySql-net9.0-admin/20260122054439_Init.Designer.cs new file mode 100644 index 00000000..eb2bf411 --- /dev/null +++ b/template/src/ABC.Template.Infrastructure/MigrationsAll/MySql-net9.0-admin/20260122054439_Init.Designer.cs @@ -0,0 +1,440 @@ +// +using System; +using ABC.Template.Infrastructure; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace ABC.Template.Infrastructure.Migrations +{ + [DbContext(typeof(ApplicationDbContext))] + [Migration("20260122054439_Init")] + partial class Init + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "9.0.0") + .HasAnnotation("Relational:MaxIdentifierLength", 64); + + MySqlModelBuilderExtensions.AutoIncrementColumns(modelBuilder); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.DeptAggregate.Dept", b => + { + b.Property("Id") + .HasColumnType("bigint"); + + b.Property("CreatedAt") + .HasColumnType("datetime(6)"); + + b.Property("DeletedAt") + .HasColumnType("datetime(6)"); + + b.Property("IsDeleted") + .HasColumnType("tinyint(1)"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("varchar(100)"); + + b.Property("ParentId") + .HasColumnType("bigint"); + + b.Property("Remark") + .IsRequired() + .HasMaxLength(500) + .HasColumnType("varchar(500)"); + + b.Property("Status") + .HasColumnType("int"); + + b.Property("UpdateTime") + .HasColumnType("datetime(6)"); + + b.HasKey("Id"); + + b.HasIndex("IsDeleted"); + + b.HasIndex("ParentId"); + + b.HasIndex("Status"); + + b.ToTable("dept", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.Role", b => + { + b.Property("Id") + .HasColumnType("char(36)"); + + b.Property("CreatedAt") + .HasColumnType("datetime(6)"); + + b.Property("DeletedAt") + .HasColumnType("datetime(6)"); + + b.Property("Description") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("varchar(200)"); + + b.Property("IsActive") + .HasColumnType("tinyint(1)"); + + b.Property("IsDeleted") + .HasColumnType("tinyint(1)"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("varchar(50)"); + + b.HasKey("Id"); + + b.HasIndex("Name") + .IsUnique(); + + b.ToTable("role", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.RolePermission", b => + { + b.Property("RoleId") + .HasColumnType("char(36)"); + + b.Property("PermissionCode") + .HasMaxLength(100) + .HasColumnType("varchar(100)"); + + b.Property("PermissionDescription") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("varchar(200)"); + + b.Property("PermissionName") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("varchar(100)"); + + b.HasKey("RoleId", "PermissionCode"); + + b.ToTable("role_permission", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.User", b => + { + b.Property("Id") + .HasColumnType("bigint"); + + b.Property("Age") + .HasColumnType("int"); + + b.Property("BirthDate") + .HasColumnType("datetime(6)"); + + b.Property("CreatedAt") + .HasColumnType("datetime(6)"); + + b.Property("DeletedAt") + .HasColumnType("datetime(6)"); + + b.Property("Email") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("varchar(100)"); + + b.Property("Gender") + .IsRequired() + .HasMaxLength(10) + .HasColumnType("varchar(10)"); + + b.Property("IsActive") + .HasColumnType("tinyint(1)"); + + b.Property("IsDeleted") + .HasColumnType("tinyint(1)"); + + b.Property("LastLoginTime") + .HasColumnType("datetime(6)"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("varchar(50)"); + + b.Property("PasswordHash") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("varchar(255)"); + + b.Property("Phone") + .IsRequired() + .HasMaxLength(20) + .HasColumnType("varchar(20)"); + + b.Property("RealName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("varchar(50)"); + + b.Property("Status") + .HasColumnType("int"); + + b.Property("UpdateTime") + .HasColumnType("datetime(6)"); + + b.HasKey("Id"); + + b.HasIndex("Email"); + + b.HasIndex("Name"); + + b.ToTable("user", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserDept", b => + { + b.Property("UserId") + .HasColumnType("bigint"); + + b.Property("AssignedAt") + .HasColumnType("datetime(6)"); + + b.Property("DeptId") + .HasColumnType("bigint"); + + b.Property("DeptName") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("varchar(100)"); + + b.HasKey("UserId"); + + b.HasIndex("DeptId"); + + b.HasIndex("UserId"); + + b.ToTable("user_dept", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRefreshToken", b => + { + b.Property("Id") + .HasColumnType("bigint"); + + b.Property("CreatedTime") + .HasColumnType("datetime(6)"); + + b.Property("ExpiresTime") + .HasColumnType("datetime(6)"); + + b.Property("IsRevoked") + .HasColumnType("tinyint(1)"); + + b.Property("IsUsed") + .HasColumnType("tinyint(1)"); + + b.Property("Token") + .IsRequired() + .HasMaxLength(500) + .HasColumnType("varchar(500)"); + + b.Property("UserId") + .HasColumnType("bigint"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("user_refresh_token", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRole", b => + { + b.Property("UserId") + .HasColumnType("bigint"); + + b.Property("RoleId") + .HasColumnType("char(36)"); + + b.Property("RoleName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("varchar(50)"); + + b.HasKey("UserId", "RoleId"); + + b.ToTable("user_role", (string)null); + }); + + modelBuilder.Entity("NetCorePal.Extensions.DistributedTransactions.CAP.Persistence.CapLock", b => + { + b.Property("Key") + .HasMaxLength(128) + .HasColumnType("varchar(128)"); + + b.Property("Instance") + .HasMaxLength(256) + .HasColumnType("varchar"); + + b.Property("LastLockTime") + .HasColumnType("DATETIME(6)"); + + b.HasKey("Key"); + + b.ToTable("CAPLock", (string)null); + }); + + modelBuilder.Entity("NetCorePal.Extensions.DistributedTransactions.CAP.Persistence.PublishedMessage", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property("Id")); + + b.Property("Added") + .HasColumnType("DATETIME(6)"); + + b.Property("Content") + .HasColumnType("longtext"); + + b.Property("ExpiresAt") + .HasColumnType("DATETIME(6)"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("varchar(200)"); + + b.Property("Retries") + .HasColumnType("int"); + + b.Property("StatusName") + .IsRequired() + .HasMaxLength(40) + .HasColumnType("varchar(40)"); + + b.Property("Version") + .HasMaxLength(20) + .HasColumnType("varchar(20)"); + + b.HasKey("Id"); + + b.HasIndex(new[] { "ExpiresAt", "StatusName" }, "IX_ExpiresAt_StatusName"); + + b.HasIndex(new[] { "Version", "ExpiresAt", "StatusName" }, "IX_Version_ExpiresAt_StatusName"); + + b.ToTable("CAPPublishedMessage", (string)null); + }); + + modelBuilder.Entity("NetCorePal.Extensions.DistributedTransactions.CAP.Persistence.ReceivedMessage", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property("Id")); + + b.Property("Added") + .HasColumnType("DATETIME(6)"); + + b.Property("Content") + .HasColumnType("longtext"); + + b.Property("ExpiresAt") + .HasColumnType("DATETIME(6)"); + + b.Property("Group") + .HasMaxLength(200) + .HasColumnType("varchar(200)"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(400) + .HasColumnType("varchar(400)"); + + b.Property("Retries") + .HasColumnType("int"); + + b.Property("StatusName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("varchar(50)"); + + b.Property("Version") + .HasMaxLength(20) + .HasColumnType("varchar(20)"); + + b.HasKey("Id"); + + b.HasIndex(new[] { "ExpiresAt", "StatusName" }, "IX_ExpiresAt_StatusName") + .HasDatabaseName("IX_ExpiresAt_StatusName1"); + + b.HasIndex(new[] { "Version", "ExpiresAt", "StatusName" }, "IX_Version_ExpiresAt_StatusName") + .HasDatabaseName("IX_Version_ExpiresAt_StatusName1"); + + b.ToTable("CAPReceivedMessage", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.RolePermission", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.RoleAggregate.Role", null) + .WithMany("Permissions") + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserDept", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.UserAggregate.User", null) + .WithOne("Dept") + .HasForeignKey("ABC.Template.Domain.AggregatesModel.UserAggregate.UserDept", "UserId") + .OnDelete(DeleteBehavior.ClientCascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRefreshToken", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.UserAggregate.User", null) + .WithMany("RefreshTokens") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRole", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.UserAggregate.User", null) + .WithMany("Roles") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.Role", b => + { + b.Navigation("Permissions"); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.User", b => + { + b.Navigation("Dept") + .IsRequired(); + + b.Navigation("RefreshTokens"); + + b.Navigation("Roles"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/template/src/ABC.Template.Infrastructure/MigrationsAll/MySql-net9.0-admin/20260122054439_Init.cs b/template/src/ABC.Template.Infrastructure/MigrationsAll/MySql-net9.0-admin/20260122054439_Init.cs new file mode 100644 index 00000000..290bfee7 --- /dev/null +++ b/template/src/ABC.Template.Infrastructure/MigrationsAll/MySql-net9.0-admin/20260122054439_Init.cs @@ -0,0 +1,351 @@ +using System; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace ABC.Template.Infrastructure.Migrations +{ + /// + public partial class Init : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AlterDatabase() + .Annotation("MySql:CharSet", "utf8mb4"); + + migrationBuilder.CreateTable( + name: "CAPLock", + columns: table => new + { + Key = table.Column(type: "varchar(128)", maxLength: 128, nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + Instance = table.Column(type: "varchar(256)", maxLength: 256, nullable: true) + .Annotation("MySql:CharSet", "utf8mb4"), + LastLockTime = table.Column(type: "DATETIME(6)", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_CAPLock", x => x.Key); + }) + .Annotation("MySql:CharSet", "utf8mb4"); + + migrationBuilder.CreateTable( + name: "CAPPublishedMessage", + columns: table => new + { + Id = table.Column(type: "bigint", nullable: false) + .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), + Version = table.Column(type: "varchar(20)", maxLength: 20, nullable: true) + .Annotation("MySql:CharSet", "utf8mb4"), + Name = table.Column(type: "varchar(200)", maxLength: 200, nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + Content = table.Column(type: "longtext", nullable: true) + .Annotation("MySql:CharSet", "utf8mb4"), + Retries = table.Column(type: "int", nullable: true), + Added = table.Column(type: "DATETIME(6)", nullable: false), + ExpiresAt = table.Column(type: "DATETIME(6)", nullable: true), + StatusName = table.Column(type: "varchar(40)", maxLength: 40, nullable: false) + .Annotation("MySql:CharSet", "utf8mb4") + }, + constraints: table => + { + table.PrimaryKey("PK_CAPPublishedMessage", x => x.Id); + }) + .Annotation("MySql:CharSet", "utf8mb4"); + + migrationBuilder.CreateTable( + name: "CAPReceivedMessage", + columns: table => new + { + Id = table.Column(type: "bigint", nullable: false) + .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), + Version = table.Column(type: "varchar(20)", maxLength: 20, nullable: true) + .Annotation("MySql:CharSet", "utf8mb4"), + Name = table.Column(type: "varchar(400)", maxLength: 400, nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + Group = table.Column(type: "varchar(200)", maxLength: 200, nullable: true) + .Annotation("MySql:CharSet", "utf8mb4"), + Content = table.Column(type: "longtext", nullable: true) + .Annotation("MySql:CharSet", "utf8mb4"), + Retries = table.Column(type: "int", nullable: true), + Added = table.Column(type: "DATETIME(6)", nullable: false), + ExpiresAt = table.Column(type: "DATETIME(6)", nullable: true), + StatusName = table.Column(type: "varchar(50)", maxLength: 50, nullable: false) + .Annotation("MySql:CharSet", "utf8mb4") + }, + constraints: table => + { + table.PrimaryKey("PK_CAPReceivedMessage", x => x.Id); + }) + .Annotation("MySql:CharSet", "utf8mb4"); + + migrationBuilder.CreateTable( + name: "dept", + columns: table => new + { + Id = table.Column(type: "bigint", nullable: false), + Name = table.Column(type: "varchar(100)", maxLength: 100, nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + Remark = table.Column(type: "varchar(500)", maxLength: 500, nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + ParentId = table.Column(type: "bigint", nullable: false), + Status = table.Column(type: "int", nullable: false), + CreatedAt = table.Column(type: "datetime(6)", nullable: false), + IsDeleted = table.Column(type: "tinyint(1)", nullable: false), + DeletedAt = table.Column(type: "datetime(6)", nullable: false), + UpdateTime = table.Column(type: "datetime(6)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_dept", x => x.Id); + }) + .Annotation("MySql:CharSet", "utf8mb4"); + + migrationBuilder.CreateTable( + name: "role", + columns: table => new + { + Id = table.Column(type: "char(36)", nullable: false, collation: "ascii_general_ci"), + Name = table.Column(type: "varchar(50)", maxLength: 50, nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + Description = table.Column(type: "varchar(200)", maxLength: 200, nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + CreatedAt = table.Column(type: "datetime(6)", nullable: false), + IsActive = table.Column(type: "tinyint(1)", nullable: false), + IsDeleted = table.Column(type: "tinyint(1)", nullable: false), + DeletedAt = table.Column(type: "datetime(6)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_role", x => x.Id); + }) + .Annotation("MySql:CharSet", "utf8mb4"); + + migrationBuilder.CreateTable( + name: "user", + columns: table => new + { + Id = table.Column(type: "bigint", nullable: false), + Name = table.Column(type: "varchar(50)", maxLength: 50, nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + Email = table.Column(type: "varchar(100)", maxLength: 100, nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + Phone = table.Column(type: "varchar(20)", maxLength: 20, nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + RealName = table.Column(type: "varchar(50)", maxLength: 50, nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + Status = table.Column(type: "int", nullable: false), + PasswordHash = table.Column(type: "varchar(255)", maxLength: 255, nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + IsActive = table.Column(type: "tinyint(1)", nullable: false), + CreatedAt = table.Column(type: "datetime(6)", nullable: false), + LastLoginTime = table.Column(type: "datetime(6)", nullable: true), + UpdateTime = table.Column(type: "datetime(6)", nullable: false), + IsDeleted = table.Column(type: "tinyint(1)", nullable: false), + DeletedAt = table.Column(type: "datetime(6)", nullable: false), + Gender = table.Column(type: "varchar(10)", maxLength: 10, nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + Age = table.Column(type: "int", nullable: false), + BirthDate = table.Column(type: "datetime(6)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_user", x => x.Id); + }) + .Annotation("MySql:CharSet", "utf8mb4"); + + migrationBuilder.CreateTable( + name: "role_permission", + columns: table => new + { + RoleId = table.Column(type: "char(36)", nullable: false, collation: "ascii_general_ci"), + PermissionCode = table.Column(type: "varchar(100)", maxLength: 100, nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + PermissionName = table.Column(type: "varchar(100)", maxLength: 100, nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + PermissionDescription = table.Column(type: "varchar(200)", maxLength: 200, nullable: false) + .Annotation("MySql:CharSet", "utf8mb4") + }, + constraints: table => + { + table.PrimaryKey("PK_role_permission", x => new { x.RoleId, x.PermissionCode }); + table.ForeignKey( + name: "FK_role_permission_role_RoleId", + column: x => x.RoleId, + principalTable: "role", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }) + .Annotation("MySql:CharSet", "utf8mb4"); + + migrationBuilder.CreateTable( + name: "user_dept", + columns: table => new + { + UserId = table.Column(type: "bigint", nullable: false), + DeptId = table.Column(type: "bigint", nullable: false), + DeptName = table.Column(type: "varchar(100)", maxLength: 100, nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + AssignedAt = table.Column(type: "datetime(6)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_user_dept", x => x.UserId); + table.ForeignKey( + name: "FK_user_dept_user_UserId", + column: x => x.UserId, + principalTable: "user", + principalColumn: "Id"); + }) + .Annotation("MySql:CharSet", "utf8mb4"); + + migrationBuilder.CreateTable( + name: "user_refresh_token", + columns: table => new + { + Id = table.Column(type: "bigint", nullable: false), + UserId = table.Column(type: "bigint", nullable: false), + Token = table.Column(type: "varchar(500)", maxLength: 500, nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + CreatedTime = table.Column(type: "datetime(6)", nullable: false), + ExpiresTime = table.Column(type: "datetime(6)", nullable: false), + IsUsed = table.Column(type: "tinyint(1)", nullable: false), + IsRevoked = table.Column(type: "tinyint(1)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_user_refresh_token", x => x.Id); + table.ForeignKey( + name: "FK_user_refresh_token_user_UserId", + column: x => x.UserId, + principalTable: "user", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }) + .Annotation("MySql:CharSet", "utf8mb4"); + + migrationBuilder.CreateTable( + name: "user_role", + columns: table => new + { + UserId = table.Column(type: "bigint", nullable: false), + RoleId = table.Column(type: "char(36)", nullable: false, collation: "ascii_general_ci"), + RoleName = table.Column(type: "varchar(50)", maxLength: 50, nullable: false) + .Annotation("MySql:CharSet", "utf8mb4") + }, + constraints: table => + { + table.PrimaryKey("PK_user_role", x => new { x.UserId, x.RoleId }); + table.ForeignKey( + name: "FK_user_role_user_UserId", + column: x => x.UserId, + principalTable: "user", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }) + .Annotation("MySql:CharSet", "utf8mb4"); + + migrationBuilder.CreateIndex( + name: "IX_ExpiresAt_StatusName", + table: "CAPPublishedMessage", + columns: new[] { "ExpiresAt", "StatusName" }); + + migrationBuilder.CreateIndex( + name: "IX_Version_ExpiresAt_StatusName", + table: "CAPPublishedMessage", + columns: new[] { "Version", "ExpiresAt", "StatusName" }); + + migrationBuilder.CreateIndex( + name: "IX_ExpiresAt_StatusName1", + table: "CAPReceivedMessage", + columns: new[] { "ExpiresAt", "StatusName" }); + + migrationBuilder.CreateIndex( + name: "IX_Version_ExpiresAt_StatusName1", + table: "CAPReceivedMessage", + columns: new[] { "Version", "ExpiresAt", "StatusName" }); + + migrationBuilder.CreateIndex( + name: "IX_dept_IsDeleted", + table: "dept", + column: "IsDeleted"); + + migrationBuilder.CreateIndex( + name: "IX_dept_ParentId", + table: "dept", + column: "ParentId"); + + migrationBuilder.CreateIndex( + name: "IX_dept_Status", + table: "dept", + column: "Status"); + + migrationBuilder.CreateIndex( + name: "IX_role_Name", + table: "role", + column: "Name", + unique: true); + + migrationBuilder.CreateIndex( + name: "IX_user_Email", + table: "user", + column: "Email"); + + migrationBuilder.CreateIndex( + name: "IX_user_Name", + table: "user", + column: "Name"); + + migrationBuilder.CreateIndex( + name: "IX_user_dept_DeptId", + table: "user_dept", + column: "DeptId"); + + migrationBuilder.CreateIndex( + name: "IX_user_dept_UserId", + table: "user_dept", + column: "UserId"); + + migrationBuilder.CreateIndex( + name: "IX_user_refresh_token_UserId", + table: "user_refresh_token", + column: "UserId"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "CAPLock"); + + migrationBuilder.DropTable( + name: "CAPPublishedMessage"); + + migrationBuilder.DropTable( + name: "CAPReceivedMessage"); + + migrationBuilder.DropTable( + name: "dept"); + + migrationBuilder.DropTable( + name: "role_permission"); + + migrationBuilder.DropTable( + name: "user_dept"); + + migrationBuilder.DropTable( + name: "user_refresh_token"); + + migrationBuilder.DropTable( + name: "user_role"); + + migrationBuilder.DropTable( + name: "role"); + + migrationBuilder.DropTable( + name: "user"); + } + } +} diff --git a/template/src/ABC.Template.Infrastructure/MigrationsAll/MySql-net9.0-admin/ApplicationDbContextModelSnapshot.cs b/template/src/ABC.Template.Infrastructure/MigrationsAll/MySql-net9.0-admin/ApplicationDbContextModelSnapshot.cs new file mode 100644 index 00000000..f0c1ec88 --- /dev/null +++ b/template/src/ABC.Template.Infrastructure/MigrationsAll/MySql-net9.0-admin/ApplicationDbContextModelSnapshot.cs @@ -0,0 +1,437 @@ +// +using System; +using ABC.Template.Infrastructure; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace ABC.Template.Infrastructure.Migrations +{ + [DbContext(typeof(ApplicationDbContext))] + partial class ApplicationDbContextModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "9.0.0") + .HasAnnotation("Relational:MaxIdentifierLength", 64); + + MySqlModelBuilderExtensions.AutoIncrementColumns(modelBuilder); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.DeptAggregate.Dept", b => + { + b.Property("Id") + .HasColumnType("bigint"); + + b.Property("CreatedAt") + .HasColumnType("datetime(6)"); + + b.Property("DeletedAt") + .HasColumnType("datetime(6)"); + + b.Property("IsDeleted") + .HasColumnType("tinyint(1)"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("varchar(100)"); + + b.Property("ParentId") + .HasColumnType("bigint"); + + b.Property("Remark") + .IsRequired() + .HasMaxLength(500) + .HasColumnType("varchar(500)"); + + b.Property("Status") + .HasColumnType("int"); + + b.Property("UpdateTime") + .HasColumnType("datetime(6)"); + + b.HasKey("Id"); + + b.HasIndex("IsDeleted"); + + b.HasIndex("ParentId"); + + b.HasIndex("Status"); + + b.ToTable("dept", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.Role", b => + { + b.Property("Id") + .HasColumnType("char(36)"); + + b.Property("CreatedAt") + .HasColumnType("datetime(6)"); + + b.Property("DeletedAt") + .HasColumnType("datetime(6)"); + + b.Property("Description") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("varchar(200)"); + + b.Property("IsActive") + .HasColumnType("tinyint(1)"); + + b.Property("IsDeleted") + .HasColumnType("tinyint(1)"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("varchar(50)"); + + b.HasKey("Id"); + + b.HasIndex("Name") + .IsUnique(); + + b.ToTable("role", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.RolePermission", b => + { + b.Property("RoleId") + .HasColumnType("char(36)"); + + b.Property("PermissionCode") + .HasMaxLength(100) + .HasColumnType("varchar(100)"); + + b.Property("PermissionDescription") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("varchar(200)"); + + b.Property("PermissionName") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("varchar(100)"); + + b.HasKey("RoleId", "PermissionCode"); + + b.ToTable("role_permission", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.User", b => + { + b.Property("Id") + .HasColumnType("bigint"); + + b.Property("Age") + .HasColumnType("int"); + + b.Property("BirthDate") + .HasColumnType("datetime(6)"); + + b.Property("CreatedAt") + .HasColumnType("datetime(6)"); + + b.Property("DeletedAt") + .HasColumnType("datetime(6)"); + + b.Property("Email") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("varchar(100)"); + + b.Property("Gender") + .IsRequired() + .HasMaxLength(10) + .HasColumnType("varchar(10)"); + + b.Property("IsActive") + .HasColumnType("tinyint(1)"); + + b.Property("IsDeleted") + .HasColumnType("tinyint(1)"); + + b.Property("LastLoginTime") + .HasColumnType("datetime(6)"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("varchar(50)"); + + b.Property("PasswordHash") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("varchar(255)"); + + b.Property("Phone") + .IsRequired() + .HasMaxLength(20) + .HasColumnType("varchar(20)"); + + b.Property("RealName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("varchar(50)"); + + b.Property("Status") + .HasColumnType("int"); + + b.Property("UpdateTime") + .HasColumnType("datetime(6)"); + + b.HasKey("Id"); + + b.HasIndex("Email"); + + b.HasIndex("Name"); + + b.ToTable("user", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserDept", b => + { + b.Property("UserId") + .HasColumnType("bigint"); + + b.Property("AssignedAt") + .HasColumnType("datetime(6)"); + + b.Property("DeptId") + .HasColumnType("bigint"); + + b.Property("DeptName") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("varchar(100)"); + + b.HasKey("UserId"); + + b.HasIndex("DeptId"); + + b.HasIndex("UserId"); + + b.ToTable("user_dept", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRefreshToken", b => + { + b.Property("Id") + .HasColumnType("bigint"); + + b.Property("CreatedTime") + .HasColumnType("datetime(6)"); + + b.Property("ExpiresTime") + .HasColumnType("datetime(6)"); + + b.Property("IsRevoked") + .HasColumnType("tinyint(1)"); + + b.Property("IsUsed") + .HasColumnType("tinyint(1)"); + + b.Property("Token") + .IsRequired() + .HasMaxLength(500) + .HasColumnType("varchar(500)"); + + b.Property("UserId") + .HasColumnType("bigint"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("user_refresh_token", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRole", b => + { + b.Property("UserId") + .HasColumnType("bigint"); + + b.Property("RoleId") + .HasColumnType("char(36)"); + + b.Property("RoleName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("varchar(50)"); + + b.HasKey("UserId", "RoleId"); + + b.ToTable("user_role", (string)null); + }); + + modelBuilder.Entity("NetCorePal.Extensions.DistributedTransactions.CAP.Persistence.CapLock", b => + { + b.Property("Key") + .HasMaxLength(128) + .HasColumnType("varchar(128)"); + + b.Property("Instance") + .HasMaxLength(256) + .HasColumnType("varchar"); + + b.Property("LastLockTime") + .HasColumnType("DATETIME(6)"); + + b.HasKey("Key"); + + b.ToTable("CAPLock", (string)null); + }); + + modelBuilder.Entity("NetCorePal.Extensions.DistributedTransactions.CAP.Persistence.PublishedMessage", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property("Id")); + + b.Property("Added") + .HasColumnType("DATETIME(6)"); + + b.Property("Content") + .HasColumnType("longtext"); + + b.Property("ExpiresAt") + .HasColumnType("DATETIME(6)"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("varchar(200)"); + + b.Property("Retries") + .HasColumnType("int"); + + b.Property("StatusName") + .IsRequired() + .HasMaxLength(40) + .HasColumnType("varchar(40)"); + + b.Property("Version") + .HasMaxLength(20) + .HasColumnType("varchar(20)"); + + b.HasKey("Id"); + + b.HasIndex(new[] { "ExpiresAt", "StatusName" }, "IX_ExpiresAt_StatusName"); + + b.HasIndex(new[] { "Version", "ExpiresAt", "StatusName" }, "IX_Version_ExpiresAt_StatusName"); + + b.ToTable("CAPPublishedMessage", (string)null); + }); + + modelBuilder.Entity("NetCorePal.Extensions.DistributedTransactions.CAP.Persistence.ReceivedMessage", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property("Id")); + + b.Property("Added") + .HasColumnType("DATETIME(6)"); + + b.Property("Content") + .HasColumnType("longtext"); + + b.Property("ExpiresAt") + .HasColumnType("DATETIME(6)"); + + b.Property("Group") + .HasMaxLength(200) + .HasColumnType("varchar(200)"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(400) + .HasColumnType("varchar(400)"); + + b.Property("Retries") + .HasColumnType("int"); + + b.Property("StatusName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("varchar(50)"); + + b.Property("Version") + .HasMaxLength(20) + .HasColumnType("varchar(20)"); + + b.HasKey("Id"); + + b.HasIndex(new[] { "ExpiresAt", "StatusName" }, "IX_ExpiresAt_StatusName") + .HasDatabaseName("IX_ExpiresAt_StatusName1"); + + b.HasIndex(new[] { "Version", "ExpiresAt", "StatusName" }, "IX_Version_ExpiresAt_StatusName") + .HasDatabaseName("IX_Version_ExpiresAt_StatusName1"); + + b.ToTable("CAPReceivedMessage", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.RolePermission", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.RoleAggregate.Role", null) + .WithMany("Permissions") + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserDept", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.UserAggregate.User", null) + .WithOne("Dept") + .HasForeignKey("ABC.Template.Domain.AggregatesModel.UserAggregate.UserDept", "UserId") + .OnDelete(DeleteBehavior.ClientCascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRefreshToken", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.UserAggregate.User", null) + .WithMany("RefreshTokens") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRole", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.UserAggregate.User", null) + .WithMany("Roles") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.Role", b => + { + b.Navigation("Permissions"); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.User", b => + { + b.Navigation("Dept") + .IsRequired(); + + b.Navigation("RefreshTokens"); + + b.Navigation("Roles"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/template/src/ABC.Template.Infrastructure/MigrationsAll/MySql-net10.0/20251225065009_Init.Designer.cs b/template/src/ABC.Template.Infrastructure/MigrationsAll/MySql-net9.0/20260122054430_Init.Designer.cs similarity index 78% rename from template/src/ABC.Template.Infrastructure/MigrationsAll/MySql-net10.0/20251225065009_Init.Designer.cs rename to template/src/ABC.Template.Infrastructure/MigrationsAll/MySql-net9.0/20260122054430_Init.Designer.cs index e30c0555..d18e45c3 100644 --- a/template/src/ABC.Template.Infrastructure/MigrationsAll/MySql-net10.0/20251225065009_Init.Designer.cs +++ b/template/src/ABC.Template.Infrastructure/MigrationsAll/MySql-net9.0/20260122054430_Init.Designer.cs @@ -1,18 +1,18 @@ // using System; +using ABC.Template.Infrastructure; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using ABC.Template.Infrastructure; #nullable disable namespace ABC.Template.Infrastructure.Migrations { [DbContext(typeof(ApplicationDbContext))] - [Migration("20251225065009_Init")] + [Migration("20260122054430_Init")] partial class Init { /// @@ -134,47 +134,6 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.ToTable("CAPReceivedMessage", (string)null); }); - - modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.DeliverAggregate.DeliverRecord", b => - { - b.Property("Id") - .HasColumnType("char(36)"); - - b.Property("OrderId") - .HasColumnType("char(36)"); - - b.HasKey("Id"); - - b.ToTable("deliverrecord", (string)null); - }); - - modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.OrderAggregate.Order", b => - { - b.Property("Id") - .HasColumnType("char(36)"); - - b.Property("Count") - .HasColumnType("int"); - - b.Property("Name") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("varchar(100)"); - - b.Property("Paid") - .HasColumnType("tinyint(1)"); - - b.Property("RowVersion") - .IsConcurrencyToken() - .HasColumnType("int"); - - b.Property("UpdateTime") - .HasColumnType("datetime(6)"); - - b.HasKey("Id"); - - b.ToTable("order", (string)null); - }); #pragma warning restore 612, 618 } } diff --git a/template/src/ABC.Template.Infrastructure/MigrationsAll/MySql-net10.0/20251225065009_Init.cs b/template/src/ABC.Template.Infrastructure/MigrationsAll/MySql-net9.0/20260122054430_Init.cs similarity index 76% rename from template/src/ABC.Template.Infrastructure/MigrationsAll/MySql-net10.0/20251225065009_Init.cs rename to template/src/ABC.Template.Infrastructure/MigrationsAll/MySql-net9.0/20260122054430_Init.cs index dc3a6e74..cab54e92 100644 --- a/template/src/ABC.Template.Infrastructure/MigrationsAll/MySql-net10.0/20251225065009_Init.cs +++ b/template/src/ABC.Template.Infrastructure/MigrationsAll/MySql-net9.0/20260122054430_Init.cs @@ -81,37 +81,6 @@ protected override void Up(MigrationBuilder migrationBuilder) }) .Annotation("MySql:CharSet", "utf8mb4"); - migrationBuilder.CreateTable( - name: "deliverrecord", - columns: table => new - { - Id = table.Column(type: "char(36)", nullable: false, collation: "ascii_general_ci"), - OrderId = table.Column(type: "char(36)", nullable: false, collation: "ascii_general_ci") - }, - constraints: table => - { - table.PrimaryKey("PK_deliverrecord", x => x.Id); - }) - .Annotation("MySql:CharSet", "utf8mb4"); - - migrationBuilder.CreateTable( - name: "order", - columns: table => new - { - Id = table.Column(type: "char(36)", nullable: false, collation: "ascii_general_ci"), - Paid = table.Column(type: "tinyint(1)", nullable: false), - Name = table.Column(type: "varchar(100)", maxLength: 100, nullable: false) - .Annotation("MySql:CharSet", "utf8mb4"), - Count = table.Column(type: "int", nullable: false), - RowVersion = table.Column(type: "int", nullable: false), - UpdateTime = table.Column(type: "datetime(6)", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_order", x => x.Id); - }) - .Annotation("MySql:CharSet", "utf8mb4"); - migrationBuilder.CreateIndex( name: "IX_ExpiresAt_StatusName", table: "CAPPublishedMessage", @@ -144,12 +113,6 @@ protected override void Down(MigrationBuilder migrationBuilder) migrationBuilder.DropTable( name: "CAPReceivedMessage"); - - migrationBuilder.DropTable( - name: "deliverrecord"); - - migrationBuilder.DropTable( - name: "order"); } } } diff --git a/template/src/ABC.Template.Infrastructure/MigrationsAll/MySql-net9.0/ApplicationDbContextModelSnapshot.cs b/template/src/ABC.Template.Infrastructure/MigrationsAll/MySql-net9.0/ApplicationDbContextModelSnapshot.cs index 99305034..b80e31bf 100644 --- a/template/src/ABC.Template.Infrastructure/MigrationsAll/MySql-net9.0/ApplicationDbContextModelSnapshot.cs +++ b/template/src/ABC.Template.Infrastructure/MigrationsAll/MySql-net9.0/ApplicationDbContextModelSnapshot.cs @@ -1,10 +1,10 @@ // using System; +using ABC.Template.Infrastructure; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using ABC.Template.Infrastructure; #nullable disable @@ -131,47 +131,6 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.ToTable("CAPReceivedMessage", (string)null); }); - - modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.DeliverAggregate.DeliverRecord", b => - { - b.Property("Id") - .HasColumnType("char(36)"); - - b.Property("OrderId") - .HasColumnType("char(36)"); - - b.HasKey("Id"); - - b.ToTable("deliverrecord", (string)null); - }); - - modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.OrderAggregate.Order", b => - { - b.Property("Id") - .HasColumnType("char(36)"); - - b.Property("Count") - .HasColumnType("int"); - - b.Property("Name") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("varchar(100)"); - - b.Property("Paid") - .HasColumnType("tinyint(1)"); - - b.Property("RowVersion") - .IsConcurrencyToken() - .HasColumnType("int"); - - b.Property("UpdateTime") - .HasColumnType("datetime(6)"); - - b.HasKey("Id"); - - b.ToTable("order", (string)null); - }); #pragma warning restore 612, 618 } } diff --git a/template/src/ABC.Template.Infrastructure/MigrationsAll/PostgreSQL-net10.0-admin/20260122054753_Init.Designer.cs b/template/src/ABC.Template.Infrastructure/MigrationsAll/PostgreSQL-net10.0-admin/20260122054753_Init.Designer.cs new file mode 100644 index 00000000..72a4df24 --- /dev/null +++ b/template/src/ABC.Template.Infrastructure/MigrationsAll/PostgreSQL-net10.0-admin/20260122054753_Init.Designer.cs @@ -0,0 +1,440 @@ +// +using System; +using ABC.Template.Infrastructure; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace ABC.Template.Infrastructure.Migrations +{ + [DbContext(typeof(ApplicationDbContext))] + [Migration("20260122054753_Init")] + partial class Init + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "9.0.0") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.DeptAggregate.Dept", b => + { + b.Property("Id") + .HasColumnType("bigint"); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("DeletedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("character varying(100)"); + + b.Property("ParentId") + .HasColumnType("bigint"); + + b.Property("Remark") + .IsRequired() + .HasMaxLength(500) + .HasColumnType("character varying(500)"); + + b.Property("Status") + .HasColumnType("integer"); + + b.Property("UpdateTime") + .HasColumnType("timestamp with time zone"); + + b.HasKey("Id"); + + b.HasIndex("IsDeleted"); + + b.HasIndex("ParentId"); + + b.HasIndex("Status"); + + b.ToTable("dept", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.Role", b => + { + b.Property("Id") + .HasColumnType("uuid"); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("DeletedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("Description") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("character varying(200)"); + + b.Property("IsActive") + .HasColumnType("boolean"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("character varying(50)"); + + b.HasKey("Id"); + + b.HasIndex("Name") + .IsUnique(); + + b.ToTable("role", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.RolePermission", b => + { + b.Property("RoleId") + .HasColumnType("uuid"); + + b.Property("PermissionCode") + .HasMaxLength(100) + .HasColumnType("character varying(100)"); + + b.Property("PermissionDescription") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("character varying(200)"); + + b.Property("PermissionName") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("character varying(100)"); + + b.HasKey("RoleId", "PermissionCode"); + + b.ToTable("role_permission", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.User", b => + { + b.Property("Id") + .HasColumnType("bigint"); + + b.Property("Age") + .HasColumnType("integer"); + + b.Property("BirthDate") + .HasColumnType("timestamp with time zone"); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("DeletedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("Email") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("character varying(100)"); + + b.Property("Gender") + .IsRequired() + .HasMaxLength(10) + .HasColumnType("character varying(10)"); + + b.Property("IsActive") + .HasColumnType("boolean"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("LastLoginTime") + .HasColumnType("timestamp with time zone"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("character varying(50)"); + + b.Property("PasswordHash") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("character varying(255)"); + + b.Property("Phone") + .IsRequired() + .HasMaxLength(20) + .HasColumnType("character varying(20)"); + + b.Property("RealName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("character varying(50)"); + + b.Property("Status") + .HasColumnType("integer"); + + b.Property("UpdateTime") + .HasColumnType("timestamp with time zone"); + + b.HasKey("Id"); + + b.HasIndex("Email"); + + b.HasIndex("Name"); + + b.ToTable("user", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserDept", b => + { + b.Property("UserId") + .HasColumnType("bigint"); + + b.Property("AssignedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("DeptId") + .HasColumnType("bigint"); + + b.Property("DeptName") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("character varying(100)"); + + b.HasKey("UserId"); + + b.HasIndex("DeptId"); + + b.HasIndex("UserId"); + + b.ToTable("user_dept", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRefreshToken", b => + { + b.Property("Id") + .HasColumnType("bigint"); + + b.Property("CreatedTime") + .HasColumnType("timestamp with time zone"); + + b.Property("ExpiresTime") + .HasColumnType("timestamp with time zone"); + + b.Property("IsRevoked") + .HasColumnType("boolean"); + + b.Property("IsUsed") + .HasColumnType("boolean"); + + b.Property("Token") + .IsRequired() + .HasMaxLength(500) + .HasColumnType("character varying(500)"); + + b.Property("UserId") + .HasColumnType("bigint"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("user_refresh_token", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRole", b => + { + b.Property("UserId") + .HasColumnType("bigint"); + + b.Property("RoleId") + .HasColumnType("uuid"); + + b.Property("RoleName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("character varying(50)"); + + b.HasKey("UserId", "RoleId"); + + b.ToTable("user_role", (string)null); + }); + + modelBuilder.Entity("NetCorePal.Extensions.DistributedTransactions.CAP.Persistence.CapLock", b => + { + b.Property("Key") + .HasMaxLength(128) + .HasColumnType("character varying(128)"); + + b.Property("Instance") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.Property("LastLockTime") + .HasColumnType("TIMESTAMP"); + + b.HasKey("Key"); + + b.ToTable("CAPLock", (string)null); + }); + + modelBuilder.Entity("NetCorePal.Extensions.DistributedTransactions.CAP.Persistence.PublishedMessage", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Added") + .HasColumnType("TIMESTAMP"); + + b.Property("Content") + .HasColumnType("TEXT"); + + b.Property("ExpiresAt") + .HasColumnType("TIMESTAMP"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("character varying(200)"); + + b.Property("Retries") + .HasColumnType("integer"); + + b.Property("StatusName") + .IsRequired() + .HasMaxLength(40) + .HasColumnType("character varying(40)"); + + b.Property("Version") + .HasMaxLength(20) + .HasColumnType("character varying(20)"); + + b.HasKey("Id"); + + b.HasIndex(new[] { "ExpiresAt", "StatusName" }, "IX_ExpiresAt_StatusName"); + + b.HasIndex(new[] { "Version", "ExpiresAt", "StatusName" }, "IX_Version_ExpiresAt_StatusName"); + + b.ToTable("CAPPublishedMessage", (string)null); + }); + + modelBuilder.Entity("NetCorePal.Extensions.DistributedTransactions.CAP.Persistence.ReceivedMessage", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Added") + .HasColumnType("TIMESTAMP"); + + b.Property("Content") + .HasColumnType("TEXT"); + + b.Property("ExpiresAt") + .HasColumnType("TIMESTAMP"); + + b.Property("Group") + .HasMaxLength(200) + .HasColumnType("character varying(200)"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(400) + .HasColumnType("character varying(400)"); + + b.Property("Retries") + .HasColumnType("integer"); + + b.Property("StatusName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("character varying(50)"); + + b.Property("Version") + .HasMaxLength(20) + .HasColumnType("character varying(20)"); + + b.HasKey("Id"); + + b.HasIndex(new[] { "ExpiresAt", "StatusName" }, "IX_ExpiresAt_StatusName") + .HasDatabaseName("IX_ExpiresAt_StatusName1"); + + b.HasIndex(new[] { "Version", "ExpiresAt", "StatusName" }, "IX_Version_ExpiresAt_StatusName") + .HasDatabaseName("IX_Version_ExpiresAt_StatusName1"); + + b.ToTable("CAPReceivedMessage", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.RolePermission", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.RoleAggregate.Role", null) + .WithMany("Permissions") + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserDept", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.UserAggregate.User", null) + .WithOne("Dept") + .HasForeignKey("ABC.Template.Domain.AggregatesModel.UserAggregate.UserDept", "UserId") + .OnDelete(DeleteBehavior.ClientCascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRefreshToken", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.UserAggregate.User", null) + .WithMany("RefreshTokens") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRole", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.UserAggregate.User", null) + .WithMany("Roles") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.Role", b => + { + b.Navigation("Permissions"); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.User", b => + { + b.Navigation("Dept") + .IsRequired(); + + b.Navigation("RefreshTokens"); + + b.Navigation("Roles"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/template/src/ABC.Template.Infrastructure/MigrationsAll/PostgreSQL-net10.0-admin/20260122054753_Init.cs b/template/src/ABC.Template.Infrastructure/MigrationsAll/PostgreSQL-net10.0-admin/20260122054753_Init.cs new file mode 100644 index 00000000..b8f83d56 --- /dev/null +++ b/template/src/ABC.Template.Infrastructure/MigrationsAll/PostgreSQL-net10.0-admin/20260122054753_Init.cs @@ -0,0 +1,311 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace ABC.Template.Infrastructure.Migrations +{ + /// + public partial class Init : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "CAPLock", + columns: table => new + { + Key = table.Column(type: "character varying(128)", maxLength: 128, nullable: false), + Instance = table.Column(type: "character varying(256)", maxLength: 256, nullable: true), + LastLockTime = table.Column(type: "TIMESTAMP", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_CAPLock", x => x.Key); + }); + + migrationBuilder.CreateTable( + name: "CAPPublishedMessage", + columns: table => new + { + Id = table.Column(type: "bigint", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + Version = table.Column(type: "character varying(20)", maxLength: 20, nullable: true), + Name = table.Column(type: "character varying(200)", maxLength: 200, nullable: false), + Content = table.Column(type: "TEXT", nullable: true), + Retries = table.Column(type: "integer", nullable: true), + Added = table.Column(type: "TIMESTAMP", nullable: false), + ExpiresAt = table.Column(type: "TIMESTAMP", nullable: true), + StatusName = table.Column(type: "character varying(40)", maxLength: 40, nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_CAPPublishedMessage", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "CAPReceivedMessage", + columns: table => new + { + Id = table.Column(type: "bigint", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + Version = table.Column(type: "character varying(20)", maxLength: 20, nullable: true), + Name = table.Column(type: "character varying(400)", maxLength: 400, nullable: false), + Group = table.Column(type: "character varying(200)", maxLength: 200, nullable: true), + Content = table.Column(type: "TEXT", nullable: true), + Retries = table.Column(type: "integer", nullable: true), + Added = table.Column(type: "TIMESTAMP", nullable: false), + ExpiresAt = table.Column(type: "TIMESTAMP", nullable: true), + StatusName = table.Column(type: "character varying(50)", maxLength: 50, nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_CAPReceivedMessage", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "dept", + columns: table => new + { + Id = table.Column(type: "bigint", nullable: false), + Name = table.Column(type: "character varying(100)", maxLength: 100, nullable: false), + Remark = table.Column(type: "character varying(500)", maxLength: 500, nullable: false), + ParentId = table.Column(type: "bigint", nullable: false), + Status = table.Column(type: "integer", nullable: false), + CreatedAt = table.Column(type: "timestamp with time zone", nullable: false), + IsDeleted = table.Column(type: "boolean", nullable: false), + DeletedAt = table.Column(type: "timestamp with time zone", nullable: false), + UpdateTime = table.Column(type: "timestamp with time zone", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_dept", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "role", + columns: table => new + { + Id = table.Column(type: "uuid", nullable: false), + Name = table.Column(type: "character varying(50)", maxLength: 50, nullable: false), + Description = table.Column(type: "character varying(200)", maxLength: 200, nullable: false), + CreatedAt = table.Column(type: "timestamp with time zone", nullable: false), + IsActive = table.Column(type: "boolean", nullable: false), + IsDeleted = table.Column(type: "boolean", nullable: false), + DeletedAt = table.Column(type: "timestamp with time zone", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_role", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "user", + columns: table => new + { + Id = table.Column(type: "bigint", nullable: false), + Name = table.Column(type: "character varying(50)", maxLength: 50, nullable: false), + Email = table.Column(type: "character varying(100)", maxLength: 100, nullable: false), + Phone = table.Column(type: "character varying(20)", maxLength: 20, nullable: false), + RealName = table.Column(type: "character varying(50)", maxLength: 50, nullable: false), + Status = table.Column(type: "integer", nullable: false), + PasswordHash = table.Column(type: "character varying(255)", maxLength: 255, nullable: false), + IsActive = table.Column(type: "boolean", nullable: false), + CreatedAt = table.Column(type: "timestamp with time zone", nullable: false), + LastLoginTime = table.Column(type: "timestamp with time zone", nullable: true), + UpdateTime = table.Column(type: "timestamp with time zone", nullable: false), + IsDeleted = table.Column(type: "boolean", nullable: false), + DeletedAt = table.Column(type: "timestamp with time zone", nullable: false), + Gender = table.Column(type: "character varying(10)", maxLength: 10, nullable: false), + Age = table.Column(type: "integer", nullable: false), + BirthDate = table.Column(type: "timestamp with time zone", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_user", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "role_permission", + columns: table => new + { + RoleId = table.Column(type: "uuid", nullable: false), + PermissionCode = table.Column(type: "character varying(100)", maxLength: 100, nullable: false), + PermissionName = table.Column(type: "character varying(100)", maxLength: 100, nullable: false), + PermissionDescription = table.Column(type: "character varying(200)", maxLength: 200, nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_role_permission", x => new { x.RoleId, x.PermissionCode }); + table.ForeignKey( + name: "FK_role_permission_role_RoleId", + column: x => x.RoleId, + principalTable: "role", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "user_dept", + columns: table => new + { + UserId = table.Column(type: "bigint", nullable: false), + DeptId = table.Column(type: "bigint", nullable: false), + DeptName = table.Column(type: "character varying(100)", maxLength: 100, nullable: false), + AssignedAt = table.Column(type: "timestamp with time zone", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_user_dept", x => x.UserId); + table.ForeignKey( + name: "FK_user_dept_user_UserId", + column: x => x.UserId, + principalTable: "user", + principalColumn: "Id"); + }); + + migrationBuilder.CreateTable( + name: "user_refresh_token", + columns: table => new + { + Id = table.Column(type: "bigint", nullable: false), + UserId = table.Column(type: "bigint", nullable: false), + Token = table.Column(type: "character varying(500)", maxLength: 500, nullable: false), + CreatedTime = table.Column(type: "timestamp with time zone", nullable: false), + ExpiresTime = table.Column(type: "timestamp with time zone", nullable: false), + IsUsed = table.Column(type: "boolean", nullable: false), + IsRevoked = table.Column(type: "boolean", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_user_refresh_token", x => x.Id); + table.ForeignKey( + name: "FK_user_refresh_token_user_UserId", + column: x => x.UserId, + principalTable: "user", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "user_role", + columns: table => new + { + UserId = table.Column(type: "bigint", nullable: false), + RoleId = table.Column(type: "uuid", nullable: false), + RoleName = table.Column(type: "character varying(50)", maxLength: 50, nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_user_role", x => new { x.UserId, x.RoleId }); + table.ForeignKey( + name: "FK_user_role_user_UserId", + column: x => x.UserId, + principalTable: "user", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_ExpiresAt_StatusName", + table: "CAPPublishedMessage", + columns: new[] { "ExpiresAt", "StatusName" }); + + migrationBuilder.CreateIndex( + name: "IX_Version_ExpiresAt_StatusName", + table: "CAPPublishedMessage", + columns: new[] { "Version", "ExpiresAt", "StatusName" }); + + migrationBuilder.CreateIndex( + name: "IX_ExpiresAt_StatusName1", + table: "CAPReceivedMessage", + columns: new[] { "ExpiresAt", "StatusName" }); + + migrationBuilder.CreateIndex( + name: "IX_Version_ExpiresAt_StatusName1", + table: "CAPReceivedMessage", + columns: new[] { "Version", "ExpiresAt", "StatusName" }); + + migrationBuilder.CreateIndex( + name: "IX_dept_IsDeleted", + table: "dept", + column: "IsDeleted"); + + migrationBuilder.CreateIndex( + name: "IX_dept_ParentId", + table: "dept", + column: "ParentId"); + + migrationBuilder.CreateIndex( + name: "IX_dept_Status", + table: "dept", + column: "Status"); + + migrationBuilder.CreateIndex( + name: "IX_role_Name", + table: "role", + column: "Name", + unique: true); + + migrationBuilder.CreateIndex( + name: "IX_user_Email", + table: "user", + column: "Email"); + + migrationBuilder.CreateIndex( + name: "IX_user_Name", + table: "user", + column: "Name"); + + migrationBuilder.CreateIndex( + name: "IX_user_dept_DeptId", + table: "user_dept", + column: "DeptId"); + + migrationBuilder.CreateIndex( + name: "IX_user_dept_UserId", + table: "user_dept", + column: "UserId"); + + migrationBuilder.CreateIndex( + name: "IX_user_refresh_token_UserId", + table: "user_refresh_token", + column: "UserId"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "CAPLock"); + + migrationBuilder.DropTable( + name: "CAPPublishedMessage"); + + migrationBuilder.DropTable( + name: "CAPReceivedMessage"); + + migrationBuilder.DropTable( + name: "dept"); + + migrationBuilder.DropTable( + name: "role_permission"); + + migrationBuilder.DropTable( + name: "user_dept"); + + migrationBuilder.DropTable( + name: "user_refresh_token"); + + migrationBuilder.DropTable( + name: "user_role"); + + migrationBuilder.DropTable( + name: "role"); + + migrationBuilder.DropTable( + name: "user"); + } + } +} diff --git a/template/src/ABC.Template.Infrastructure/MigrationsAll/PostgreSQL-net10.0-admin/ApplicationDbContextModelSnapshot.cs b/template/src/ABC.Template.Infrastructure/MigrationsAll/PostgreSQL-net10.0-admin/ApplicationDbContextModelSnapshot.cs new file mode 100644 index 00000000..da544d51 --- /dev/null +++ b/template/src/ABC.Template.Infrastructure/MigrationsAll/PostgreSQL-net10.0-admin/ApplicationDbContextModelSnapshot.cs @@ -0,0 +1,437 @@ +// +using System; +using ABC.Template.Infrastructure; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace ABC.Template.Infrastructure.Migrations +{ + [DbContext(typeof(ApplicationDbContext))] + partial class ApplicationDbContextModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "9.0.0") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.DeptAggregate.Dept", b => + { + b.Property("Id") + .HasColumnType("bigint"); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("DeletedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("character varying(100)"); + + b.Property("ParentId") + .HasColumnType("bigint"); + + b.Property("Remark") + .IsRequired() + .HasMaxLength(500) + .HasColumnType("character varying(500)"); + + b.Property("Status") + .HasColumnType("integer"); + + b.Property("UpdateTime") + .HasColumnType("timestamp with time zone"); + + b.HasKey("Id"); + + b.HasIndex("IsDeleted"); + + b.HasIndex("ParentId"); + + b.HasIndex("Status"); + + b.ToTable("dept", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.Role", b => + { + b.Property("Id") + .HasColumnType("uuid"); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("DeletedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("Description") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("character varying(200)"); + + b.Property("IsActive") + .HasColumnType("boolean"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("character varying(50)"); + + b.HasKey("Id"); + + b.HasIndex("Name") + .IsUnique(); + + b.ToTable("role", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.RolePermission", b => + { + b.Property("RoleId") + .HasColumnType("uuid"); + + b.Property("PermissionCode") + .HasMaxLength(100) + .HasColumnType("character varying(100)"); + + b.Property("PermissionDescription") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("character varying(200)"); + + b.Property("PermissionName") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("character varying(100)"); + + b.HasKey("RoleId", "PermissionCode"); + + b.ToTable("role_permission", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.User", b => + { + b.Property("Id") + .HasColumnType("bigint"); + + b.Property("Age") + .HasColumnType("integer"); + + b.Property("BirthDate") + .HasColumnType("timestamp with time zone"); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("DeletedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("Email") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("character varying(100)"); + + b.Property("Gender") + .IsRequired() + .HasMaxLength(10) + .HasColumnType("character varying(10)"); + + b.Property("IsActive") + .HasColumnType("boolean"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("LastLoginTime") + .HasColumnType("timestamp with time zone"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("character varying(50)"); + + b.Property("PasswordHash") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("character varying(255)"); + + b.Property("Phone") + .IsRequired() + .HasMaxLength(20) + .HasColumnType("character varying(20)"); + + b.Property("RealName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("character varying(50)"); + + b.Property("Status") + .HasColumnType("integer"); + + b.Property("UpdateTime") + .HasColumnType("timestamp with time zone"); + + b.HasKey("Id"); + + b.HasIndex("Email"); + + b.HasIndex("Name"); + + b.ToTable("user", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserDept", b => + { + b.Property("UserId") + .HasColumnType("bigint"); + + b.Property("AssignedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("DeptId") + .HasColumnType("bigint"); + + b.Property("DeptName") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("character varying(100)"); + + b.HasKey("UserId"); + + b.HasIndex("DeptId"); + + b.HasIndex("UserId"); + + b.ToTable("user_dept", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRefreshToken", b => + { + b.Property("Id") + .HasColumnType("bigint"); + + b.Property("CreatedTime") + .HasColumnType("timestamp with time zone"); + + b.Property("ExpiresTime") + .HasColumnType("timestamp with time zone"); + + b.Property("IsRevoked") + .HasColumnType("boolean"); + + b.Property("IsUsed") + .HasColumnType("boolean"); + + b.Property("Token") + .IsRequired() + .HasMaxLength(500) + .HasColumnType("character varying(500)"); + + b.Property("UserId") + .HasColumnType("bigint"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("user_refresh_token", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRole", b => + { + b.Property("UserId") + .HasColumnType("bigint"); + + b.Property("RoleId") + .HasColumnType("uuid"); + + b.Property("RoleName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("character varying(50)"); + + b.HasKey("UserId", "RoleId"); + + b.ToTable("user_role", (string)null); + }); + + modelBuilder.Entity("NetCorePal.Extensions.DistributedTransactions.CAP.Persistence.CapLock", b => + { + b.Property("Key") + .HasMaxLength(128) + .HasColumnType("character varying(128)"); + + b.Property("Instance") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.Property("LastLockTime") + .HasColumnType("TIMESTAMP"); + + b.HasKey("Key"); + + b.ToTable("CAPLock", (string)null); + }); + + modelBuilder.Entity("NetCorePal.Extensions.DistributedTransactions.CAP.Persistence.PublishedMessage", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Added") + .HasColumnType("TIMESTAMP"); + + b.Property("Content") + .HasColumnType("TEXT"); + + b.Property("ExpiresAt") + .HasColumnType("TIMESTAMP"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("character varying(200)"); + + b.Property("Retries") + .HasColumnType("integer"); + + b.Property("StatusName") + .IsRequired() + .HasMaxLength(40) + .HasColumnType("character varying(40)"); + + b.Property("Version") + .HasMaxLength(20) + .HasColumnType("character varying(20)"); + + b.HasKey("Id"); + + b.HasIndex(new[] { "ExpiresAt", "StatusName" }, "IX_ExpiresAt_StatusName"); + + b.HasIndex(new[] { "Version", "ExpiresAt", "StatusName" }, "IX_Version_ExpiresAt_StatusName"); + + b.ToTable("CAPPublishedMessage", (string)null); + }); + + modelBuilder.Entity("NetCorePal.Extensions.DistributedTransactions.CAP.Persistence.ReceivedMessage", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Added") + .HasColumnType("TIMESTAMP"); + + b.Property("Content") + .HasColumnType("TEXT"); + + b.Property("ExpiresAt") + .HasColumnType("TIMESTAMP"); + + b.Property("Group") + .HasMaxLength(200) + .HasColumnType("character varying(200)"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(400) + .HasColumnType("character varying(400)"); + + b.Property("Retries") + .HasColumnType("integer"); + + b.Property("StatusName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("character varying(50)"); + + b.Property("Version") + .HasMaxLength(20) + .HasColumnType("character varying(20)"); + + b.HasKey("Id"); + + b.HasIndex(new[] { "ExpiresAt", "StatusName" }, "IX_ExpiresAt_StatusName") + .HasDatabaseName("IX_ExpiresAt_StatusName1"); + + b.HasIndex(new[] { "Version", "ExpiresAt", "StatusName" }, "IX_Version_ExpiresAt_StatusName") + .HasDatabaseName("IX_Version_ExpiresAt_StatusName1"); + + b.ToTable("CAPReceivedMessage", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.RolePermission", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.RoleAggregate.Role", null) + .WithMany("Permissions") + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserDept", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.UserAggregate.User", null) + .WithOne("Dept") + .HasForeignKey("ABC.Template.Domain.AggregatesModel.UserAggregate.UserDept", "UserId") + .OnDelete(DeleteBehavior.ClientCascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRefreshToken", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.UserAggregate.User", null) + .WithMany("RefreshTokens") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRole", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.UserAggregate.User", null) + .WithMany("Roles") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.Role", b => + { + b.Navigation("Permissions"); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.User", b => + { + b.Navigation("Dept") + .IsRequired(); + + b.Navigation("RefreshTokens"); + + b.Navigation("Roles"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/template/src/ABC.Template.Infrastructure/MigrationsAll/PostgreSQL-net9.0/20251225065100_Init.Designer.cs b/template/src/ABC.Template.Infrastructure/MigrationsAll/PostgreSQL-net10.0/20260122054728_Init.Designer.cs similarity index 78% rename from template/src/ABC.Template.Infrastructure/MigrationsAll/PostgreSQL-net9.0/20251225065100_Init.Designer.cs rename to template/src/ABC.Template.Infrastructure/MigrationsAll/PostgreSQL-net10.0/20260122054728_Init.Designer.cs index 8677ed1e..00673fcc 100644 --- a/template/src/ABC.Template.Infrastructure/MigrationsAll/PostgreSQL-net9.0/20251225065100_Init.Designer.cs +++ b/template/src/ABC.Template.Infrastructure/MigrationsAll/PostgreSQL-net10.0/20260122054728_Init.Designer.cs @@ -1,18 +1,18 @@ // using System; +using ABC.Template.Infrastructure; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; -using ABC.Template.Infrastructure; #nullable disable namespace ABC.Template.Infrastructure.Migrations { [DbContext(typeof(ApplicationDbContext))] - [Migration("20251225065100_Init")] + [Migration("20260122054728_Init")] partial class Init { /// @@ -134,47 +134,6 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.ToTable("CAPReceivedMessage", (string)null); }); - - modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.DeliverAggregate.DeliverRecord", b => - { - b.Property("Id") - .HasColumnType("uuid"); - - b.Property("OrderId") - .HasColumnType("uuid"); - - b.HasKey("Id"); - - b.ToTable("deliverrecord", (string)null); - }); - - modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.OrderAggregate.Order", b => - { - b.Property("Id") - .HasColumnType("uuid"); - - b.Property("Count") - .HasColumnType("integer"); - - b.Property("Name") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("character varying(100)"); - - b.Property("Paid") - .HasColumnType("boolean"); - - b.Property("RowVersion") - .IsConcurrencyToken() - .HasColumnType("integer"); - - b.Property("UpdateTime") - .HasColumnType("timestamp with time zone"); - - b.HasKey("Id"); - - b.ToTable("order", (string)null); - }); #pragma warning restore 612, 618 } } diff --git a/template/src/ABC.Template.Infrastructure/MigrationsAll/PostgreSQL-net8.0/20251225065050_Init.cs b/template/src/ABC.Template.Infrastructure/MigrationsAll/PostgreSQL-net10.0/20260122054728_Init.cs similarity index 76% rename from template/src/ABC.Template.Infrastructure/MigrationsAll/PostgreSQL-net8.0/20251225065050_Init.cs rename to template/src/ABC.Template.Infrastructure/MigrationsAll/PostgreSQL-net10.0/20260122054728_Init.cs index 994de8c5..68029fcc 100644 --- a/template/src/ABC.Template.Infrastructure/MigrationsAll/PostgreSQL-net8.0/20251225065050_Init.cs +++ b/template/src/ABC.Template.Infrastructure/MigrationsAll/PostgreSQL-net10.0/20260122054728_Init.cs @@ -64,34 +64,6 @@ protected override void Up(MigrationBuilder migrationBuilder) table.PrimaryKey("PK_CAPReceivedMessage", x => x.Id); }); - migrationBuilder.CreateTable( - name: "deliverrecord", - columns: table => new - { - Id = table.Column(type: "uuid", nullable: false), - OrderId = table.Column(type: "uuid", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_deliverrecord", x => x.Id); - }); - - migrationBuilder.CreateTable( - name: "order", - columns: table => new - { - Id = table.Column(type: "uuid", nullable: false), - Paid = table.Column(type: "boolean", nullable: false), - Name = table.Column(type: "character varying(100)", maxLength: 100, nullable: false), - Count = table.Column(type: "integer", nullable: false), - RowVersion = table.Column(type: "integer", nullable: false), - UpdateTime = table.Column(type: "timestamp with time zone", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_order", x => x.Id); - }); - migrationBuilder.CreateIndex( name: "IX_ExpiresAt_StatusName", table: "CAPPublishedMessage", @@ -124,12 +96,6 @@ protected override void Down(MigrationBuilder migrationBuilder) migrationBuilder.DropTable( name: "CAPReceivedMessage"); - - migrationBuilder.DropTable( - name: "deliverrecord"); - - migrationBuilder.DropTable( - name: "order"); } } } diff --git a/template/src/ABC.Template.Infrastructure/MigrationsAll/PostgreSQL-net10.0/ApplicationDbContextModelSnapshot.cs b/template/src/ABC.Template.Infrastructure/MigrationsAll/PostgreSQL-net10.0/ApplicationDbContextModelSnapshot.cs index b33fd3aa..b914d406 100644 --- a/template/src/ABC.Template.Infrastructure/MigrationsAll/PostgreSQL-net10.0/ApplicationDbContextModelSnapshot.cs +++ b/template/src/ABC.Template.Infrastructure/MigrationsAll/PostgreSQL-net10.0/ApplicationDbContextModelSnapshot.cs @@ -1,10 +1,10 @@ // using System; +using ABC.Template.Infrastructure; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; -using ABC.Template.Infrastructure; #nullable disable @@ -131,47 +131,6 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.ToTable("CAPReceivedMessage", (string)null); }); - - modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.DeliverAggregate.DeliverRecord", b => - { - b.Property("Id") - .HasColumnType("uuid"); - - b.Property("OrderId") - .HasColumnType("uuid"); - - b.HasKey("Id"); - - b.ToTable("deliverrecord", (string)null); - }); - - modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.OrderAggregate.Order", b => - { - b.Property("Id") - .HasColumnType("uuid"); - - b.Property("Count") - .HasColumnType("integer"); - - b.Property("Name") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("character varying(100)"); - - b.Property("Paid") - .HasColumnType("boolean"); - - b.Property("RowVersion") - .IsConcurrencyToken() - .HasColumnType("integer"); - - b.Property("UpdateTime") - .HasColumnType("timestamp with time zone"); - - b.HasKey("Id"); - - b.ToTable("order", (string)null); - }); #pragma warning restore 612, 618 } } diff --git a/template/src/ABC.Template.Infrastructure/MigrationsAll/PostgreSQL-net8.0-admin/20260122054629_Init.Designer.cs b/template/src/ABC.Template.Infrastructure/MigrationsAll/PostgreSQL-net8.0-admin/20260122054629_Init.Designer.cs new file mode 100644 index 00000000..61ab7bbf --- /dev/null +++ b/template/src/ABC.Template.Infrastructure/MigrationsAll/PostgreSQL-net8.0-admin/20260122054629_Init.Designer.cs @@ -0,0 +1,440 @@ +// +using System; +using ABC.Template.Infrastructure; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace ABC.Template.Infrastructure.Migrations +{ + [DbContext(typeof(ApplicationDbContext))] + [Migration("20260122054629_Init")] + partial class Init + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "8.0.10") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.DeptAggregate.Dept", b => + { + b.Property("Id") + .HasColumnType("bigint"); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("DeletedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("character varying(100)"); + + b.Property("ParentId") + .HasColumnType("bigint"); + + b.Property("Remark") + .IsRequired() + .HasMaxLength(500) + .HasColumnType("character varying(500)"); + + b.Property("Status") + .HasColumnType("integer"); + + b.Property("UpdateTime") + .HasColumnType("timestamp with time zone"); + + b.HasKey("Id"); + + b.HasIndex("IsDeleted"); + + b.HasIndex("ParentId"); + + b.HasIndex("Status"); + + b.ToTable("dept", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.Role", b => + { + b.Property("Id") + .HasColumnType("uuid"); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("DeletedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("Description") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("character varying(200)"); + + b.Property("IsActive") + .HasColumnType("boolean"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("character varying(50)"); + + b.HasKey("Id"); + + b.HasIndex("Name") + .IsUnique(); + + b.ToTable("role", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.RolePermission", b => + { + b.Property("RoleId") + .HasColumnType("uuid"); + + b.Property("PermissionCode") + .HasMaxLength(100) + .HasColumnType("character varying(100)"); + + b.Property("PermissionDescription") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("character varying(200)"); + + b.Property("PermissionName") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("character varying(100)"); + + b.HasKey("RoleId", "PermissionCode"); + + b.ToTable("role_permission", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.User", b => + { + b.Property("Id") + .HasColumnType("bigint"); + + b.Property("Age") + .HasColumnType("integer"); + + b.Property("BirthDate") + .HasColumnType("timestamp with time zone"); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("DeletedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("Email") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("character varying(100)"); + + b.Property("Gender") + .IsRequired() + .HasMaxLength(10) + .HasColumnType("character varying(10)"); + + b.Property("IsActive") + .HasColumnType("boolean"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("LastLoginTime") + .HasColumnType("timestamp with time zone"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("character varying(50)"); + + b.Property("PasswordHash") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("character varying(255)"); + + b.Property("Phone") + .IsRequired() + .HasMaxLength(20) + .HasColumnType("character varying(20)"); + + b.Property("RealName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("character varying(50)"); + + b.Property("Status") + .HasColumnType("integer"); + + b.Property("UpdateTime") + .HasColumnType("timestamp with time zone"); + + b.HasKey("Id"); + + b.HasIndex("Email"); + + b.HasIndex("Name"); + + b.ToTable("user", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserDept", b => + { + b.Property("UserId") + .HasColumnType("bigint"); + + b.Property("AssignedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("DeptId") + .HasColumnType("bigint"); + + b.Property("DeptName") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("character varying(100)"); + + b.HasKey("UserId"); + + b.HasIndex("DeptId"); + + b.HasIndex("UserId"); + + b.ToTable("user_dept", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRefreshToken", b => + { + b.Property("Id") + .HasColumnType("bigint"); + + b.Property("CreatedTime") + .HasColumnType("timestamp with time zone"); + + b.Property("ExpiresTime") + .HasColumnType("timestamp with time zone"); + + b.Property("IsRevoked") + .HasColumnType("boolean"); + + b.Property("IsUsed") + .HasColumnType("boolean"); + + b.Property("Token") + .IsRequired() + .HasMaxLength(500) + .HasColumnType("character varying(500)"); + + b.Property("UserId") + .HasColumnType("bigint"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("user_refresh_token", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRole", b => + { + b.Property("UserId") + .HasColumnType("bigint"); + + b.Property("RoleId") + .HasColumnType("uuid"); + + b.Property("RoleName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("character varying(50)"); + + b.HasKey("UserId", "RoleId"); + + b.ToTable("user_role", (string)null); + }); + + modelBuilder.Entity("NetCorePal.Extensions.DistributedTransactions.CAP.Persistence.CapLock", b => + { + b.Property("Key") + .HasMaxLength(128) + .HasColumnType("character varying(128)"); + + b.Property("Instance") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.Property("LastLockTime") + .HasColumnType("TIMESTAMP"); + + b.HasKey("Key"); + + b.ToTable("CAPLock", (string)null); + }); + + modelBuilder.Entity("NetCorePal.Extensions.DistributedTransactions.CAP.Persistence.PublishedMessage", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Added") + .HasColumnType("TIMESTAMP"); + + b.Property("Content") + .HasColumnType("TEXT"); + + b.Property("ExpiresAt") + .HasColumnType("TIMESTAMP"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("character varying(200)"); + + b.Property("Retries") + .HasColumnType("integer"); + + b.Property("StatusName") + .IsRequired() + .HasMaxLength(40) + .HasColumnType("character varying(40)"); + + b.Property("Version") + .HasMaxLength(20) + .HasColumnType("character varying(20)"); + + b.HasKey("Id"); + + b.HasIndex(new[] { "ExpiresAt", "StatusName" }, "IX_ExpiresAt_StatusName"); + + b.HasIndex(new[] { "Version", "ExpiresAt", "StatusName" }, "IX_Version_ExpiresAt_StatusName"); + + b.ToTable("CAPPublishedMessage", (string)null); + }); + + modelBuilder.Entity("NetCorePal.Extensions.DistributedTransactions.CAP.Persistence.ReceivedMessage", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Added") + .HasColumnType("TIMESTAMP"); + + b.Property("Content") + .HasColumnType("TEXT"); + + b.Property("ExpiresAt") + .HasColumnType("TIMESTAMP"); + + b.Property("Group") + .HasMaxLength(200) + .HasColumnType("character varying(200)"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(400) + .HasColumnType("character varying(400)"); + + b.Property("Retries") + .HasColumnType("integer"); + + b.Property("StatusName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("character varying(50)"); + + b.Property("Version") + .HasMaxLength(20) + .HasColumnType("character varying(20)"); + + b.HasKey("Id"); + + b.HasIndex(new[] { "ExpiresAt", "StatusName" }, "IX_ExpiresAt_StatusName") + .HasDatabaseName("IX_ExpiresAt_StatusName1"); + + b.HasIndex(new[] { "Version", "ExpiresAt", "StatusName" }, "IX_Version_ExpiresAt_StatusName") + .HasDatabaseName("IX_Version_ExpiresAt_StatusName1"); + + b.ToTable("CAPReceivedMessage", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.RolePermission", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.RoleAggregate.Role", null) + .WithMany("Permissions") + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserDept", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.UserAggregate.User", null) + .WithOne("Dept") + .HasForeignKey("ABC.Template.Domain.AggregatesModel.UserAggregate.UserDept", "UserId") + .OnDelete(DeleteBehavior.ClientCascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRefreshToken", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.UserAggregate.User", null) + .WithMany("RefreshTokens") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRole", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.UserAggregate.User", null) + .WithMany("Roles") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.Role", b => + { + b.Navigation("Permissions"); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.User", b => + { + b.Navigation("Dept") + .IsRequired(); + + b.Navigation("RefreshTokens"); + + b.Navigation("Roles"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/template/src/ABC.Template.Infrastructure/MigrationsAll/PostgreSQL-net8.0-admin/20260122054629_Init.cs b/template/src/ABC.Template.Infrastructure/MigrationsAll/PostgreSQL-net8.0-admin/20260122054629_Init.cs new file mode 100644 index 00000000..b8f83d56 --- /dev/null +++ b/template/src/ABC.Template.Infrastructure/MigrationsAll/PostgreSQL-net8.0-admin/20260122054629_Init.cs @@ -0,0 +1,311 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace ABC.Template.Infrastructure.Migrations +{ + /// + public partial class Init : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "CAPLock", + columns: table => new + { + Key = table.Column(type: "character varying(128)", maxLength: 128, nullable: false), + Instance = table.Column(type: "character varying(256)", maxLength: 256, nullable: true), + LastLockTime = table.Column(type: "TIMESTAMP", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_CAPLock", x => x.Key); + }); + + migrationBuilder.CreateTable( + name: "CAPPublishedMessage", + columns: table => new + { + Id = table.Column(type: "bigint", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + Version = table.Column(type: "character varying(20)", maxLength: 20, nullable: true), + Name = table.Column(type: "character varying(200)", maxLength: 200, nullable: false), + Content = table.Column(type: "TEXT", nullable: true), + Retries = table.Column(type: "integer", nullable: true), + Added = table.Column(type: "TIMESTAMP", nullable: false), + ExpiresAt = table.Column(type: "TIMESTAMP", nullable: true), + StatusName = table.Column(type: "character varying(40)", maxLength: 40, nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_CAPPublishedMessage", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "CAPReceivedMessage", + columns: table => new + { + Id = table.Column(type: "bigint", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + Version = table.Column(type: "character varying(20)", maxLength: 20, nullable: true), + Name = table.Column(type: "character varying(400)", maxLength: 400, nullable: false), + Group = table.Column(type: "character varying(200)", maxLength: 200, nullable: true), + Content = table.Column(type: "TEXT", nullable: true), + Retries = table.Column(type: "integer", nullable: true), + Added = table.Column(type: "TIMESTAMP", nullable: false), + ExpiresAt = table.Column(type: "TIMESTAMP", nullable: true), + StatusName = table.Column(type: "character varying(50)", maxLength: 50, nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_CAPReceivedMessage", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "dept", + columns: table => new + { + Id = table.Column(type: "bigint", nullable: false), + Name = table.Column(type: "character varying(100)", maxLength: 100, nullable: false), + Remark = table.Column(type: "character varying(500)", maxLength: 500, nullable: false), + ParentId = table.Column(type: "bigint", nullable: false), + Status = table.Column(type: "integer", nullable: false), + CreatedAt = table.Column(type: "timestamp with time zone", nullable: false), + IsDeleted = table.Column(type: "boolean", nullable: false), + DeletedAt = table.Column(type: "timestamp with time zone", nullable: false), + UpdateTime = table.Column(type: "timestamp with time zone", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_dept", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "role", + columns: table => new + { + Id = table.Column(type: "uuid", nullable: false), + Name = table.Column(type: "character varying(50)", maxLength: 50, nullable: false), + Description = table.Column(type: "character varying(200)", maxLength: 200, nullable: false), + CreatedAt = table.Column(type: "timestamp with time zone", nullable: false), + IsActive = table.Column(type: "boolean", nullable: false), + IsDeleted = table.Column(type: "boolean", nullable: false), + DeletedAt = table.Column(type: "timestamp with time zone", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_role", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "user", + columns: table => new + { + Id = table.Column(type: "bigint", nullable: false), + Name = table.Column(type: "character varying(50)", maxLength: 50, nullable: false), + Email = table.Column(type: "character varying(100)", maxLength: 100, nullable: false), + Phone = table.Column(type: "character varying(20)", maxLength: 20, nullable: false), + RealName = table.Column(type: "character varying(50)", maxLength: 50, nullable: false), + Status = table.Column(type: "integer", nullable: false), + PasswordHash = table.Column(type: "character varying(255)", maxLength: 255, nullable: false), + IsActive = table.Column(type: "boolean", nullable: false), + CreatedAt = table.Column(type: "timestamp with time zone", nullable: false), + LastLoginTime = table.Column(type: "timestamp with time zone", nullable: true), + UpdateTime = table.Column(type: "timestamp with time zone", nullable: false), + IsDeleted = table.Column(type: "boolean", nullable: false), + DeletedAt = table.Column(type: "timestamp with time zone", nullable: false), + Gender = table.Column(type: "character varying(10)", maxLength: 10, nullable: false), + Age = table.Column(type: "integer", nullable: false), + BirthDate = table.Column(type: "timestamp with time zone", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_user", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "role_permission", + columns: table => new + { + RoleId = table.Column(type: "uuid", nullable: false), + PermissionCode = table.Column(type: "character varying(100)", maxLength: 100, nullable: false), + PermissionName = table.Column(type: "character varying(100)", maxLength: 100, nullable: false), + PermissionDescription = table.Column(type: "character varying(200)", maxLength: 200, nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_role_permission", x => new { x.RoleId, x.PermissionCode }); + table.ForeignKey( + name: "FK_role_permission_role_RoleId", + column: x => x.RoleId, + principalTable: "role", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "user_dept", + columns: table => new + { + UserId = table.Column(type: "bigint", nullable: false), + DeptId = table.Column(type: "bigint", nullable: false), + DeptName = table.Column(type: "character varying(100)", maxLength: 100, nullable: false), + AssignedAt = table.Column(type: "timestamp with time zone", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_user_dept", x => x.UserId); + table.ForeignKey( + name: "FK_user_dept_user_UserId", + column: x => x.UserId, + principalTable: "user", + principalColumn: "Id"); + }); + + migrationBuilder.CreateTable( + name: "user_refresh_token", + columns: table => new + { + Id = table.Column(type: "bigint", nullable: false), + UserId = table.Column(type: "bigint", nullable: false), + Token = table.Column(type: "character varying(500)", maxLength: 500, nullable: false), + CreatedTime = table.Column(type: "timestamp with time zone", nullable: false), + ExpiresTime = table.Column(type: "timestamp with time zone", nullable: false), + IsUsed = table.Column(type: "boolean", nullable: false), + IsRevoked = table.Column(type: "boolean", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_user_refresh_token", x => x.Id); + table.ForeignKey( + name: "FK_user_refresh_token_user_UserId", + column: x => x.UserId, + principalTable: "user", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "user_role", + columns: table => new + { + UserId = table.Column(type: "bigint", nullable: false), + RoleId = table.Column(type: "uuid", nullable: false), + RoleName = table.Column(type: "character varying(50)", maxLength: 50, nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_user_role", x => new { x.UserId, x.RoleId }); + table.ForeignKey( + name: "FK_user_role_user_UserId", + column: x => x.UserId, + principalTable: "user", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_ExpiresAt_StatusName", + table: "CAPPublishedMessage", + columns: new[] { "ExpiresAt", "StatusName" }); + + migrationBuilder.CreateIndex( + name: "IX_Version_ExpiresAt_StatusName", + table: "CAPPublishedMessage", + columns: new[] { "Version", "ExpiresAt", "StatusName" }); + + migrationBuilder.CreateIndex( + name: "IX_ExpiresAt_StatusName1", + table: "CAPReceivedMessage", + columns: new[] { "ExpiresAt", "StatusName" }); + + migrationBuilder.CreateIndex( + name: "IX_Version_ExpiresAt_StatusName1", + table: "CAPReceivedMessage", + columns: new[] { "Version", "ExpiresAt", "StatusName" }); + + migrationBuilder.CreateIndex( + name: "IX_dept_IsDeleted", + table: "dept", + column: "IsDeleted"); + + migrationBuilder.CreateIndex( + name: "IX_dept_ParentId", + table: "dept", + column: "ParentId"); + + migrationBuilder.CreateIndex( + name: "IX_dept_Status", + table: "dept", + column: "Status"); + + migrationBuilder.CreateIndex( + name: "IX_role_Name", + table: "role", + column: "Name", + unique: true); + + migrationBuilder.CreateIndex( + name: "IX_user_Email", + table: "user", + column: "Email"); + + migrationBuilder.CreateIndex( + name: "IX_user_Name", + table: "user", + column: "Name"); + + migrationBuilder.CreateIndex( + name: "IX_user_dept_DeptId", + table: "user_dept", + column: "DeptId"); + + migrationBuilder.CreateIndex( + name: "IX_user_dept_UserId", + table: "user_dept", + column: "UserId"); + + migrationBuilder.CreateIndex( + name: "IX_user_refresh_token_UserId", + table: "user_refresh_token", + column: "UserId"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "CAPLock"); + + migrationBuilder.DropTable( + name: "CAPPublishedMessage"); + + migrationBuilder.DropTable( + name: "CAPReceivedMessage"); + + migrationBuilder.DropTable( + name: "dept"); + + migrationBuilder.DropTable( + name: "role_permission"); + + migrationBuilder.DropTable( + name: "user_dept"); + + migrationBuilder.DropTable( + name: "user_refresh_token"); + + migrationBuilder.DropTable( + name: "user_role"); + + migrationBuilder.DropTable( + name: "role"); + + migrationBuilder.DropTable( + name: "user"); + } + } +} diff --git a/template/src/ABC.Template.Infrastructure/MigrationsAll/PostgreSQL-net8.0-admin/ApplicationDbContextModelSnapshot.cs b/template/src/ABC.Template.Infrastructure/MigrationsAll/PostgreSQL-net8.0-admin/ApplicationDbContextModelSnapshot.cs new file mode 100644 index 00000000..0107e74a --- /dev/null +++ b/template/src/ABC.Template.Infrastructure/MigrationsAll/PostgreSQL-net8.0-admin/ApplicationDbContextModelSnapshot.cs @@ -0,0 +1,437 @@ +// +using System; +using ABC.Template.Infrastructure; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace ABC.Template.Infrastructure.Migrations +{ + [DbContext(typeof(ApplicationDbContext))] + partial class ApplicationDbContextModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "8.0.10") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.DeptAggregate.Dept", b => + { + b.Property("Id") + .HasColumnType("bigint"); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("DeletedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("character varying(100)"); + + b.Property("ParentId") + .HasColumnType("bigint"); + + b.Property("Remark") + .IsRequired() + .HasMaxLength(500) + .HasColumnType("character varying(500)"); + + b.Property("Status") + .HasColumnType("integer"); + + b.Property("UpdateTime") + .HasColumnType("timestamp with time zone"); + + b.HasKey("Id"); + + b.HasIndex("IsDeleted"); + + b.HasIndex("ParentId"); + + b.HasIndex("Status"); + + b.ToTable("dept", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.Role", b => + { + b.Property("Id") + .HasColumnType("uuid"); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("DeletedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("Description") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("character varying(200)"); + + b.Property("IsActive") + .HasColumnType("boolean"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("character varying(50)"); + + b.HasKey("Id"); + + b.HasIndex("Name") + .IsUnique(); + + b.ToTable("role", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.RolePermission", b => + { + b.Property("RoleId") + .HasColumnType("uuid"); + + b.Property("PermissionCode") + .HasMaxLength(100) + .HasColumnType("character varying(100)"); + + b.Property("PermissionDescription") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("character varying(200)"); + + b.Property("PermissionName") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("character varying(100)"); + + b.HasKey("RoleId", "PermissionCode"); + + b.ToTable("role_permission", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.User", b => + { + b.Property("Id") + .HasColumnType("bigint"); + + b.Property("Age") + .HasColumnType("integer"); + + b.Property("BirthDate") + .HasColumnType("timestamp with time zone"); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("DeletedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("Email") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("character varying(100)"); + + b.Property("Gender") + .IsRequired() + .HasMaxLength(10) + .HasColumnType("character varying(10)"); + + b.Property("IsActive") + .HasColumnType("boolean"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("LastLoginTime") + .HasColumnType("timestamp with time zone"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("character varying(50)"); + + b.Property("PasswordHash") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("character varying(255)"); + + b.Property("Phone") + .IsRequired() + .HasMaxLength(20) + .HasColumnType("character varying(20)"); + + b.Property("RealName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("character varying(50)"); + + b.Property("Status") + .HasColumnType("integer"); + + b.Property("UpdateTime") + .HasColumnType("timestamp with time zone"); + + b.HasKey("Id"); + + b.HasIndex("Email"); + + b.HasIndex("Name"); + + b.ToTable("user", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserDept", b => + { + b.Property("UserId") + .HasColumnType("bigint"); + + b.Property("AssignedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("DeptId") + .HasColumnType("bigint"); + + b.Property("DeptName") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("character varying(100)"); + + b.HasKey("UserId"); + + b.HasIndex("DeptId"); + + b.HasIndex("UserId"); + + b.ToTable("user_dept", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRefreshToken", b => + { + b.Property("Id") + .HasColumnType("bigint"); + + b.Property("CreatedTime") + .HasColumnType("timestamp with time zone"); + + b.Property("ExpiresTime") + .HasColumnType("timestamp with time zone"); + + b.Property("IsRevoked") + .HasColumnType("boolean"); + + b.Property("IsUsed") + .HasColumnType("boolean"); + + b.Property("Token") + .IsRequired() + .HasMaxLength(500) + .HasColumnType("character varying(500)"); + + b.Property("UserId") + .HasColumnType("bigint"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("user_refresh_token", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRole", b => + { + b.Property("UserId") + .HasColumnType("bigint"); + + b.Property("RoleId") + .HasColumnType("uuid"); + + b.Property("RoleName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("character varying(50)"); + + b.HasKey("UserId", "RoleId"); + + b.ToTable("user_role", (string)null); + }); + + modelBuilder.Entity("NetCorePal.Extensions.DistributedTransactions.CAP.Persistence.CapLock", b => + { + b.Property("Key") + .HasMaxLength(128) + .HasColumnType("character varying(128)"); + + b.Property("Instance") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.Property("LastLockTime") + .HasColumnType("TIMESTAMP"); + + b.HasKey("Key"); + + b.ToTable("CAPLock", (string)null); + }); + + modelBuilder.Entity("NetCorePal.Extensions.DistributedTransactions.CAP.Persistence.PublishedMessage", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Added") + .HasColumnType("TIMESTAMP"); + + b.Property("Content") + .HasColumnType("TEXT"); + + b.Property("ExpiresAt") + .HasColumnType("TIMESTAMP"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("character varying(200)"); + + b.Property("Retries") + .HasColumnType("integer"); + + b.Property("StatusName") + .IsRequired() + .HasMaxLength(40) + .HasColumnType("character varying(40)"); + + b.Property("Version") + .HasMaxLength(20) + .HasColumnType("character varying(20)"); + + b.HasKey("Id"); + + b.HasIndex(new[] { "ExpiresAt", "StatusName" }, "IX_ExpiresAt_StatusName"); + + b.HasIndex(new[] { "Version", "ExpiresAt", "StatusName" }, "IX_Version_ExpiresAt_StatusName"); + + b.ToTable("CAPPublishedMessage", (string)null); + }); + + modelBuilder.Entity("NetCorePal.Extensions.DistributedTransactions.CAP.Persistence.ReceivedMessage", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Added") + .HasColumnType("TIMESTAMP"); + + b.Property("Content") + .HasColumnType("TEXT"); + + b.Property("ExpiresAt") + .HasColumnType("TIMESTAMP"); + + b.Property("Group") + .HasMaxLength(200) + .HasColumnType("character varying(200)"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(400) + .HasColumnType("character varying(400)"); + + b.Property("Retries") + .HasColumnType("integer"); + + b.Property("StatusName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("character varying(50)"); + + b.Property("Version") + .HasMaxLength(20) + .HasColumnType("character varying(20)"); + + b.HasKey("Id"); + + b.HasIndex(new[] { "ExpiresAt", "StatusName" }, "IX_ExpiresAt_StatusName") + .HasDatabaseName("IX_ExpiresAt_StatusName1"); + + b.HasIndex(new[] { "Version", "ExpiresAt", "StatusName" }, "IX_Version_ExpiresAt_StatusName") + .HasDatabaseName("IX_Version_ExpiresAt_StatusName1"); + + b.ToTable("CAPReceivedMessage", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.RolePermission", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.RoleAggregate.Role", null) + .WithMany("Permissions") + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserDept", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.UserAggregate.User", null) + .WithOne("Dept") + .HasForeignKey("ABC.Template.Domain.AggregatesModel.UserAggregate.UserDept", "UserId") + .OnDelete(DeleteBehavior.ClientCascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRefreshToken", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.UserAggregate.User", null) + .WithMany("RefreshTokens") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRole", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.UserAggregate.User", null) + .WithMany("Roles") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.Role", b => + { + b.Navigation("Permissions"); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.User", b => + { + b.Navigation("Dept") + .IsRequired(); + + b.Navigation("RefreshTokens"); + + b.Navigation("Roles"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/template/src/ABC.Template.Infrastructure/MigrationsAll/PostgreSQL-net8.0/20251225065050_Init.Designer.cs b/template/src/ABC.Template.Infrastructure/MigrationsAll/PostgreSQL-net8.0/20260122054614_Init.Designer.cs similarity index 78% rename from template/src/ABC.Template.Infrastructure/MigrationsAll/PostgreSQL-net8.0/20251225065050_Init.Designer.cs rename to template/src/ABC.Template.Infrastructure/MigrationsAll/PostgreSQL-net8.0/20260122054614_Init.Designer.cs index 2f4902a0..8e29b971 100644 --- a/template/src/ABC.Template.Infrastructure/MigrationsAll/PostgreSQL-net8.0/20251225065050_Init.Designer.cs +++ b/template/src/ABC.Template.Infrastructure/MigrationsAll/PostgreSQL-net8.0/20260122054614_Init.Designer.cs @@ -1,18 +1,18 @@ // using System; +using ABC.Template.Infrastructure; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; -using ABC.Template.Infrastructure; #nullable disable namespace ABC.Template.Infrastructure.Migrations { [DbContext(typeof(ApplicationDbContext))] - [Migration("20251225065050_Init")] + [Migration("20260122054614_Init")] partial class Init { /// @@ -134,47 +134,6 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.ToTable("CAPReceivedMessage", (string)null); }); - - modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.DeliverAggregate.DeliverRecord", b => - { - b.Property("Id") - .HasColumnType("uuid"); - - b.Property("OrderId") - .HasColumnType("uuid"); - - b.HasKey("Id"); - - b.ToTable("deliverrecord", (string)null); - }); - - modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.OrderAggregate.Order", b => - { - b.Property("Id") - .HasColumnType("uuid"); - - b.Property("Count") - .HasColumnType("integer"); - - b.Property("Name") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("character varying(100)"); - - b.Property("Paid") - .HasColumnType("boolean"); - - b.Property("RowVersion") - .IsConcurrencyToken() - .HasColumnType("integer"); - - b.Property("UpdateTime") - .HasColumnType("timestamp with time zone"); - - b.HasKey("Id"); - - b.ToTable("order", (string)null); - }); #pragma warning restore 612, 618 } } diff --git a/template/src/ABC.Template.Infrastructure/MigrationsAll/PostgreSQL-net9.0/20251225065100_Init.cs b/template/src/ABC.Template.Infrastructure/MigrationsAll/PostgreSQL-net8.0/20260122054614_Init.cs similarity index 76% rename from template/src/ABC.Template.Infrastructure/MigrationsAll/PostgreSQL-net9.0/20251225065100_Init.cs rename to template/src/ABC.Template.Infrastructure/MigrationsAll/PostgreSQL-net8.0/20260122054614_Init.cs index 994de8c5..68029fcc 100644 --- a/template/src/ABC.Template.Infrastructure/MigrationsAll/PostgreSQL-net9.0/20251225065100_Init.cs +++ b/template/src/ABC.Template.Infrastructure/MigrationsAll/PostgreSQL-net8.0/20260122054614_Init.cs @@ -64,34 +64,6 @@ protected override void Up(MigrationBuilder migrationBuilder) table.PrimaryKey("PK_CAPReceivedMessage", x => x.Id); }); - migrationBuilder.CreateTable( - name: "deliverrecord", - columns: table => new - { - Id = table.Column(type: "uuid", nullable: false), - OrderId = table.Column(type: "uuid", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_deliverrecord", x => x.Id); - }); - - migrationBuilder.CreateTable( - name: "order", - columns: table => new - { - Id = table.Column(type: "uuid", nullable: false), - Paid = table.Column(type: "boolean", nullable: false), - Name = table.Column(type: "character varying(100)", maxLength: 100, nullable: false), - Count = table.Column(type: "integer", nullable: false), - RowVersion = table.Column(type: "integer", nullable: false), - UpdateTime = table.Column(type: "timestamp with time zone", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_order", x => x.Id); - }); - migrationBuilder.CreateIndex( name: "IX_ExpiresAt_StatusName", table: "CAPPublishedMessage", @@ -124,12 +96,6 @@ protected override void Down(MigrationBuilder migrationBuilder) migrationBuilder.DropTable( name: "CAPReceivedMessage"); - - migrationBuilder.DropTable( - name: "deliverrecord"); - - migrationBuilder.DropTable( - name: "order"); } } } diff --git a/template/src/ABC.Template.Infrastructure/MigrationsAll/PostgreSQL-net8.0/ApplicationDbContextModelSnapshot.cs b/template/src/ABC.Template.Infrastructure/MigrationsAll/PostgreSQL-net8.0/ApplicationDbContextModelSnapshot.cs index a290b2dd..b26ea00a 100644 --- a/template/src/ABC.Template.Infrastructure/MigrationsAll/PostgreSQL-net8.0/ApplicationDbContextModelSnapshot.cs +++ b/template/src/ABC.Template.Infrastructure/MigrationsAll/PostgreSQL-net8.0/ApplicationDbContextModelSnapshot.cs @@ -1,10 +1,10 @@ // using System; +using ABC.Template.Infrastructure; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; -using ABC.Template.Infrastructure; #nullable disable @@ -131,47 +131,6 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.ToTable("CAPReceivedMessage", (string)null); }); - - modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.DeliverAggregate.DeliverRecord", b => - { - b.Property("Id") - .HasColumnType("uuid"); - - b.Property("OrderId") - .HasColumnType("uuid"); - - b.HasKey("Id"); - - b.ToTable("deliverrecord", (string)null); - }); - - modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.OrderAggregate.Order", b => - { - b.Property("Id") - .HasColumnType("uuid"); - - b.Property("Count") - .HasColumnType("integer"); - - b.Property("Name") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("character varying(100)"); - - b.Property("Paid") - .HasColumnType("boolean"); - - b.Property("RowVersion") - .IsConcurrencyToken() - .HasColumnType("integer"); - - b.Property("UpdateTime") - .HasColumnType("timestamp with time zone"); - - b.HasKey("Id"); - - b.ToTable("order", (string)null); - }); #pragma warning restore 612, 618 } } diff --git a/template/src/ABC.Template.Infrastructure/MigrationsAll/PostgreSQL-net9.0-admin/20260122054707_Init.Designer.cs b/template/src/ABC.Template.Infrastructure/MigrationsAll/PostgreSQL-net9.0-admin/20260122054707_Init.Designer.cs new file mode 100644 index 00000000..cd3261f7 --- /dev/null +++ b/template/src/ABC.Template.Infrastructure/MigrationsAll/PostgreSQL-net9.0-admin/20260122054707_Init.Designer.cs @@ -0,0 +1,440 @@ +// +using System; +using ABC.Template.Infrastructure; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace ABC.Template.Infrastructure.Migrations +{ + [DbContext(typeof(ApplicationDbContext))] + [Migration("20260122054707_Init")] + partial class Init + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "9.0.0") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.DeptAggregate.Dept", b => + { + b.Property("Id") + .HasColumnType("bigint"); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("DeletedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("character varying(100)"); + + b.Property("ParentId") + .HasColumnType("bigint"); + + b.Property("Remark") + .IsRequired() + .HasMaxLength(500) + .HasColumnType("character varying(500)"); + + b.Property("Status") + .HasColumnType("integer"); + + b.Property("UpdateTime") + .HasColumnType("timestamp with time zone"); + + b.HasKey("Id"); + + b.HasIndex("IsDeleted"); + + b.HasIndex("ParentId"); + + b.HasIndex("Status"); + + b.ToTable("dept", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.Role", b => + { + b.Property("Id") + .HasColumnType("uuid"); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("DeletedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("Description") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("character varying(200)"); + + b.Property("IsActive") + .HasColumnType("boolean"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("character varying(50)"); + + b.HasKey("Id"); + + b.HasIndex("Name") + .IsUnique(); + + b.ToTable("role", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.RolePermission", b => + { + b.Property("RoleId") + .HasColumnType("uuid"); + + b.Property("PermissionCode") + .HasMaxLength(100) + .HasColumnType("character varying(100)"); + + b.Property("PermissionDescription") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("character varying(200)"); + + b.Property("PermissionName") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("character varying(100)"); + + b.HasKey("RoleId", "PermissionCode"); + + b.ToTable("role_permission", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.User", b => + { + b.Property("Id") + .HasColumnType("bigint"); + + b.Property("Age") + .HasColumnType("integer"); + + b.Property("BirthDate") + .HasColumnType("timestamp with time zone"); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("DeletedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("Email") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("character varying(100)"); + + b.Property("Gender") + .IsRequired() + .HasMaxLength(10) + .HasColumnType("character varying(10)"); + + b.Property("IsActive") + .HasColumnType("boolean"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("LastLoginTime") + .HasColumnType("timestamp with time zone"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("character varying(50)"); + + b.Property("PasswordHash") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("character varying(255)"); + + b.Property("Phone") + .IsRequired() + .HasMaxLength(20) + .HasColumnType("character varying(20)"); + + b.Property("RealName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("character varying(50)"); + + b.Property("Status") + .HasColumnType("integer"); + + b.Property("UpdateTime") + .HasColumnType("timestamp with time zone"); + + b.HasKey("Id"); + + b.HasIndex("Email"); + + b.HasIndex("Name"); + + b.ToTable("user", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserDept", b => + { + b.Property("UserId") + .HasColumnType("bigint"); + + b.Property("AssignedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("DeptId") + .HasColumnType("bigint"); + + b.Property("DeptName") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("character varying(100)"); + + b.HasKey("UserId"); + + b.HasIndex("DeptId"); + + b.HasIndex("UserId"); + + b.ToTable("user_dept", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRefreshToken", b => + { + b.Property("Id") + .HasColumnType("bigint"); + + b.Property("CreatedTime") + .HasColumnType("timestamp with time zone"); + + b.Property("ExpiresTime") + .HasColumnType("timestamp with time zone"); + + b.Property("IsRevoked") + .HasColumnType("boolean"); + + b.Property("IsUsed") + .HasColumnType("boolean"); + + b.Property("Token") + .IsRequired() + .HasMaxLength(500) + .HasColumnType("character varying(500)"); + + b.Property("UserId") + .HasColumnType("bigint"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("user_refresh_token", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRole", b => + { + b.Property("UserId") + .HasColumnType("bigint"); + + b.Property("RoleId") + .HasColumnType("uuid"); + + b.Property("RoleName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("character varying(50)"); + + b.HasKey("UserId", "RoleId"); + + b.ToTable("user_role", (string)null); + }); + + modelBuilder.Entity("NetCorePal.Extensions.DistributedTransactions.CAP.Persistence.CapLock", b => + { + b.Property("Key") + .HasMaxLength(128) + .HasColumnType("character varying(128)"); + + b.Property("Instance") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.Property("LastLockTime") + .HasColumnType("TIMESTAMP"); + + b.HasKey("Key"); + + b.ToTable("CAPLock", (string)null); + }); + + modelBuilder.Entity("NetCorePal.Extensions.DistributedTransactions.CAP.Persistence.PublishedMessage", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Added") + .HasColumnType("TIMESTAMP"); + + b.Property("Content") + .HasColumnType("TEXT"); + + b.Property("ExpiresAt") + .HasColumnType("TIMESTAMP"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("character varying(200)"); + + b.Property("Retries") + .HasColumnType("integer"); + + b.Property("StatusName") + .IsRequired() + .HasMaxLength(40) + .HasColumnType("character varying(40)"); + + b.Property("Version") + .HasMaxLength(20) + .HasColumnType("character varying(20)"); + + b.HasKey("Id"); + + b.HasIndex(new[] { "ExpiresAt", "StatusName" }, "IX_ExpiresAt_StatusName"); + + b.HasIndex(new[] { "Version", "ExpiresAt", "StatusName" }, "IX_Version_ExpiresAt_StatusName"); + + b.ToTable("CAPPublishedMessage", (string)null); + }); + + modelBuilder.Entity("NetCorePal.Extensions.DistributedTransactions.CAP.Persistence.ReceivedMessage", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Added") + .HasColumnType("TIMESTAMP"); + + b.Property("Content") + .HasColumnType("TEXT"); + + b.Property("ExpiresAt") + .HasColumnType("TIMESTAMP"); + + b.Property("Group") + .HasMaxLength(200) + .HasColumnType("character varying(200)"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(400) + .HasColumnType("character varying(400)"); + + b.Property("Retries") + .HasColumnType("integer"); + + b.Property("StatusName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("character varying(50)"); + + b.Property("Version") + .HasMaxLength(20) + .HasColumnType("character varying(20)"); + + b.HasKey("Id"); + + b.HasIndex(new[] { "ExpiresAt", "StatusName" }, "IX_ExpiresAt_StatusName") + .HasDatabaseName("IX_ExpiresAt_StatusName1"); + + b.HasIndex(new[] { "Version", "ExpiresAt", "StatusName" }, "IX_Version_ExpiresAt_StatusName") + .HasDatabaseName("IX_Version_ExpiresAt_StatusName1"); + + b.ToTable("CAPReceivedMessage", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.RolePermission", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.RoleAggregate.Role", null) + .WithMany("Permissions") + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserDept", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.UserAggregate.User", null) + .WithOne("Dept") + .HasForeignKey("ABC.Template.Domain.AggregatesModel.UserAggregate.UserDept", "UserId") + .OnDelete(DeleteBehavior.ClientCascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRefreshToken", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.UserAggregate.User", null) + .WithMany("RefreshTokens") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRole", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.UserAggregate.User", null) + .WithMany("Roles") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.Role", b => + { + b.Navigation("Permissions"); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.User", b => + { + b.Navigation("Dept") + .IsRequired(); + + b.Navigation("RefreshTokens"); + + b.Navigation("Roles"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/template/src/ABC.Template.Infrastructure/MigrationsAll/PostgreSQL-net9.0-admin/20260122054707_Init.cs b/template/src/ABC.Template.Infrastructure/MigrationsAll/PostgreSQL-net9.0-admin/20260122054707_Init.cs new file mode 100644 index 00000000..b8f83d56 --- /dev/null +++ b/template/src/ABC.Template.Infrastructure/MigrationsAll/PostgreSQL-net9.0-admin/20260122054707_Init.cs @@ -0,0 +1,311 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace ABC.Template.Infrastructure.Migrations +{ + /// + public partial class Init : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "CAPLock", + columns: table => new + { + Key = table.Column(type: "character varying(128)", maxLength: 128, nullable: false), + Instance = table.Column(type: "character varying(256)", maxLength: 256, nullable: true), + LastLockTime = table.Column(type: "TIMESTAMP", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_CAPLock", x => x.Key); + }); + + migrationBuilder.CreateTable( + name: "CAPPublishedMessage", + columns: table => new + { + Id = table.Column(type: "bigint", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + Version = table.Column(type: "character varying(20)", maxLength: 20, nullable: true), + Name = table.Column(type: "character varying(200)", maxLength: 200, nullable: false), + Content = table.Column(type: "TEXT", nullable: true), + Retries = table.Column(type: "integer", nullable: true), + Added = table.Column(type: "TIMESTAMP", nullable: false), + ExpiresAt = table.Column(type: "TIMESTAMP", nullable: true), + StatusName = table.Column(type: "character varying(40)", maxLength: 40, nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_CAPPublishedMessage", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "CAPReceivedMessage", + columns: table => new + { + Id = table.Column(type: "bigint", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + Version = table.Column(type: "character varying(20)", maxLength: 20, nullable: true), + Name = table.Column(type: "character varying(400)", maxLength: 400, nullable: false), + Group = table.Column(type: "character varying(200)", maxLength: 200, nullable: true), + Content = table.Column(type: "TEXT", nullable: true), + Retries = table.Column(type: "integer", nullable: true), + Added = table.Column(type: "TIMESTAMP", nullable: false), + ExpiresAt = table.Column(type: "TIMESTAMP", nullable: true), + StatusName = table.Column(type: "character varying(50)", maxLength: 50, nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_CAPReceivedMessage", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "dept", + columns: table => new + { + Id = table.Column(type: "bigint", nullable: false), + Name = table.Column(type: "character varying(100)", maxLength: 100, nullable: false), + Remark = table.Column(type: "character varying(500)", maxLength: 500, nullable: false), + ParentId = table.Column(type: "bigint", nullable: false), + Status = table.Column(type: "integer", nullable: false), + CreatedAt = table.Column(type: "timestamp with time zone", nullable: false), + IsDeleted = table.Column(type: "boolean", nullable: false), + DeletedAt = table.Column(type: "timestamp with time zone", nullable: false), + UpdateTime = table.Column(type: "timestamp with time zone", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_dept", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "role", + columns: table => new + { + Id = table.Column(type: "uuid", nullable: false), + Name = table.Column(type: "character varying(50)", maxLength: 50, nullable: false), + Description = table.Column(type: "character varying(200)", maxLength: 200, nullable: false), + CreatedAt = table.Column(type: "timestamp with time zone", nullable: false), + IsActive = table.Column(type: "boolean", nullable: false), + IsDeleted = table.Column(type: "boolean", nullable: false), + DeletedAt = table.Column(type: "timestamp with time zone", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_role", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "user", + columns: table => new + { + Id = table.Column(type: "bigint", nullable: false), + Name = table.Column(type: "character varying(50)", maxLength: 50, nullable: false), + Email = table.Column(type: "character varying(100)", maxLength: 100, nullable: false), + Phone = table.Column(type: "character varying(20)", maxLength: 20, nullable: false), + RealName = table.Column(type: "character varying(50)", maxLength: 50, nullable: false), + Status = table.Column(type: "integer", nullable: false), + PasswordHash = table.Column(type: "character varying(255)", maxLength: 255, nullable: false), + IsActive = table.Column(type: "boolean", nullable: false), + CreatedAt = table.Column(type: "timestamp with time zone", nullable: false), + LastLoginTime = table.Column(type: "timestamp with time zone", nullable: true), + UpdateTime = table.Column(type: "timestamp with time zone", nullable: false), + IsDeleted = table.Column(type: "boolean", nullable: false), + DeletedAt = table.Column(type: "timestamp with time zone", nullable: false), + Gender = table.Column(type: "character varying(10)", maxLength: 10, nullable: false), + Age = table.Column(type: "integer", nullable: false), + BirthDate = table.Column(type: "timestamp with time zone", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_user", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "role_permission", + columns: table => new + { + RoleId = table.Column(type: "uuid", nullable: false), + PermissionCode = table.Column(type: "character varying(100)", maxLength: 100, nullable: false), + PermissionName = table.Column(type: "character varying(100)", maxLength: 100, nullable: false), + PermissionDescription = table.Column(type: "character varying(200)", maxLength: 200, nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_role_permission", x => new { x.RoleId, x.PermissionCode }); + table.ForeignKey( + name: "FK_role_permission_role_RoleId", + column: x => x.RoleId, + principalTable: "role", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "user_dept", + columns: table => new + { + UserId = table.Column(type: "bigint", nullable: false), + DeptId = table.Column(type: "bigint", nullable: false), + DeptName = table.Column(type: "character varying(100)", maxLength: 100, nullable: false), + AssignedAt = table.Column(type: "timestamp with time zone", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_user_dept", x => x.UserId); + table.ForeignKey( + name: "FK_user_dept_user_UserId", + column: x => x.UserId, + principalTable: "user", + principalColumn: "Id"); + }); + + migrationBuilder.CreateTable( + name: "user_refresh_token", + columns: table => new + { + Id = table.Column(type: "bigint", nullable: false), + UserId = table.Column(type: "bigint", nullable: false), + Token = table.Column(type: "character varying(500)", maxLength: 500, nullable: false), + CreatedTime = table.Column(type: "timestamp with time zone", nullable: false), + ExpiresTime = table.Column(type: "timestamp with time zone", nullable: false), + IsUsed = table.Column(type: "boolean", nullable: false), + IsRevoked = table.Column(type: "boolean", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_user_refresh_token", x => x.Id); + table.ForeignKey( + name: "FK_user_refresh_token_user_UserId", + column: x => x.UserId, + principalTable: "user", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "user_role", + columns: table => new + { + UserId = table.Column(type: "bigint", nullable: false), + RoleId = table.Column(type: "uuid", nullable: false), + RoleName = table.Column(type: "character varying(50)", maxLength: 50, nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_user_role", x => new { x.UserId, x.RoleId }); + table.ForeignKey( + name: "FK_user_role_user_UserId", + column: x => x.UserId, + principalTable: "user", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_ExpiresAt_StatusName", + table: "CAPPublishedMessage", + columns: new[] { "ExpiresAt", "StatusName" }); + + migrationBuilder.CreateIndex( + name: "IX_Version_ExpiresAt_StatusName", + table: "CAPPublishedMessage", + columns: new[] { "Version", "ExpiresAt", "StatusName" }); + + migrationBuilder.CreateIndex( + name: "IX_ExpiresAt_StatusName1", + table: "CAPReceivedMessage", + columns: new[] { "ExpiresAt", "StatusName" }); + + migrationBuilder.CreateIndex( + name: "IX_Version_ExpiresAt_StatusName1", + table: "CAPReceivedMessage", + columns: new[] { "Version", "ExpiresAt", "StatusName" }); + + migrationBuilder.CreateIndex( + name: "IX_dept_IsDeleted", + table: "dept", + column: "IsDeleted"); + + migrationBuilder.CreateIndex( + name: "IX_dept_ParentId", + table: "dept", + column: "ParentId"); + + migrationBuilder.CreateIndex( + name: "IX_dept_Status", + table: "dept", + column: "Status"); + + migrationBuilder.CreateIndex( + name: "IX_role_Name", + table: "role", + column: "Name", + unique: true); + + migrationBuilder.CreateIndex( + name: "IX_user_Email", + table: "user", + column: "Email"); + + migrationBuilder.CreateIndex( + name: "IX_user_Name", + table: "user", + column: "Name"); + + migrationBuilder.CreateIndex( + name: "IX_user_dept_DeptId", + table: "user_dept", + column: "DeptId"); + + migrationBuilder.CreateIndex( + name: "IX_user_dept_UserId", + table: "user_dept", + column: "UserId"); + + migrationBuilder.CreateIndex( + name: "IX_user_refresh_token_UserId", + table: "user_refresh_token", + column: "UserId"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "CAPLock"); + + migrationBuilder.DropTable( + name: "CAPPublishedMessage"); + + migrationBuilder.DropTable( + name: "CAPReceivedMessage"); + + migrationBuilder.DropTable( + name: "dept"); + + migrationBuilder.DropTable( + name: "role_permission"); + + migrationBuilder.DropTable( + name: "user_dept"); + + migrationBuilder.DropTable( + name: "user_refresh_token"); + + migrationBuilder.DropTable( + name: "user_role"); + + migrationBuilder.DropTable( + name: "role"); + + migrationBuilder.DropTable( + name: "user"); + } + } +} diff --git a/template/src/ABC.Template.Infrastructure/MigrationsAll/PostgreSQL-net9.0-admin/ApplicationDbContextModelSnapshot.cs b/template/src/ABC.Template.Infrastructure/MigrationsAll/PostgreSQL-net9.0-admin/ApplicationDbContextModelSnapshot.cs new file mode 100644 index 00000000..da544d51 --- /dev/null +++ b/template/src/ABC.Template.Infrastructure/MigrationsAll/PostgreSQL-net9.0-admin/ApplicationDbContextModelSnapshot.cs @@ -0,0 +1,437 @@ +// +using System; +using ABC.Template.Infrastructure; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace ABC.Template.Infrastructure.Migrations +{ + [DbContext(typeof(ApplicationDbContext))] + partial class ApplicationDbContextModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "9.0.0") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.DeptAggregate.Dept", b => + { + b.Property("Id") + .HasColumnType("bigint"); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("DeletedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("character varying(100)"); + + b.Property("ParentId") + .HasColumnType("bigint"); + + b.Property("Remark") + .IsRequired() + .HasMaxLength(500) + .HasColumnType("character varying(500)"); + + b.Property("Status") + .HasColumnType("integer"); + + b.Property("UpdateTime") + .HasColumnType("timestamp with time zone"); + + b.HasKey("Id"); + + b.HasIndex("IsDeleted"); + + b.HasIndex("ParentId"); + + b.HasIndex("Status"); + + b.ToTable("dept", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.Role", b => + { + b.Property("Id") + .HasColumnType("uuid"); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("DeletedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("Description") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("character varying(200)"); + + b.Property("IsActive") + .HasColumnType("boolean"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("character varying(50)"); + + b.HasKey("Id"); + + b.HasIndex("Name") + .IsUnique(); + + b.ToTable("role", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.RolePermission", b => + { + b.Property("RoleId") + .HasColumnType("uuid"); + + b.Property("PermissionCode") + .HasMaxLength(100) + .HasColumnType("character varying(100)"); + + b.Property("PermissionDescription") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("character varying(200)"); + + b.Property("PermissionName") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("character varying(100)"); + + b.HasKey("RoleId", "PermissionCode"); + + b.ToTable("role_permission", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.User", b => + { + b.Property("Id") + .HasColumnType("bigint"); + + b.Property("Age") + .HasColumnType("integer"); + + b.Property("BirthDate") + .HasColumnType("timestamp with time zone"); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("DeletedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("Email") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("character varying(100)"); + + b.Property("Gender") + .IsRequired() + .HasMaxLength(10) + .HasColumnType("character varying(10)"); + + b.Property("IsActive") + .HasColumnType("boolean"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("LastLoginTime") + .HasColumnType("timestamp with time zone"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("character varying(50)"); + + b.Property("PasswordHash") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("character varying(255)"); + + b.Property("Phone") + .IsRequired() + .HasMaxLength(20) + .HasColumnType("character varying(20)"); + + b.Property("RealName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("character varying(50)"); + + b.Property("Status") + .HasColumnType("integer"); + + b.Property("UpdateTime") + .HasColumnType("timestamp with time zone"); + + b.HasKey("Id"); + + b.HasIndex("Email"); + + b.HasIndex("Name"); + + b.ToTable("user", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserDept", b => + { + b.Property("UserId") + .HasColumnType("bigint"); + + b.Property("AssignedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("DeptId") + .HasColumnType("bigint"); + + b.Property("DeptName") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("character varying(100)"); + + b.HasKey("UserId"); + + b.HasIndex("DeptId"); + + b.HasIndex("UserId"); + + b.ToTable("user_dept", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRefreshToken", b => + { + b.Property("Id") + .HasColumnType("bigint"); + + b.Property("CreatedTime") + .HasColumnType("timestamp with time zone"); + + b.Property("ExpiresTime") + .HasColumnType("timestamp with time zone"); + + b.Property("IsRevoked") + .HasColumnType("boolean"); + + b.Property("IsUsed") + .HasColumnType("boolean"); + + b.Property("Token") + .IsRequired() + .HasMaxLength(500) + .HasColumnType("character varying(500)"); + + b.Property("UserId") + .HasColumnType("bigint"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("user_refresh_token", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRole", b => + { + b.Property("UserId") + .HasColumnType("bigint"); + + b.Property("RoleId") + .HasColumnType("uuid"); + + b.Property("RoleName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("character varying(50)"); + + b.HasKey("UserId", "RoleId"); + + b.ToTable("user_role", (string)null); + }); + + modelBuilder.Entity("NetCorePal.Extensions.DistributedTransactions.CAP.Persistence.CapLock", b => + { + b.Property("Key") + .HasMaxLength(128) + .HasColumnType("character varying(128)"); + + b.Property("Instance") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.Property("LastLockTime") + .HasColumnType("TIMESTAMP"); + + b.HasKey("Key"); + + b.ToTable("CAPLock", (string)null); + }); + + modelBuilder.Entity("NetCorePal.Extensions.DistributedTransactions.CAP.Persistence.PublishedMessage", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Added") + .HasColumnType("TIMESTAMP"); + + b.Property("Content") + .HasColumnType("TEXT"); + + b.Property("ExpiresAt") + .HasColumnType("TIMESTAMP"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("character varying(200)"); + + b.Property("Retries") + .HasColumnType("integer"); + + b.Property("StatusName") + .IsRequired() + .HasMaxLength(40) + .HasColumnType("character varying(40)"); + + b.Property("Version") + .HasMaxLength(20) + .HasColumnType("character varying(20)"); + + b.HasKey("Id"); + + b.HasIndex(new[] { "ExpiresAt", "StatusName" }, "IX_ExpiresAt_StatusName"); + + b.HasIndex(new[] { "Version", "ExpiresAt", "StatusName" }, "IX_Version_ExpiresAt_StatusName"); + + b.ToTable("CAPPublishedMessage", (string)null); + }); + + modelBuilder.Entity("NetCorePal.Extensions.DistributedTransactions.CAP.Persistence.ReceivedMessage", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Added") + .HasColumnType("TIMESTAMP"); + + b.Property("Content") + .HasColumnType("TEXT"); + + b.Property("ExpiresAt") + .HasColumnType("TIMESTAMP"); + + b.Property("Group") + .HasMaxLength(200) + .HasColumnType("character varying(200)"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(400) + .HasColumnType("character varying(400)"); + + b.Property("Retries") + .HasColumnType("integer"); + + b.Property("StatusName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("character varying(50)"); + + b.Property("Version") + .HasMaxLength(20) + .HasColumnType("character varying(20)"); + + b.HasKey("Id"); + + b.HasIndex(new[] { "ExpiresAt", "StatusName" }, "IX_ExpiresAt_StatusName") + .HasDatabaseName("IX_ExpiresAt_StatusName1"); + + b.HasIndex(new[] { "Version", "ExpiresAt", "StatusName" }, "IX_Version_ExpiresAt_StatusName") + .HasDatabaseName("IX_Version_ExpiresAt_StatusName1"); + + b.ToTable("CAPReceivedMessage", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.RolePermission", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.RoleAggregate.Role", null) + .WithMany("Permissions") + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserDept", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.UserAggregate.User", null) + .WithOne("Dept") + .HasForeignKey("ABC.Template.Domain.AggregatesModel.UserAggregate.UserDept", "UserId") + .OnDelete(DeleteBehavior.ClientCascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRefreshToken", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.UserAggregate.User", null) + .WithMany("RefreshTokens") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRole", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.UserAggregate.User", null) + .WithMany("Roles") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.Role", b => + { + b.Navigation("Permissions"); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.User", b => + { + b.Navigation("Dept") + .IsRequired(); + + b.Navigation("RefreshTokens"); + + b.Navigation("Roles"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/template/src/ABC.Template.Infrastructure/MigrationsAll/PostgreSQL-net10.0/20251225065110_Init.Designer.cs b/template/src/ABC.Template.Infrastructure/MigrationsAll/PostgreSQL-net9.0/20260122054646_Init.Designer.cs similarity index 78% rename from template/src/ABC.Template.Infrastructure/MigrationsAll/PostgreSQL-net10.0/20251225065110_Init.Designer.cs rename to template/src/ABC.Template.Infrastructure/MigrationsAll/PostgreSQL-net9.0/20260122054646_Init.Designer.cs index ac9065a2..97567fd1 100644 --- a/template/src/ABC.Template.Infrastructure/MigrationsAll/PostgreSQL-net10.0/20251225065110_Init.Designer.cs +++ b/template/src/ABC.Template.Infrastructure/MigrationsAll/PostgreSQL-net9.0/20260122054646_Init.Designer.cs @@ -1,18 +1,18 @@ // using System; +using ABC.Template.Infrastructure; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; -using ABC.Template.Infrastructure; #nullable disable namespace ABC.Template.Infrastructure.Migrations { [DbContext(typeof(ApplicationDbContext))] - [Migration("20251225065110_Init")] + [Migration("20260122054646_Init")] partial class Init { /// @@ -134,47 +134,6 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.ToTable("CAPReceivedMessage", (string)null); }); - - modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.DeliverAggregate.DeliverRecord", b => - { - b.Property("Id") - .HasColumnType("uuid"); - - b.Property("OrderId") - .HasColumnType("uuid"); - - b.HasKey("Id"); - - b.ToTable("deliverrecord", (string)null); - }); - - modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.OrderAggregate.Order", b => - { - b.Property("Id") - .HasColumnType("uuid"); - - b.Property("Count") - .HasColumnType("integer"); - - b.Property("Name") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("character varying(100)"); - - b.Property("Paid") - .HasColumnType("boolean"); - - b.Property("RowVersion") - .IsConcurrencyToken() - .HasColumnType("integer"); - - b.Property("UpdateTime") - .HasColumnType("timestamp with time zone"); - - b.HasKey("Id"); - - b.ToTable("order", (string)null); - }); #pragma warning restore 612, 618 } } diff --git a/template/src/ABC.Template.Infrastructure/MigrationsAll/PostgreSQL-net10.0/20251225065110_Init.cs b/template/src/ABC.Template.Infrastructure/MigrationsAll/PostgreSQL-net9.0/20260122054646_Init.cs similarity index 76% rename from template/src/ABC.Template.Infrastructure/MigrationsAll/PostgreSQL-net10.0/20251225065110_Init.cs rename to template/src/ABC.Template.Infrastructure/MigrationsAll/PostgreSQL-net9.0/20260122054646_Init.cs index 994de8c5..68029fcc 100644 --- a/template/src/ABC.Template.Infrastructure/MigrationsAll/PostgreSQL-net10.0/20251225065110_Init.cs +++ b/template/src/ABC.Template.Infrastructure/MigrationsAll/PostgreSQL-net9.0/20260122054646_Init.cs @@ -64,34 +64,6 @@ protected override void Up(MigrationBuilder migrationBuilder) table.PrimaryKey("PK_CAPReceivedMessage", x => x.Id); }); - migrationBuilder.CreateTable( - name: "deliverrecord", - columns: table => new - { - Id = table.Column(type: "uuid", nullable: false), - OrderId = table.Column(type: "uuid", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_deliverrecord", x => x.Id); - }); - - migrationBuilder.CreateTable( - name: "order", - columns: table => new - { - Id = table.Column(type: "uuid", nullable: false), - Paid = table.Column(type: "boolean", nullable: false), - Name = table.Column(type: "character varying(100)", maxLength: 100, nullable: false), - Count = table.Column(type: "integer", nullable: false), - RowVersion = table.Column(type: "integer", nullable: false), - UpdateTime = table.Column(type: "timestamp with time zone", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_order", x => x.Id); - }); - migrationBuilder.CreateIndex( name: "IX_ExpiresAt_StatusName", table: "CAPPublishedMessage", @@ -124,12 +96,6 @@ protected override void Down(MigrationBuilder migrationBuilder) migrationBuilder.DropTable( name: "CAPReceivedMessage"); - - migrationBuilder.DropTable( - name: "deliverrecord"); - - migrationBuilder.DropTable( - name: "order"); } } } diff --git a/template/src/ABC.Template.Infrastructure/MigrationsAll/PostgreSQL-net9.0/ApplicationDbContextModelSnapshot.cs b/template/src/ABC.Template.Infrastructure/MigrationsAll/PostgreSQL-net9.0/ApplicationDbContextModelSnapshot.cs index b33fd3aa..b914d406 100644 --- a/template/src/ABC.Template.Infrastructure/MigrationsAll/PostgreSQL-net9.0/ApplicationDbContextModelSnapshot.cs +++ b/template/src/ABC.Template.Infrastructure/MigrationsAll/PostgreSQL-net9.0/ApplicationDbContextModelSnapshot.cs @@ -1,10 +1,10 @@ // using System; +using ABC.Template.Infrastructure; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; -using ABC.Template.Infrastructure; #nullable disable @@ -131,47 +131,6 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.ToTable("CAPReceivedMessage", (string)null); }); - - modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.DeliverAggregate.DeliverRecord", b => - { - b.Property("Id") - .HasColumnType("uuid"); - - b.Property("OrderId") - .HasColumnType("uuid"); - - b.HasKey("Id"); - - b.ToTable("deliverrecord", (string)null); - }); - - modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.OrderAggregate.Order", b => - { - b.Property("Id") - .HasColumnType("uuid"); - - b.Property("Count") - .HasColumnType("integer"); - - b.Property("Name") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("character varying(100)"); - - b.Property("Paid") - .HasColumnType("boolean"); - - b.Property("RowVersion") - .IsConcurrencyToken() - .HasColumnType("integer"); - - b.Property("UpdateTime") - .HasColumnType("timestamp with time zone"); - - b.HasKey("Id"); - - b.ToTable("order", (string)null); - }); #pragma warning restore 612, 618 } } diff --git a/template/src/ABC.Template.Infrastructure/MigrationsAll/SqlServer-net10.0-admin/20260122054606_Init.Designer.cs b/template/src/ABC.Template.Infrastructure/MigrationsAll/SqlServer-net10.0-admin/20260122054606_Init.Designer.cs new file mode 100644 index 00000000..702c6d98 --- /dev/null +++ b/template/src/ABC.Template.Infrastructure/MigrationsAll/SqlServer-net10.0-admin/20260122054606_Init.Designer.cs @@ -0,0 +1,432 @@ +// +using System; +using ABC.Template.Infrastructure; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace ABC.Template.Infrastructure.Migrations +{ + [DbContext(typeof(ApplicationDbContext))] + [Migration("20260122054606_Init")] + partial class Init + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "9.0.0") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.DeptAggregate.Dept", b => + { + b.Property("Id") + .HasColumnType("bigint"); + + b.Property("CreatedAt") + .HasColumnType("datetimeoffset"); + + b.Property("DeletedAt") + .HasColumnType("datetimeoffset"); + + b.Property("IsDeleted") + .HasColumnType("bit"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.Property("ParentId") + .HasColumnType("bigint"); + + b.Property("Remark") + .IsRequired() + .HasMaxLength(500) + .HasColumnType("nvarchar(500)"); + + b.Property("Status") + .HasColumnType("int"); + + b.Property("UpdateTime") + .HasColumnType("datetimeoffset"); + + b.HasKey("Id"); + + b.HasIndex("IsDeleted"); + + b.HasIndex("ParentId"); + + b.HasIndex("Status"); + + b.ToTable("dept", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.Role", b => + { + b.Property("Id") + .HasColumnType("uniqueidentifier"); + + b.Property("CreatedAt") + .HasColumnType("datetimeoffset"); + + b.Property("DeletedAt") + .HasColumnType("datetimeoffset"); + + b.Property("Description") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.Property("IsActive") + .HasColumnType("bit"); + + b.Property("IsDeleted") + .HasColumnType("bit"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.HasKey("Id"); + + b.HasIndex("Name") + .IsUnique(); + + b.ToTable("role", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.RolePermission", b => + { + b.Property("RoleId") + .HasColumnType("uniqueidentifier"); + + b.Property("PermissionCode") + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.Property("PermissionDescription") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.Property("PermissionName") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.HasKey("RoleId", "PermissionCode"); + + b.ToTable("role_permission", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.User", b => + { + b.Property("Id") + .HasColumnType("bigint"); + + b.Property("Age") + .HasColumnType("int"); + + b.Property("BirthDate") + .HasColumnType("datetimeoffset"); + + b.Property("CreatedAt") + .HasColumnType("datetimeoffset"); + + b.Property("DeletedAt") + .HasColumnType("datetimeoffset"); + + b.Property("Email") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.Property("Gender") + .IsRequired() + .HasMaxLength(10) + .HasColumnType("nvarchar(10)"); + + b.Property("IsActive") + .HasColumnType("bit"); + + b.Property("IsDeleted") + .HasColumnType("bit"); + + b.Property("LastLoginTime") + .HasColumnType("datetimeoffset"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.Property("PasswordHash") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("nvarchar(255)"); + + b.Property("Phone") + .IsRequired() + .HasMaxLength(20) + .HasColumnType("nvarchar(20)"); + + b.Property("RealName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.Property("Status") + .HasColumnType("int"); + + b.Property("UpdateTime") + .HasColumnType("datetimeoffset"); + + b.HasKey("Id"); + + b.HasIndex("Email"); + + b.HasIndex("Name"); + + b.ToTable("user", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserDept", b => + { + b.Property("UserId") + .HasColumnType("bigint"); + + b.Property("AssignedAt") + .HasColumnType("datetimeoffset"); + + b.Property("DeptId") + .HasColumnType("bigint"); + + b.Property("DeptName") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.HasKey("UserId"); + + b.HasIndex("DeptId"); + + b.HasIndex("UserId"); + + b.ToTable("user_dept", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRefreshToken", b => + { + b.Property("Id") + .HasColumnType("bigint"); + + b.Property("CreatedTime") + .HasColumnType("datetimeoffset"); + + b.Property("ExpiresTime") + .HasColumnType("datetimeoffset"); + + b.Property("IsRevoked") + .HasColumnType("bit"); + + b.Property("IsUsed") + .HasColumnType("bit"); + + b.Property("Token") + .IsRequired() + .HasMaxLength(500) + .HasColumnType("nvarchar(500)"); + + b.Property("UserId") + .HasColumnType("bigint"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("user_refresh_token", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRole", b => + { + b.Property("UserId") + .HasColumnType("bigint"); + + b.Property("RoleId") + .HasColumnType("uniqueidentifier"); + + b.Property("RoleName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.HasKey("UserId", "RoleId"); + + b.ToTable("user_role", (string)null); + }); + + modelBuilder.Entity("NetCorePal.Extensions.DistributedTransactions.CAP.Persistence.CapLock", b => + { + b.Property("Key") + .HasMaxLength(128) + .HasColumnType("nvarchar(128)"); + + b.Property("Instance") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.Property("LastLockTime") + .HasColumnType("datetime2(7)"); + + b.HasKey("Key"); + + b.ToTable("CAPLock", (string)null); + }); + + modelBuilder.Entity("NetCorePal.Extensions.DistributedTransactions.CAP.Persistence.PublishedMessage", b => + { + b.Property("Id") + .HasColumnType("bigint"); + + b.Property("Added") + .HasColumnType("datetime2(7)"); + + b.Property("Content") + .HasColumnType("nvarchar(max)"); + + b.Property("ExpiresAt") + .HasColumnType("datetime2(7)"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.Property("Retries") + .HasColumnType("int"); + + b.Property("StatusName") + .IsRequired() + .HasMaxLength(40) + .HasColumnType("nvarchar(40)"); + + b.Property("Version") + .HasMaxLength(20) + .HasColumnType("nvarchar(20)"); + + b.HasKey("Id"); + + b.HasIndex(new[] { "ExpiresAt", "StatusName" }, "IX_ExpiresAt_StatusName"); + + b.HasIndex(new[] { "Version", "ExpiresAt", "StatusName" }, "IX_Version_ExpiresAt_StatusName"); + + b.ToTable("CAPPublishedMessage", (string)null); + }); + + modelBuilder.Entity("NetCorePal.Extensions.DistributedTransactions.CAP.Persistence.ReceivedMessage", b => + { + b.Property("Id") + .HasColumnType("bigint"); + + b.Property("Added") + .HasColumnType("datetime2(7)"); + + b.Property("Content") + .HasColumnType("nvarchar(max)"); + + b.Property("ExpiresAt") + .HasColumnType("datetime2(7)"); + + b.Property("Group") + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(400) + .HasColumnType("nvarchar(400)"); + + b.Property("Retries") + .HasColumnType("int"); + + b.Property("StatusName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.Property("Version") + .HasMaxLength(20) + .HasColumnType("nvarchar(20)"); + + b.HasKey("Id"); + + b.HasIndex(new[] { "ExpiresAt", "StatusName" }, "IX_ExpiresAt_StatusName"); + + b.HasIndex(new[] { "Version", "ExpiresAt", "StatusName" }, "IX_Version_ExpiresAt_StatusName"); + + b.ToTable("CAPReceivedMessage", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.RolePermission", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.RoleAggregate.Role", null) + .WithMany("Permissions") + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserDept", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.UserAggregate.User", null) + .WithOne("Dept") + .HasForeignKey("ABC.Template.Domain.AggregatesModel.UserAggregate.UserDept", "UserId") + .OnDelete(DeleteBehavior.ClientCascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRefreshToken", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.UserAggregate.User", null) + .WithMany("RefreshTokens") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRole", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.UserAggregate.User", null) + .WithMany("Roles") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.Role", b => + { + b.Navigation("Permissions"); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.User", b => + { + b.Navigation("Dept") + .IsRequired(); + + b.Navigation("RefreshTokens"); + + b.Navigation("Roles"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/template/src/ABC.Template.Infrastructure/MigrationsAll/SqlServer-net10.0-admin/20260122054606_Init.cs b/template/src/ABC.Template.Infrastructure/MigrationsAll/SqlServer-net10.0-admin/20260122054606_Init.cs new file mode 100644 index 00000000..e59b8bdf --- /dev/null +++ b/template/src/ABC.Template.Infrastructure/MigrationsAll/SqlServer-net10.0-admin/20260122054606_Init.cs @@ -0,0 +1,308 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace ABC.Template.Infrastructure.Migrations +{ + /// + public partial class Init : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "CAPLock", + columns: table => new + { + Key = table.Column(type: "nvarchar(128)", maxLength: 128, nullable: false), + Instance = table.Column(type: "nvarchar(256)", maxLength: 256, nullable: true), + LastLockTime = table.Column(type: "datetime2(7)", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_CAPLock", x => x.Key); + }); + + migrationBuilder.CreateTable( + name: "CAPPublishedMessage", + columns: table => new + { + Id = table.Column(type: "bigint", nullable: false), + Version = table.Column(type: "nvarchar(20)", maxLength: 20, nullable: true), + Name = table.Column(type: "nvarchar(200)", maxLength: 200, nullable: false), + Content = table.Column(type: "nvarchar(max)", nullable: true), + Retries = table.Column(type: "int", nullable: true), + Added = table.Column(type: "datetime2(7)", nullable: false), + ExpiresAt = table.Column(type: "datetime2(7)", nullable: true), + StatusName = table.Column(type: "nvarchar(40)", maxLength: 40, nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_CAPPublishedMessage", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "CAPReceivedMessage", + columns: table => new + { + Id = table.Column(type: "bigint", nullable: false), + Version = table.Column(type: "nvarchar(20)", maxLength: 20, nullable: true), + Name = table.Column(type: "nvarchar(400)", maxLength: 400, nullable: false), + Group = table.Column(type: "nvarchar(200)", maxLength: 200, nullable: true), + Content = table.Column(type: "nvarchar(max)", nullable: true), + Retries = table.Column(type: "int", nullable: true), + Added = table.Column(type: "datetime2(7)", nullable: false), + ExpiresAt = table.Column(type: "datetime2(7)", nullable: true), + StatusName = table.Column(type: "nvarchar(50)", maxLength: 50, nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_CAPReceivedMessage", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "dept", + columns: table => new + { + Id = table.Column(type: "bigint", nullable: false), + Name = table.Column(type: "nvarchar(100)", maxLength: 100, nullable: false), + Remark = table.Column(type: "nvarchar(500)", maxLength: 500, nullable: false), + ParentId = table.Column(type: "bigint", nullable: false), + Status = table.Column(type: "int", nullable: false), + CreatedAt = table.Column(type: "datetimeoffset", nullable: false), + IsDeleted = table.Column(type: "bit", nullable: false), + DeletedAt = table.Column(type: "datetimeoffset", nullable: false), + UpdateTime = table.Column(type: "datetimeoffset", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_dept", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "role", + columns: table => new + { + Id = table.Column(type: "uniqueidentifier", nullable: false), + Name = table.Column(type: "nvarchar(50)", maxLength: 50, nullable: false), + Description = table.Column(type: "nvarchar(200)", maxLength: 200, nullable: false), + CreatedAt = table.Column(type: "datetimeoffset", nullable: false), + IsActive = table.Column(type: "bit", nullable: false), + IsDeleted = table.Column(type: "bit", nullable: false), + DeletedAt = table.Column(type: "datetimeoffset", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_role", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "user", + columns: table => new + { + Id = table.Column(type: "bigint", nullable: false), + Name = table.Column(type: "nvarchar(50)", maxLength: 50, nullable: false), + Email = table.Column(type: "nvarchar(100)", maxLength: 100, nullable: false), + Phone = table.Column(type: "nvarchar(20)", maxLength: 20, nullable: false), + RealName = table.Column(type: "nvarchar(50)", maxLength: 50, nullable: false), + Status = table.Column(type: "int", nullable: false), + PasswordHash = table.Column(type: "nvarchar(255)", maxLength: 255, nullable: false), + IsActive = table.Column(type: "bit", nullable: false), + CreatedAt = table.Column(type: "datetimeoffset", nullable: false), + LastLoginTime = table.Column(type: "datetimeoffset", nullable: true), + UpdateTime = table.Column(type: "datetimeoffset", nullable: false), + IsDeleted = table.Column(type: "bit", nullable: false), + DeletedAt = table.Column(type: "datetimeoffset", nullable: false), + Gender = table.Column(type: "nvarchar(10)", maxLength: 10, nullable: false), + Age = table.Column(type: "int", nullable: false), + BirthDate = table.Column(type: "datetimeoffset", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_user", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "role_permission", + columns: table => new + { + RoleId = table.Column(type: "uniqueidentifier", nullable: false), + PermissionCode = table.Column(type: "nvarchar(100)", maxLength: 100, nullable: false), + PermissionName = table.Column(type: "nvarchar(100)", maxLength: 100, nullable: false), + PermissionDescription = table.Column(type: "nvarchar(200)", maxLength: 200, nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_role_permission", x => new { x.RoleId, x.PermissionCode }); + table.ForeignKey( + name: "FK_role_permission_role_RoleId", + column: x => x.RoleId, + principalTable: "role", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "user_dept", + columns: table => new + { + UserId = table.Column(type: "bigint", nullable: false), + DeptId = table.Column(type: "bigint", nullable: false), + DeptName = table.Column(type: "nvarchar(100)", maxLength: 100, nullable: false), + AssignedAt = table.Column(type: "datetimeoffset", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_user_dept", x => x.UserId); + table.ForeignKey( + name: "FK_user_dept_user_UserId", + column: x => x.UserId, + principalTable: "user", + principalColumn: "Id"); + }); + + migrationBuilder.CreateTable( + name: "user_refresh_token", + columns: table => new + { + Id = table.Column(type: "bigint", nullable: false), + UserId = table.Column(type: "bigint", nullable: false), + Token = table.Column(type: "nvarchar(500)", maxLength: 500, nullable: false), + CreatedTime = table.Column(type: "datetimeoffset", nullable: false), + ExpiresTime = table.Column(type: "datetimeoffset", nullable: false), + IsUsed = table.Column(type: "bit", nullable: false), + IsRevoked = table.Column(type: "bit", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_user_refresh_token", x => x.Id); + table.ForeignKey( + name: "FK_user_refresh_token_user_UserId", + column: x => x.UserId, + principalTable: "user", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "user_role", + columns: table => new + { + UserId = table.Column(type: "bigint", nullable: false), + RoleId = table.Column(type: "uniqueidentifier", nullable: false), + RoleName = table.Column(type: "nvarchar(50)", maxLength: 50, nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_user_role", x => new { x.UserId, x.RoleId }); + table.ForeignKey( + name: "FK_user_role_user_UserId", + column: x => x.UserId, + principalTable: "user", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_ExpiresAt_StatusName", + table: "CAPPublishedMessage", + columns: new[] { "ExpiresAt", "StatusName" }); + + migrationBuilder.CreateIndex( + name: "IX_Version_ExpiresAt_StatusName", + table: "CAPPublishedMessage", + columns: new[] { "Version", "ExpiresAt", "StatusName" }); + + migrationBuilder.CreateIndex( + name: "IX_ExpiresAt_StatusName", + table: "CAPReceivedMessage", + columns: new[] { "ExpiresAt", "StatusName" }); + + migrationBuilder.CreateIndex( + name: "IX_Version_ExpiresAt_StatusName", + table: "CAPReceivedMessage", + columns: new[] { "Version", "ExpiresAt", "StatusName" }); + + migrationBuilder.CreateIndex( + name: "IX_dept_IsDeleted", + table: "dept", + column: "IsDeleted"); + + migrationBuilder.CreateIndex( + name: "IX_dept_ParentId", + table: "dept", + column: "ParentId"); + + migrationBuilder.CreateIndex( + name: "IX_dept_Status", + table: "dept", + column: "Status"); + + migrationBuilder.CreateIndex( + name: "IX_role_Name", + table: "role", + column: "Name", + unique: true); + + migrationBuilder.CreateIndex( + name: "IX_user_Email", + table: "user", + column: "Email"); + + migrationBuilder.CreateIndex( + name: "IX_user_Name", + table: "user", + column: "Name"); + + migrationBuilder.CreateIndex( + name: "IX_user_dept_DeptId", + table: "user_dept", + column: "DeptId"); + + migrationBuilder.CreateIndex( + name: "IX_user_dept_UserId", + table: "user_dept", + column: "UserId"); + + migrationBuilder.CreateIndex( + name: "IX_user_refresh_token_UserId", + table: "user_refresh_token", + column: "UserId"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "CAPLock"); + + migrationBuilder.DropTable( + name: "CAPPublishedMessage"); + + migrationBuilder.DropTable( + name: "CAPReceivedMessage"); + + migrationBuilder.DropTable( + name: "dept"); + + migrationBuilder.DropTable( + name: "role_permission"); + + migrationBuilder.DropTable( + name: "user_dept"); + + migrationBuilder.DropTable( + name: "user_refresh_token"); + + migrationBuilder.DropTable( + name: "user_role"); + + migrationBuilder.DropTable( + name: "role"); + + migrationBuilder.DropTable( + name: "user"); + } + } +} diff --git a/template/src/ABC.Template.Infrastructure/MigrationsAll/SqlServer-net10.0-admin/ApplicationDbContextModelSnapshot.cs b/template/src/ABC.Template.Infrastructure/MigrationsAll/SqlServer-net10.0-admin/ApplicationDbContextModelSnapshot.cs new file mode 100644 index 00000000..03c8242f --- /dev/null +++ b/template/src/ABC.Template.Infrastructure/MigrationsAll/SqlServer-net10.0-admin/ApplicationDbContextModelSnapshot.cs @@ -0,0 +1,429 @@ +// +using System; +using ABC.Template.Infrastructure; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace ABC.Template.Infrastructure.Migrations +{ + [DbContext(typeof(ApplicationDbContext))] + partial class ApplicationDbContextModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "9.0.0") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.DeptAggregate.Dept", b => + { + b.Property("Id") + .HasColumnType("bigint"); + + b.Property("CreatedAt") + .HasColumnType("datetimeoffset"); + + b.Property("DeletedAt") + .HasColumnType("datetimeoffset"); + + b.Property("IsDeleted") + .HasColumnType("bit"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.Property("ParentId") + .HasColumnType("bigint"); + + b.Property("Remark") + .IsRequired() + .HasMaxLength(500) + .HasColumnType("nvarchar(500)"); + + b.Property("Status") + .HasColumnType("int"); + + b.Property("UpdateTime") + .HasColumnType("datetimeoffset"); + + b.HasKey("Id"); + + b.HasIndex("IsDeleted"); + + b.HasIndex("ParentId"); + + b.HasIndex("Status"); + + b.ToTable("dept", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.Role", b => + { + b.Property("Id") + .HasColumnType("uniqueidentifier"); + + b.Property("CreatedAt") + .HasColumnType("datetimeoffset"); + + b.Property("DeletedAt") + .HasColumnType("datetimeoffset"); + + b.Property("Description") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.Property("IsActive") + .HasColumnType("bit"); + + b.Property("IsDeleted") + .HasColumnType("bit"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.HasKey("Id"); + + b.HasIndex("Name") + .IsUnique(); + + b.ToTable("role", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.RolePermission", b => + { + b.Property("RoleId") + .HasColumnType("uniqueidentifier"); + + b.Property("PermissionCode") + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.Property("PermissionDescription") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.Property("PermissionName") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.HasKey("RoleId", "PermissionCode"); + + b.ToTable("role_permission", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.User", b => + { + b.Property("Id") + .HasColumnType("bigint"); + + b.Property("Age") + .HasColumnType("int"); + + b.Property("BirthDate") + .HasColumnType("datetimeoffset"); + + b.Property("CreatedAt") + .HasColumnType("datetimeoffset"); + + b.Property("DeletedAt") + .HasColumnType("datetimeoffset"); + + b.Property("Email") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.Property("Gender") + .IsRequired() + .HasMaxLength(10) + .HasColumnType("nvarchar(10)"); + + b.Property("IsActive") + .HasColumnType("bit"); + + b.Property("IsDeleted") + .HasColumnType("bit"); + + b.Property("LastLoginTime") + .HasColumnType("datetimeoffset"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.Property("PasswordHash") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("nvarchar(255)"); + + b.Property("Phone") + .IsRequired() + .HasMaxLength(20) + .HasColumnType("nvarchar(20)"); + + b.Property("RealName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.Property("Status") + .HasColumnType("int"); + + b.Property("UpdateTime") + .HasColumnType("datetimeoffset"); + + b.HasKey("Id"); + + b.HasIndex("Email"); + + b.HasIndex("Name"); + + b.ToTable("user", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserDept", b => + { + b.Property("UserId") + .HasColumnType("bigint"); + + b.Property("AssignedAt") + .HasColumnType("datetimeoffset"); + + b.Property("DeptId") + .HasColumnType("bigint"); + + b.Property("DeptName") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.HasKey("UserId"); + + b.HasIndex("DeptId"); + + b.HasIndex("UserId"); + + b.ToTable("user_dept", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRefreshToken", b => + { + b.Property("Id") + .HasColumnType("bigint"); + + b.Property("CreatedTime") + .HasColumnType("datetimeoffset"); + + b.Property("ExpiresTime") + .HasColumnType("datetimeoffset"); + + b.Property("IsRevoked") + .HasColumnType("bit"); + + b.Property("IsUsed") + .HasColumnType("bit"); + + b.Property("Token") + .IsRequired() + .HasMaxLength(500) + .HasColumnType("nvarchar(500)"); + + b.Property("UserId") + .HasColumnType("bigint"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("user_refresh_token", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRole", b => + { + b.Property("UserId") + .HasColumnType("bigint"); + + b.Property("RoleId") + .HasColumnType("uniqueidentifier"); + + b.Property("RoleName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.HasKey("UserId", "RoleId"); + + b.ToTable("user_role", (string)null); + }); + + modelBuilder.Entity("NetCorePal.Extensions.DistributedTransactions.CAP.Persistence.CapLock", b => + { + b.Property("Key") + .HasMaxLength(128) + .HasColumnType("nvarchar(128)"); + + b.Property("Instance") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.Property("LastLockTime") + .HasColumnType("datetime2(7)"); + + b.HasKey("Key"); + + b.ToTable("CAPLock", (string)null); + }); + + modelBuilder.Entity("NetCorePal.Extensions.DistributedTransactions.CAP.Persistence.PublishedMessage", b => + { + b.Property("Id") + .HasColumnType("bigint"); + + b.Property("Added") + .HasColumnType("datetime2(7)"); + + b.Property("Content") + .HasColumnType("nvarchar(max)"); + + b.Property("ExpiresAt") + .HasColumnType("datetime2(7)"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.Property("Retries") + .HasColumnType("int"); + + b.Property("StatusName") + .IsRequired() + .HasMaxLength(40) + .HasColumnType("nvarchar(40)"); + + b.Property("Version") + .HasMaxLength(20) + .HasColumnType("nvarchar(20)"); + + b.HasKey("Id"); + + b.HasIndex(new[] { "ExpiresAt", "StatusName" }, "IX_ExpiresAt_StatusName"); + + b.HasIndex(new[] { "Version", "ExpiresAt", "StatusName" }, "IX_Version_ExpiresAt_StatusName"); + + b.ToTable("CAPPublishedMessage", (string)null); + }); + + modelBuilder.Entity("NetCorePal.Extensions.DistributedTransactions.CAP.Persistence.ReceivedMessage", b => + { + b.Property("Id") + .HasColumnType("bigint"); + + b.Property("Added") + .HasColumnType("datetime2(7)"); + + b.Property("Content") + .HasColumnType("nvarchar(max)"); + + b.Property("ExpiresAt") + .HasColumnType("datetime2(7)"); + + b.Property("Group") + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(400) + .HasColumnType("nvarchar(400)"); + + b.Property("Retries") + .HasColumnType("int"); + + b.Property("StatusName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.Property("Version") + .HasMaxLength(20) + .HasColumnType("nvarchar(20)"); + + b.HasKey("Id"); + + b.HasIndex(new[] { "ExpiresAt", "StatusName" }, "IX_ExpiresAt_StatusName"); + + b.HasIndex(new[] { "Version", "ExpiresAt", "StatusName" }, "IX_Version_ExpiresAt_StatusName"); + + b.ToTable("CAPReceivedMessage", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.RolePermission", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.RoleAggregate.Role", null) + .WithMany("Permissions") + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserDept", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.UserAggregate.User", null) + .WithOne("Dept") + .HasForeignKey("ABC.Template.Domain.AggregatesModel.UserAggregate.UserDept", "UserId") + .OnDelete(DeleteBehavior.ClientCascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRefreshToken", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.UserAggregate.User", null) + .WithMany("RefreshTokens") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRole", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.UserAggregate.User", null) + .WithMany("Roles") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.Role", b => + { + b.Navigation("Permissions"); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.User", b => + { + b.Navigation("Dept") + .IsRequired(); + + b.Navigation("RefreshTokens"); + + b.Navigation("Roles"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/template/src/ABC.Template.Infrastructure/MigrationsAll/SqlServer-net9.0/20251225065030_Init.Designer.cs b/template/src/ABC.Template.Infrastructure/MigrationsAll/SqlServer-net10.0/20260122054552_Init.Designer.cs similarity index 76% rename from template/src/ABC.Template.Infrastructure/MigrationsAll/SqlServer-net9.0/20251225065030_Init.Designer.cs rename to template/src/ABC.Template.Infrastructure/MigrationsAll/SqlServer-net10.0/20260122054552_Init.Designer.cs index 6475ecce..db25373f 100644 --- a/template/src/ABC.Template.Infrastructure/MigrationsAll/SqlServer-net9.0/20251225065030_Init.Designer.cs +++ b/template/src/ABC.Template.Infrastructure/MigrationsAll/SqlServer-net10.0/20260122054552_Init.Designer.cs @@ -1,18 +1,18 @@ // using System; +using ABC.Template.Infrastructure; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using ABC.Template.Infrastructure; #nullable disable namespace ABC.Template.Infrastructure.Migrations { [DbContext(typeof(ApplicationDbContext))] - [Migration("20251225065030_Init")] + [Migration("20260122054552_Init")] partial class Init { /// @@ -126,47 +126,6 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.ToTable("CAPReceivedMessage", (string)null); }); - - modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.DeliverAggregate.DeliverRecord", b => - { - b.Property("Id") - .HasColumnType("uniqueidentifier"); - - b.Property("OrderId") - .HasColumnType("uniqueidentifier"); - - b.HasKey("Id"); - - b.ToTable("deliverrecord", (string)null); - }); - - modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.OrderAggregate.Order", b => - { - b.Property("Id") - .HasColumnType("uniqueidentifier"); - - b.Property("Count") - .HasColumnType("int"); - - b.Property("Name") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("nvarchar(100)"); - - b.Property("Paid") - .HasColumnType("bit"); - - b.Property("RowVersion") - .IsConcurrencyToken() - .HasColumnType("int"); - - b.Property("UpdateTime") - .HasColumnType("datetimeoffset"); - - b.HasKey("Id"); - - b.ToTable("order", (string)null); - }); #pragma warning restore 612, 618 } } diff --git a/template/src/ABC.Template.Infrastructure/MigrationsAll/SqlServer-net8.0/20251225065020_Init.cs b/template/src/ABC.Template.Infrastructure/MigrationsAll/SqlServer-net10.0/20260122054552_Init.cs similarity index 75% rename from template/src/ABC.Template.Infrastructure/MigrationsAll/SqlServer-net8.0/20251225065020_Init.cs rename to template/src/ABC.Template.Infrastructure/MigrationsAll/SqlServer-net10.0/20260122054552_Init.cs index 00cc1805..dabb2f4f 100644 --- a/template/src/ABC.Template.Infrastructure/MigrationsAll/SqlServer-net8.0/20251225065020_Init.cs +++ b/template/src/ABC.Template.Infrastructure/MigrationsAll/SqlServer-net10.0/20260122054552_Init.cs @@ -61,34 +61,6 @@ protected override void Up(MigrationBuilder migrationBuilder) table.PrimaryKey("PK_CAPReceivedMessage", x => x.Id); }); - migrationBuilder.CreateTable( - name: "deliverrecord", - columns: table => new - { - Id = table.Column(type: "uniqueidentifier", nullable: false), - OrderId = table.Column(type: "uniqueidentifier", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_deliverrecord", x => x.Id); - }); - - migrationBuilder.CreateTable( - name: "order", - columns: table => new - { - Id = table.Column(type: "uniqueidentifier", nullable: false), - Paid = table.Column(type: "bit", nullable: false), - Name = table.Column(type: "nvarchar(100)", maxLength: 100, nullable: false), - Count = table.Column(type: "int", nullable: false), - RowVersion = table.Column(type: "int", nullable: false), - UpdateTime = table.Column(type: "datetimeoffset", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_order", x => x.Id); - }); - migrationBuilder.CreateIndex( name: "IX_ExpiresAt_StatusName", table: "CAPPublishedMessage", @@ -121,12 +93,6 @@ protected override void Down(MigrationBuilder migrationBuilder) migrationBuilder.DropTable( name: "CAPReceivedMessage"); - - migrationBuilder.DropTable( - name: "deliverrecord"); - - migrationBuilder.DropTable( - name: "order"); } } } diff --git a/template/src/ABC.Template.Infrastructure/MigrationsAll/SqlServer-net10.0/ApplicationDbContextModelSnapshot.cs b/template/src/ABC.Template.Infrastructure/MigrationsAll/SqlServer-net10.0/ApplicationDbContextModelSnapshot.cs index cd78fe21..619a9cef 100644 --- a/template/src/ABC.Template.Infrastructure/MigrationsAll/SqlServer-net10.0/ApplicationDbContextModelSnapshot.cs +++ b/template/src/ABC.Template.Infrastructure/MigrationsAll/SqlServer-net10.0/ApplicationDbContextModelSnapshot.cs @@ -1,10 +1,10 @@ // using System; +using ABC.Template.Infrastructure; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using ABC.Template.Infrastructure; #nullable disable @@ -123,47 +123,6 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.ToTable("CAPReceivedMessage", (string)null); }); - - modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.DeliverAggregate.DeliverRecord", b => - { - b.Property("Id") - .HasColumnType("uniqueidentifier"); - - b.Property("OrderId") - .HasColumnType("uniqueidentifier"); - - b.HasKey("Id"); - - b.ToTable("deliverrecord", (string)null); - }); - - modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.OrderAggregate.Order", b => - { - b.Property("Id") - .HasColumnType("uniqueidentifier"); - - b.Property("Count") - .HasColumnType("int"); - - b.Property("Name") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("nvarchar(100)"); - - b.Property("Paid") - .HasColumnType("bit"); - - b.Property("RowVersion") - .IsConcurrencyToken() - .HasColumnType("int"); - - b.Property("UpdateTime") - .HasColumnType("datetimeoffset"); - - b.HasKey("Id"); - - b.ToTable("order", (string)null); - }); #pragma warning restore 612, 618 } } diff --git a/template/src/ABC.Template.Infrastructure/MigrationsAll/SqlServer-net8.0-admin/20260122054522_Init.Designer.cs b/template/src/ABC.Template.Infrastructure/MigrationsAll/SqlServer-net8.0-admin/20260122054522_Init.Designer.cs new file mode 100644 index 00000000..aabf8725 --- /dev/null +++ b/template/src/ABC.Template.Infrastructure/MigrationsAll/SqlServer-net8.0-admin/20260122054522_Init.Designer.cs @@ -0,0 +1,432 @@ +// +using System; +using ABC.Template.Infrastructure; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace ABC.Template.Infrastructure.Migrations +{ + [DbContext(typeof(ApplicationDbContext))] + [Migration("20260122054522_Init")] + partial class Init + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "8.0.10") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.DeptAggregate.Dept", b => + { + b.Property("Id") + .HasColumnType("bigint"); + + b.Property("CreatedAt") + .HasColumnType("datetimeoffset"); + + b.Property("DeletedAt") + .HasColumnType("datetimeoffset"); + + b.Property("IsDeleted") + .HasColumnType("bit"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.Property("ParentId") + .HasColumnType("bigint"); + + b.Property("Remark") + .IsRequired() + .HasMaxLength(500) + .HasColumnType("nvarchar(500)"); + + b.Property("Status") + .HasColumnType("int"); + + b.Property("UpdateTime") + .HasColumnType("datetimeoffset"); + + b.HasKey("Id"); + + b.HasIndex("IsDeleted"); + + b.HasIndex("ParentId"); + + b.HasIndex("Status"); + + b.ToTable("dept", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.Role", b => + { + b.Property("Id") + .HasColumnType("uniqueidentifier"); + + b.Property("CreatedAt") + .HasColumnType("datetimeoffset"); + + b.Property("DeletedAt") + .HasColumnType("datetimeoffset"); + + b.Property("Description") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.Property("IsActive") + .HasColumnType("bit"); + + b.Property("IsDeleted") + .HasColumnType("bit"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.HasKey("Id"); + + b.HasIndex("Name") + .IsUnique(); + + b.ToTable("role", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.RolePermission", b => + { + b.Property("RoleId") + .HasColumnType("uniqueidentifier"); + + b.Property("PermissionCode") + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.Property("PermissionDescription") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.Property("PermissionName") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.HasKey("RoleId", "PermissionCode"); + + b.ToTable("role_permission", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.User", b => + { + b.Property("Id") + .HasColumnType("bigint"); + + b.Property("Age") + .HasColumnType("int"); + + b.Property("BirthDate") + .HasColumnType("datetimeoffset"); + + b.Property("CreatedAt") + .HasColumnType("datetimeoffset"); + + b.Property("DeletedAt") + .HasColumnType("datetimeoffset"); + + b.Property("Email") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.Property("Gender") + .IsRequired() + .HasMaxLength(10) + .HasColumnType("nvarchar(10)"); + + b.Property("IsActive") + .HasColumnType("bit"); + + b.Property("IsDeleted") + .HasColumnType("bit"); + + b.Property("LastLoginTime") + .HasColumnType("datetimeoffset"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.Property("PasswordHash") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("nvarchar(255)"); + + b.Property("Phone") + .IsRequired() + .HasMaxLength(20) + .HasColumnType("nvarchar(20)"); + + b.Property("RealName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.Property("Status") + .HasColumnType("int"); + + b.Property("UpdateTime") + .HasColumnType("datetimeoffset"); + + b.HasKey("Id"); + + b.HasIndex("Email"); + + b.HasIndex("Name"); + + b.ToTable("user", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserDept", b => + { + b.Property("UserId") + .HasColumnType("bigint"); + + b.Property("AssignedAt") + .HasColumnType("datetimeoffset"); + + b.Property("DeptId") + .HasColumnType("bigint"); + + b.Property("DeptName") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.HasKey("UserId"); + + b.HasIndex("DeptId"); + + b.HasIndex("UserId"); + + b.ToTable("user_dept", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRefreshToken", b => + { + b.Property("Id") + .HasColumnType("bigint"); + + b.Property("CreatedTime") + .HasColumnType("datetimeoffset"); + + b.Property("ExpiresTime") + .HasColumnType("datetimeoffset"); + + b.Property("IsRevoked") + .HasColumnType("bit"); + + b.Property("IsUsed") + .HasColumnType("bit"); + + b.Property("Token") + .IsRequired() + .HasMaxLength(500) + .HasColumnType("nvarchar(500)"); + + b.Property("UserId") + .HasColumnType("bigint"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("user_refresh_token", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRole", b => + { + b.Property("UserId") + .HasColumnType("bigint"); + + b.Property("RoleId") + .HasColumnType("uniqueidentifier"); + + b.Property("RoleName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.HasKey("UserId", "RoleId"); + + b.ToTable("user_role", (string)null); + }); + + modelBuilder.Entity("NetCorePal.Extensions.DistributedTransactions.CAP.Persistence.CapLock", b => + { + b.Property("Key") + .HasMaxLength(128) + .HasColumnType("nvarchar(128)"); + + b.Property("Instance") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.Property("LastLockTime") + .HasColumnType("datetime2(7)"); + + b.HasKey("Key"); + + b.ToTable("CAPLock", (string)null); + }); + + modelBuilder.Entity("NetCorePal.Extensions.DistributedTransactions.CAP.Persistence.PublishedMessage", b => + { + b.Property("Id") + .HasColumnType("bigint"); + + b.Property("Added") + .HasColumnType("datetime2(7)"); + + b.Property("Content") + .HasColumnType("nvarchar(max)"); + + b.Property("ExpiresAt") + .HasColumnType("datetime2(7)"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.Property("Retries") + .HasColumnType("int"); + + b.Property("StatusName") + .IsRequired() + .HasMaxLength(40) + .HasColumnType("nvarchar(40)"); + + b.Property("Version") + .HasMaxLength(20) + .HasColumnType("nvarchar(20)"); + + b.HasKey("Id"); + + b.HasIndex(new[] { "ExpiresAt", "StatusName" }, "IX_ExpiresAt_StatusName"); + + b.HasIndex(new[] { "Version", "ExpiresAt", "StatusName" }, "IX_Version_ExpiresAt_StatusName"); + + b.ToTable("CAPPublishedMessage", (string)null); + }); + + modelBuilder.Entity("NetCorePal.Extensions.DistributedTransactions.CAP.Persistence.ReceivedMessage", b => + { + b.Property("Id") + .HasColumnType("bigint"); + + b.Property("Added") + .HasColumnType("datetime2(7)"); + + b.Property("Content") + .HasColumnType("nvarchar(max)"); + + b.Property("ExpiresAt") + .HasColumnType("datetime2(7)"); + + b.Property("Group") + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(400) + .HasColumnType("nvarchar(400)"); + + b.Property("Retries") + .HasColumnType("int"); + + b.Property("StatusName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.Property("Version") + .HasMaxLength(20) + .HasColumnType("nvarchar(20)"); + + b.HasKey("Id"); + + b.HasIndex(new[] { "ExpiresAt", "StatusName" }, "IX_ExpiresAt_StatusName"); + + b.HasIndex(new[] { "Version", "ExpiresAt", "StatusName" }, "IX_Version_ExpiresAt_StatusName"); + + b.ToTable("CAPReceivedMessage", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.RolePermission", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.RoleAggregate.Role", null) + .WithMany("Permissions") + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserDept", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.UserAggregate.User", null) + .WithOne("Dept") + .HasForeignKey("ABC.Template.Domain.AggregatesModel.UserAggregate.UserDept", "UserId") + .OnDelete(DeleteBehavior.ClientCascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRefreshToken", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.UserAggregate.User", null) + .WithMany("RefreshTokens") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRole", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.UserAggregate.User", null) + .WithMany("Roles") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.Role", b => + { + b.Navigation("Permissions"); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.User", b => + { + b.Navigation("Dept") + .IsRequired(); + + b.Navigation("RefreshTokens"); + + b.Navigation("Roles"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/template/src/ABC.Template.Infrastructure/MigrationsAll/SqlServer-net8.0-admin/20260122054522_Init.cs b/template/src/ABC.Template.Infrastructure/MigrationsAll/SqlServer-net8.0-admin/20260122054522_Init.cs new file mode 100644 index 00000000..e59b8bdf --- /dev/null +++ b/template/src/ABC.Template.Infrastructure/MigrationsAll/SqlServer-net8.0-admin/20260122054522_Init.cs @@ -0,0 +1,308 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace ABC.Template.Infrastructure.Migrations +{ + /// + public partial class Init : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "CAPLock", + columns: table => new + { + Key = table.Column(type: "nvarchar(128)", maxLength: 128, nullable: false), + Instance = table.Column(type: "nvarchar(256)", maxLength: 256, nullable: true), + LastLockTime = table.Column(type: "datetime2(7)", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_CAPLock", x => x.Key); + }); + + migrationBuilder.CreateTable( + name: "CAPPublishedMessage", + columns: table => new + { + Id = table.Column(type: "bigint", nullable: false), + Version = table.Column(type: "nvarchar(20)", maxLength: 20, nullable: true), + Name = table.Column(type: "nvarchar(200)", maxLength: 200, nullable: false), + Content = table.Column(type: "nvarchar(max)", nullable: true), + Retries = table.Column(type: "int", nullable: true), + Added = table.Column(type: "datetime2(7)", nullable: false), + ExpiresAt = table.Column(type: "datetime2(7)", nullable: true), + StatusName = table.Column(type: "nvarchar(40)", maxLength: 40, nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_CAPPublishedMessage", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "CAPReceivedMessage", + columns: table => new + { + Id = table.Column(type: "bigint", nullable: false), + Version = table.Column(type: "nvarchar(20)", maxLength: 20, nullable: true), + Name = table.Column(type: "nvarchar(400)", maxLength: 400, nullable: false), + Group = table.Column(type: "nvarchar(200)", maxLength: 200, nullable: true), + Content = table.Column(type: "nvarchar(max)", nullable: true), + Retries = table.Column(type: "int", nullable: true), + Added = table.Column(type: "datetime2(7)", nullable: false), + ExpiresAt = table.Column(type: "datetime2(7)", nullable: true), + StatusName = table.Column(type: "nvarchar(50)", maxLength: 50, nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_CAPReceivedMessage", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "dept", + columns: table => new + { + Id = table.Column(type: "bigint", nullable: false), + Name = table.Column(type: "nvarchar(100)", maxLength: 100, nullable: false), + Remark = table.Column(type: "nvarchar(500)", maxLength: 500, nullable: false), + ParentId = table.Column(type: "bigint", nullable: false), + Status = table.Column(type: "int", nullable: false), + CreatedAt = table.Column(type: "datetimeoffset", nullable: false), + IsDeleted = table.Column(type: "bit", nullable: false), + DeletedAt = table.Column(type: "datetimeoffset", nullable: false), + UpdateTime = table.Column(type: "datetimeoffset", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_dept", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "role", + columns: table => new + { + Id = table.Column(type: "uniqueidentifier", nullable: false), + Name = table.Column(type: "nvarchar(50)", maxLength: 50, nullable: false), + Description = table.Column(type: "nvarchar(200)", maxLength: 200, nullable: false), + CreatedAt = table.Column(type: "datetimeoffset", nullable: false), + IsActive = table.Column(type: "bit", nullable: false), + IsDeleted = table.Column(type: "bit", nullable: false), + DeletedAt = table.Column(type: "datetimeoffset", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_role", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "user", + columns: table => new + { + Id = table.Column(type: "bigint", nullable: false), + Name = table.Column(type: "nvarchar(50)", maxLength: 50, nullable: false), + Email = table.Column(type: "nvarchar(100)", maxLength: 100, nullable: false), + Phone = table.Column(type: "nvarchar(20)", maxLength: 20, nullable: false), + RealName = table.Column(type: "nvarchar(50)", maxLength: 50, nullable: false), + Status = table.Column(type: "int", nullable: false), + PasswordHash = table.Column(type: "nvarchar(255)", maxLength: 255, nullable: false), + IsActive = table.Column(type: "bit", nullable: false), + CreatedAt = table.Column(type: "datetimeoffset", nullable: false), + LastLoginTime = table.Column(type: "datetimeoffset", nullable: true), + UpdateTime = table.Column(type: "datetimeoffset", nullable: false), + IsDeleted = table.Column(type: "bit", nullable: false), + DeletedAt = table.Column(type: "datetimeoffset", nullable: false), + Gender = table.Column(type: "nvarchar(10)", maxLength: 10, nullable: false), + Age = table.Column(type: "int", nullable: false), + BirthDate = table.Column(type: "datetimeoffset", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_user", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "role_permission", + columns: table => new + { + RoleId = table.Column(type: "uniqueidentifier", nullable: false), + PermissionCode = table.Column(type: "nvarchar(100)", maxLength: 100, nullable: false), + PermissionName = table.Column(type: "nvarchar(100)", maxLength: 100, nullable: false), + PermissionDescription = table.Column(type: "nvarchar(200)", maxLength: 200, nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_role_permission", x => new { x.RoleId, x.PermissionCode }); + table.ForeignKey( + name: "FK_role_permission_role_RoleId", + column: x => x.RoleId, + principalTable: "role", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "user_dept", + columns: table => new + { + UserId = table.Column(type: "bigint", nullable: false), + DeptId = table.Column(type: "bigint", nullable: false), + DeptName = table.Column(type: "nvarchar(100)", maxLength: 100, nullable: false), + AssignedAt = table.Column(type: "datetimeoffset", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_user_dept", x => x.UserId); + table.ForeignKey( + name: "FK_user_dept_user_UserId", + column: x => x.UserId, + principalTable: "user", + principalColumn: "Id"); + }); + + migrationBuilder.CreateTable( + name: "user_refresh_token", + columns: table => new + { + Id = table.Column(type: "bigint", nullable: false), + UserId = table.Column(type: "bigint", nullable: false), + Token = table.Column(type: "nvarchar(500)", maxLength: 500, nullable: false), + CreatedTime = table.Column(type: "datetimeoffset", nullable: false), + ExpiresTime = table.Column(type: "datetimeoffset", nullable: false), + IsUsed = table.Column(type: "bit", nullable: false), + IsRevoked = table.Column(type: "bit", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_user_refresh_token", x => x.Id); + table.ForeignKey( + name: "FK_user_refresh_token_user_UserId", + column: x => x.UserId, + principalTable: "user", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "user_role", + columns: table => new + { + UserId = table.Column(type: "bigint", nullable: false), + RoleId = table.Column(type: "uniqueidentifier", nullable: false), + RoleName = table.Column(type: "nvarchar(50)", maxLength: 50, nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_user_role", x => new { x.UserId, x.RoleId }); + table.ForeignKey( + name: "FK_user_role_user_UserId", + column: x => x.UserId, + principalTable: "user", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_ExpiresAt_StatusName", + table: "CAPPublishedMessage", + columns: new[] { "ExpiresAt", "StatusName" }); + + migrationBuilder.CreateIndex( + name: "IX_Version_ExpiresAt_StatusName", + table: "CAPPublishedMessage", + columns: new[] { "Version", "ExpiresAt", "StatusName" }); + + migrationBuilder.CreateIndex( + name: "IX_ExpiresAt_StatusName", + table: "CAPReceivedMessage", + columns: new[] { "ExpiresAt", "StatusName" }); + + migrationBuilder.CreateIndex( + name: "IX_Version_ExpiresAt_StatusName", + table: "CAPReceivedMessage", + columns: new[] { "Version", "ExpiresAt", "StatusName" }); + + migrationBuilder.CreateIndex( + name: "IX_dept_IsDeleted", + table: "dept", + column: "IsDeleted"); + + migrationBuilder.CreateIndex( + name: "IX_dept_ParentId", + table: "dept", + column: "ParentId"); + + migrationBuilder.CreateIndex( + name: "IX_dept_Status", + table: "dept", + column: "Status"); + + migrationBuilder.CreateIndex( + name: "IX_role_Name", + table: "role", + column: "Name", + unique: true); + + migrationBuilder.CreateIndex( + name: "IX_user_Email", + table: "user", + column: "Email"); + + migrationBuilder.CreateIndex( + name: "IX_user_Name", + table: "user", + column: "Name"); + + migrationBuilder.CreateIndex( + name: "IX_user_dept_DeptId", + table: "user_dept", + column: "DeptId"); + + migrationBuilder.CreateIndex( + name: "IX_user_dept_UserId", + table: "user_dept", + column: "UserId"); + + migrationBuilder.CreateIndex( + name: "IX_user_refresh_token_UserId", + table: "user_refresh_token", + column: "UserId"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "CAPLock"); + + migrationBuilder.DropTable( + name: "CAPPublishedMessage"); + + migrationBuilder.DropTable( + name: "CAPReceivedMessage"); + + migrationBuilder.DropTable( + name: "dept"); + + migrationBuilder.DropTable( + name: "role_permission"); + + migrationBuilder.DropTable( + name: "user_dept"); + + migrationBuilder.DropTable( + name: "user_refresh_token"); + + migrationBuilder.DropTable( + name: "user_role"); + + migrationBuilder.DropTable( + name: "role"); + + migrationBuilder.DropTable( + name: "user"); + } + } +} diff --git a/template/src/ABC.Template.Infrastructure/MigrationsAll/SqlServer-net8.0-admin/ApplicationDbContextModelSnapshot.cs b/template/src/ABC.Template.Infrastructure/MigrationsAll/SqlServer-net8.0-admin/ApplicationDbContextModelSnapshot.cs new file mode 100644 index 00000000..a9f47834 --- /dev/null +++ b/template/src/ABC.Template.Infrastructure/MigrationsAll/SqlServer-net8.0-admin/ApplicationDbContextModelSnapshot.cs @@ -0,0 +1,429 @@ +// +using System; +using ABC.Template.Infrastructure; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace ABC.Template.Infrastructure.Migrations +{ + [DbContext(typeof(ApplicationDbContext))] + partial class ApplicationDbContextModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "8.0.10") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.DeptAggregate.Dept", b => + { + b.Property("Id") + .HasColumnType("bigint"); + + b.Property("CreatedAt") + .HasColumnType("datetimeoffset"); + + b.Property("DeletedAt") + .HasColumnType("datetimeoffset"); + + b.Property("IsDeleted") + .HasColumnType("bit"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.Property("ParentId") + .HasColumnType("bigint"); + + b.Property("Remark") + .IsRequired() + .HasMaxLength(500) + .HasColumnType("nvarchar(500)"); + + b.Property("Status") + .HasColumnType("int"); + + b.Property("UpdateTime") + .HasColumnType("datetimeoffset"); + + b.HasKey("Id"); + + b.HasIndex("IsDeleted"); + + b.HasIndex("ParentId"); + + b.HasIndex("Status"); + + b.ToTable("dept", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.Role", b => + { + b.Property("Id") + .HasColumnType("uniqueidentifier"); + + b.Property("CreatedAt") + .HasColumnType("datetimeoffset"); + + b.Property("DeletedAt") + .HasColumnType("datetimeoffset"); + + b.Property("Description") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.Property("IsActive") + .HasColumnType("bit"); + + b.Property("IsDeleted") + .HasColumnType("bit"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.HasKey("Id"); + + b.HasIndex("Name") + .IsUnique(); + + b.ToTable("role", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.RolePermission", b => + { + b.Property("RoleId") + .HasColumnType("uniqueidentifier"); + + b.Property("PermissionCode") + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.Property("PermissionDescription") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.Property("PermissionName") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.HasKey("RoleId", "PermissionCode"); + + b.ToTable("role_permission", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.User", b => + { + b.Property("Id") + .HasColumnType("bigint"); + + b.Property("Age") + .HasColumnType("int"); + + b.Property("BirthDate") + .HasColumnType("datetimeoffset"); + + b.Property("CreatedAt") + .HasColumnType("datetimeoffset"); + + b.Property("DeletedAt") + .HasColumnType("datetimeoffset"); + + b.Property("Email") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.Property("Gender") + .IsRequired() + .HasMaxLength(10) + .HasColumnType("nvarchar(10)"); + + b.Property("IsActive") + .HasColumnType("bit"); + + b.Property("IsDeleted") + .HasColumnType("bit"); + + b.Property("LastLoginTime") + .HasColumnType("datetimeoffset"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.Property("PasswordHash") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("nvarchar(255)"); + + b.Property("Phone") + .IsRequired() + .HasMaxLength(20) + .HasColumnType("nvarchar(20)"); + + b.Property("RealName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.Property("Status") + .HasColumnType("int"); + + b.Property("UpdateTime") + .HasColumnType("datetimeoffset"); + + b.HasKey("Id"); + + b.HasIndex("Email"); + + b.HasIndex("Name"); + + b.ToTable("user", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserDept", b => + { + b.Property("UserId") + .HasColumnType("bigint"); + + b.Property("AssignedAt") + .HasColumnType("datetimeoffset"); + + b.Property("DeptId") + .HasColumnType("bigint"); + + b.Property("DeptName") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.HasKey("UserId"); + + b.HasIndex("DeptId"); + + b.HasIndex("UserId"); + + b.ToTable("user_dept", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRefreshToken", b => + { + b.Property("Id") + .HasColumnType("bigint"); + + b.Property("CreatedTime") + .HasColumnType("datetimeoffset"); + + b.Property("ExpiresTime") + .HasColumnType("datetimeoffset"); + + b.Property("IsRevoked") + .HasColumnType("bit"); + + b.Property("IsUsed") + .HasColumnType("bit"); + + b.Property("Token") + .IsRequired() + .HasMaxLength(500) + .HasColumnType("nvarchar(500)"); + + b.Property("UserId") + .HasColumnType("bigint"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("user_refresh_token", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRole", b => + { + b.Property("UserId") + .HasColumnType("bigint"); + + b.Property("RoleId") + .HasColumnType("uniqueidentifier"); + + b.Property("RoleName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.HasKey("UserId", "RoleId"); + + b.ToTable("user_role", (string)null); + }); + + modelBuilder.Entity("NetCorePal.Extensions.DistributedTransactions.CAP.Persistence.CapLock", b => + { + b.Property("Key") + .HasMaxLength(128) + .HasColumnType("nvarchar(128)"); + + b.Property("Instance") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.Property("LastLockTime") + .HasColumnType("datetime2(7)"); + + b.HasKey("Key"); + + b.ToTable("CAPLock", (string)null); + }); + + modelBuilder.Entity("NetCorePal.Extensions.DistributedTransactions.CAP.Persistence.PublishedMessage", b => + { + b.Property("Id") + .HasColumnType("bigint"); + + b.Property("Added") + .HasColumnType("datetime2(7)"); + + b.Property("Content") + .HasColumnType("nvarchar(max)"); + + b.Property("ExpiresAt") + .HasColumnType("datetime2(7)"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.Property("Retries") + .HasColumnType("int"); + + b.Property("StatusName") + .IsRequired() + .HasMaxLength(40) + .HasColumnType("nvarchar(40)"); + + b.Property("Version") + .HasMaxLength(20) + .HasColumnType("nvarchar(20)"); + + b.HasKey("Id"); + + b.HasIndex(new[] { "ExpiresAt", "StatusName" }, "IX_ExpiresAt_StatusName"); + + b.HasIndex(new[] { "Version", "ExpiresAt", "StatusName" }, "IX_Version_ExpiresAt_StatusName"); + + b.ToTable("CAPPublishedMessage", (string)null); + }); + + modelBuilder.Entity("NetCorePal.Extensions.DistributedTransactions.CAP.Persistence.ReceivedMessage", b => + { + b.Property("Id") + .HasColumnType("bigint"); + + b.Property("Added") + .HasColumnType("datetime2(7)"); + + b.Property("Content") + .HasColumnType("nvarchar(max)"); + + b.Property("ExpiresAt") + .HasColumnType("datetime2(7)"); + + b.Property("Group") + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(400) + .HasColumnType("nvarchar(400)"); + + b.Property("Retries") + .HasColumnType("int"); + + b.Property("StatusName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.Property("Version") + .HasMaxLength(20) + .HasColumnType("nvarchar(20)"); + + b.HasKey("Id"); + + b.HasIndex(new[] { "ExpiresAt", "StatusName" }, "IX_ExpiresAt_StatusName"); + + b.HasIndex(new[] { "Version", "ExpiresAt", "StatusName" }, "IX_Version_ExpiresAt_StatusName"); + + b.ToTable("CAPReceivedMessage", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.RolePermission", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.RoleAggregate.Role", null) + .WithMany("Permissions") + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserDept", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.UserAggregate.User", null) + .WithOne("Dept") + .HasForeignKey("ABC.Template.Domain.AggregatesModel.UserAggregate.UserDept", "UserId") + .OnDelete(DeleteBehavior.ClientCascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRefreshToken", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.UserAggregate.User", null) + .WithMany("RefreshTokens") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRole", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.UserAggregate.User", null) + .WithMany("Roles") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.Role", b => + { + b.Navigation("Permissions"); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.User", b => + { + b.Navigation("Dept") + .IsRequired(); + + b.Navigation("RefreshTokens"); + + b.Navigation("Roles"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/template/src/ABC.Template.Infrastructure/MigrationsAll/SqlServer-net8.0/20251225065020_Init.Designer.cs b/template/src/ABC.Template.Infrastructure/MigrationsAll/SqlServer-net8.0/20260122054513_Init.Designer.cs similarity index 76% rename from template/src/ABC.Template.Infrastructure/MigrationsAll/SqlServer-net8.0/20251225065020_Init.Designer.cs rename to template/src/ABC.Template.Infrastructure/MigrationsAll/SqlServer-net8.0/20260122054513_Init.Designer.cs index 41a4dc5c..ec7bef4b 100644 --- a/template/src/ABC.Template.Infrastructure/MigrationsAll/SqlServer-net8.0/20251225065020_Init.Designer.cs +++ b/template/src/ABC.Template.Infrastructure/MigrationsAll/SqlServer-net8.0/20260122054513_Init.Designer.cs @@ -1,18 +1,18 @@ // using System; +using ABC.Template.Infrastructure; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using ABC.Template.Infrastructure; #nullable disable namespace ABC.Template.Infrastructure.Migrations { [DbContext(typeof(ApplicationDbContext))] - [Migration("20251225065020_Init")] + [Migration("20260122054513_Init")] partial class Init { /// @@ -126,47 +126,6 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.ToTable("CAPReceivedMessage", (string)null); }); - - modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.DeliverAggregate.DeliverRecord", b => - { - b.Property("Id") - .HasColumnType("uniqueidentifier"); - - b.Property("OrderId") - .HasColumnType("uniqueidentifier"); - - b.HasKey("Id"); - - b.ToTable("deliverrecord", (string)null); - }); - - modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.OrderAggregate.Order", b => - { - b.Property("Id") - .HasColumnType("uniqueidentifier"); - - b.Property("Count") - .HasColumnType("int"); - - b.Property("Name") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("nvarchar(100)"); - - b.Property("Paid") - .HasColumnType("bit"); - - b.Property("RowVersion") - .IsConcurrencyToken() - .HasColumnType("int"); - - b.Property("UpdateTime") - .HasColumnType("datetimeoffset"); - - b.HasKey("Id"); - - b.ToTable("order", (string)null); - }); #pragma warning restore 612, 618 } } diff --git a/template/src/ABC.Template.Infrastructure/MigrationsAll/SqlServer-net9.0/20251225065030_Init.cs b/template/src/ABC.Template.Infrastructure/MigrationsAll/SqlServer-net8.0/20260122054513_Init.cs similarity index 75% rename from template/src/ABC.Template.Infrastructure/MigrationsAll/SqlServer-net9.0/20251225065030_Init.cs rename to template/src/ABC.Template.Infrastructure/MigrationsAll/SqlServer-net8.0/20260122054513_Init.cs index 00cc1805..dabb2f4f 100644 --- a/template/src/ABC.Template.Infrastructure/MigrationsAll/SqlServer-net9.0/20251225065030_Init.cs +++ b/template/src/ABC.Template.Infrastructure/MigrationsAll/SqlServer-net8.0/20260122054513_Init.cs @@ -61,34 +61,6 @@ protected override void Up(MigrationBuilder migrationBuilder) table.PrimaryKey("PK_CAPReceivedMessage", x => x.Id); }); - migrationBuilder.CreateTable( - name: "deliverrecord", - columns: table => new - { - Id = table.Column(type: "uniqueidentifier", nullable: false), - OrderId = table.Column(type: "uniqueidentifier", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_deliverrecord", x => x.Id); - }); - - migrationBuilder.CreateTable( - name: "order", - columns: table => new - { - Id = table.Column(type: "uniqueidentifier", nullable: false), - Paid = table.Column(type: "bit", nullable: false), - Name = table.Column(type: "nvarchar(100)", maxLength: 100, nullable: false), - Count = table.Column(type: "int", nullable: false), - RowVersion = table.Column(type: "int", nullable: false), - UpdateTime = table.Column(type: "datetimeoffset", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_order", x => x.Id); - }); - migrationBuilder.CreateIndex( name: "IX_ExpiresAt_StatusName", table: "CAPPublishedMessage", @@ -121,12 +93,6 @@ protected override void Down(MigrationBuilder migrationBuilder) migrationBuilder.DropTable( name: "CAPReceivedMessage"); - - migrationBuilder.DropTable( - name: "deliverrecord"); - - migrationBuilder.DropTable( - name: "order"); } } } diff --git a/template/src/ABC.Template.Infrastructure/MigrationsAll/SqlServer-net8.0/ApplicationDbContextModelSnapshot.cs b/template/src/ABC.Template.Infrastructure/MigrationsAll/SqlServer-net8.0/ApplicationDbContextModelSnapshot.cs index c06b22b0..8f0af05e 100644 --- a/template/src/ABC.Template.Infrastructure/MigrationsAll/SqlServer-net8.0/ApplicationDbContextModelSnapshot.cs +++ b/template/src/ABC.Template.Infrastructure/MigrationsAll/SqlServer-net8.0/ApplicationDbContextModelSnapshot.cs @@ -1,10 +1,10 @@ // using System; +using ABC.Template.Infrastructure; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using ABC.Template.Infrastructure; #nullable disable @@ -123,47 +123,6 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.ToTable("CAPReceivedMessage", (string)null); }); - - modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.DeliverAggregate.DeliverRecord", b => - { - b.Property("Id") - .HasColumnType("uniqueidentifier"); - - b.Property("OrderId") - .HasColumnType("uniqueidentifier"); - - b.HasKey("Id"); - - b.ToTable("deliverrecord", (string)null); - }); - - modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.OrderAggregate.Order", b => - { - b.Property("Id") - .HasColumnType("uniqueidentifier"); - - b.Property("Count") - .HasColumnType("int"); - - b.Property("Name") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("nvarchar(100)"); - - b.Property("Paid") - .HasColumnType("bit"); - - b.Property("RowVersion") - .IsConcurrencyToken() - .HasColumnType("int"); - - b.Property("UpdateTime") - .HasColumnType("datetimeoffset"); - - b.HasKey("Id"); - - b.ToTable("order", (string)null); - }); #pragma warning restore 612, 618 } } diff --git a/template/src/ABC.Template.Infrastructure/MigrationsAll/SqlServer-net9.0-admin/20260122054539_Init.Designer.cs b/template/src/ABC.Template.Infrastructure/MigrationsAll/SqlServer-net9.0-admin/20260122054539_Init.Designer.cs new file mode 100644 index 00000000..e4f684c1 --- /dev/null +++ b/template/src/ABC.Template.Infrastructure/MigrationsAll/SqlServer-net9.0-admin/20260122054539_Init.Designer.cs @@ -0,0 +1,432 @@ +// +using System; +using ABC.Template.Infrastructure; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace ABC.Template.Infrastructure.Migrations +{ + [DbContext(typeof(ApplicationDbContext))] + [Migration("20260122054539_Init")] + partial class Init + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "9.0.0") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.DeptAggregate.Dept", b => + { + b.Property("Id") + .HasColumnType("bigint"); + + b.Property("CreatedAt") + .HasColumnType("datetimeoffset"); + + b.Property("DeletedAt") + .HasColumnType("datetimeoffset"); + + b.Property("IsDeleted") + .HasColumnType("bit"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.Property("ParentId") + .HasColumnType("bigint"); + + b.Property("Remark") + .IsRequired() + .HasMaxLength(500) + .HasColumnType("nvarchar(500)"); + + b.Property("Status") + .HasColumnType("int"); + + b.Property("UpdateTime") + .HasColumnType("datetimeoffset"); + + b.HasKey("Id"); + + b.HasIndex("IsDeleted"); + + b.HasIndex("ParentId"); + + b.HasIndex("Status"); + + b.ToTable("dept", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.Role", b => + { + b.Property("Id") + .HasColumnType("uniqueidentifier"); + + b.Property("CreatedAt") + .HasColumnType("datetimeoffset"); + + b.Property("DeletedAt") + .HasColumnType("datetimeoffset"); + + b.Property("Description") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.Property("IsActive") + .HasColumnType("bit"); + + b.Property("IsDeleted") + .HasColumnType("bit"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.HasKey("Id"); + + b.HasIndex("Name") + .IsUnique(); + + b.ToTable("role", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.RolePermission", b => + { + b.Property("RoleId") + .HasColumnType("uniqueidentifier"); + + b.Property("PermissionCode") + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.Property("PermissionDescription") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.Property("PermissionName") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.HasKey("RoleId", "PermissionCode"); + + b.ToTable("role_permission", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.User", b => + { + b.Property("Id") + .HasColumnType("bigint"); + + b.Property("Age") + .HasColumnType("int"); + + b.Property("BirthDate") + .HasColumnType("datetimeoffset"); + + b.Property("CreatedAt") + .HasColumnType("datetimeoffset"); + + b.Property("DeletedAt") + .HasColumnType("datetimeoffset"); + + b.Property("Email") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.Property("Gender") + .IsRequired() + .HasMaxLength(10) + .HasColumnType("nvarchar(10)"); + + b.Property("IsActive") + .HasColumnType("bit"); + + b.Property("IsDeleted") + .HasColumnType("bit"); + + b.Property("LastLoginTime") + .HasColumnType("datetimeoffset"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.Property("PasswordHash") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("nvarchar(255)"); + + b.Property("Phone") + .IsRequired() + .HasMaxLength(20) + .HasColumnType("nvarchar(20)"); + + b.Property("RealName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.Property("Status") + .HasColumnType("int"); + + b.Property("UpdateTime") + .HasColumnType("datetimeoffset"); + + b.HasKey("Id"); + + b.HasIndex("Email"); + + b.HasIndex("Name"); + + b.ToTable("user", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserDept", b => + { + b.Property("UserId") + .HasColumnType("bigint"); + + b.Property("AssignedAt") + .HasColumnType("datetimeoffset"); + + b.Property("DeptId") + .HasColumnType("bigint"); + + b.Property("DeptName") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.HasKey("UserId"); + + b.HasIndex("DeptId"); + + b.HasIndex("UserId"); + + b.ToTable("user_dept", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRefreshToken", b => + { + b.Property("Id") + .HasColumnType("bigint"); + + b.Property("CreatedTime") + .HasColumnType("datetimeoffset"); + + b.Property("ExpiresTime") + .HasColumnType("datetimeoffset"); + + b.Property("IsRevoked") + .HasColumnType("bit"); + + b.Property("IsUsed") + .HasColumnType("bit"); + + b.Property("Token") + .IsRequired() + .HasMaxLength(500) + .HasColumnType("nvarchar(500)"); + + b.Property("UserId") + .HasColumnType("bigint"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("user_refresh_token", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRole", b => + { + b.Property("UserId") + .HasColumnType("bigint"); + + b.Property("RoleId") + .HasColumnType("uniqueidentifier"); + + b.Property("RoleName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.HasKey("UserId", "RoleId"); + + b.ToTable("user_role", (string)null); + }); + + modelBuilder.Entity("NetCorePal.Extensions.DistributedTransactions.CAP.Persistence.CapLock", b => + { + b.Property("Key") + .HasMaxLength(128) + .HasColumnType("nvarchar(128)"); + + b.Property("Instance") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.Property("LastLockTime") + .HasColumnType("datetime2(7)"); + + b.HasKey("Key"); + + b.ToTable("CAPLock", (string)null); + }); + + modelBuilder.Entity("NetCorePal.Extensions.DistributedTransactions.CAP.Persistence.PublishedMessage", b => + { + b.Property("Id") + .HasColumnType("bigint"); + + b.Property("Added") + .HasColumnType("datetime2(7)"); + + b.Property("Content") + .HasColumnType("nvarchar(max)"); + + b.Property("ExpiresAt") + .HasColumnType("datetime2(7)"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.Property("Retries") + .HasColumnType("int"); + + b.Property("StatusName") + .IsRequired() + .HasMaxLength(40) + .HasColumnType("nvarchar(40)"); + + b.Property("Version") + .HasMaxLength(20) + .HasColumnType("nvarchar(20)"); + + b.HasKey("Id"); + + b.HasIndex(new[] { "ExpiresAt", "StatusName" }, "IX_ExpiresAt_StatusName"); + + b.HasIndex(new[] { "Version", "ExpiresAt", "StatusName" }, "IX_Version_ExpiresAt_StatusName"); + + b.ToTable("CAPPublishedMessage", (string)null); + }); + + modelBuilder.Entity("NetCorePal.Extensions.DistributedTransactions.CAP.Persistence.ReceivedMessage", b => + { + b.Property("Id") + .HasColumnType("bigint"); + + b.Property("Added") + .HasColumnType("datetime2(7)"); + + b.Property("Content") + .HasColumnType("nvarchar(max)"); + + b.Property("ExpiresAt") + .HasColumnType("datetime2(7)"); + + b.Property("Group") + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(400) + .HasColumnType("nvarchar(400)"); + + b.Property("Retries") + .HasColumnType("int"); + + b.Property("StatusName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.Property("Version") + .HasMaxLength(20) + .HasColumnType("nvarchar(20)"); + + b.HasKey("Id"); + + b.HasIndex(new[] { "ExpiresAt", "StatusName" }, "IX_ExpiresAt_StatusName"); + + b.HasIndex(new[] { "Version", "ExpiresAt", "StatusName" }, "IX_Version_ExpiresAt_StatusName"); + + b.ToTable("CAPReceivedMessage", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.RolePermission", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.RoleAggregate.Role", null) + .WithMany("Permissions") + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserDept", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.UserAggregate.User", null) + .WithOne("Dept") + .HasForeignKey("ABC.Template.Domain.AggregatesModel.UserAggregate.UserDept", "UserId") + .OnDelete(DeleteBehavior.ClientCascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRefreshToken", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.UserAggregate.User", null) + .WithMany("RefreshTokens") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRole", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.UserAggregate.User", null) + .WithMany("Roles") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.Role", b => + { + b.Navigation("Permissions"); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.User", b => + { + b.Navigation("Dept") + .IsRequired(); + + b.Navigation("RefreshTokens"); + + b.Navigation("Roles"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/template/src/ABC.Template.Infrastructure/MigrationsAll/SqlServer-net9.0-admin/20260122054539_Init.cs b/template/src/ABC.Template.Infrastructure/MigrationsAll/SqlServer-net9.0-admin/20260122054539_Init.cs new file mode 100644 index 00000000..e59b8bdf --- /dev/null +++ b/template/src/ABC.Template.Infrastructure/MigrationsAll/SqlServer-net9.0-admin/20260122054539_Init.cs @@ -0,0 +1,308 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace ABC.Template.Infrastructure.Migrations +{ + /// + public partial class Init : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "CAPLock", + columns: table => new + { + Key = table.Column(type: "nvarchar(128)", maxLength: 128, nullable: false), + Instance = table.Column(type: "nvarchar(256)", maxLength: 256, nullable: true), + LastLockTime = table.Column(type: "datetime2(7)", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_CAPLock", x => x.Key); + }); + + migrationBuilder.CreateTable( + name: "CAPPublishedMessage", + columns: table => new + { + Id = table.Column(type: "bigint", nullable: false), + Version = table.Column(type: "nvarchar(20)", maxLength: 20, nullable: true), + Name = table.Column(type: "nvarchar(200)", maxLength: 200, nullable: false), + Content = table.Column(type: "nvarchar(max)", nullable: true), + Retries = table.Column(type: "int", nullable: true), + Added = table.Column(type: "datetime2(7)", nullable: false), + ExpiresAt = table.Column(type: "datetime2(7)", nullable: true), + StatusName = table.Column(type: "nvarchar(40)", maxLength: 40, nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_CAPPublishedMessage", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "CAPReceivedMessage", + columns: table => new + { + Id = table.Column(type: "bigint", nullable: false), + Version = table.Column(type: "nvarchar(20)", maxLength: 20, nullable: true), + Name = table.Column(type: "nvarchar(400)", maxLength: 400, nullable: false), + Group = table.Column(type: "nvarchar(200)", maxLength: 200, nullable: true), + Content = table.Column(type: "nvarchar(max)", nullable: true), + Retries = table.Column(type: "int", nullable: true), + Added = table.Column(type: "datetime2(7)", nullable: false), + ExpiresAt = table.Column(type: "datetime2(7)", nullable: true), + StatusName = table.Column(type: "nvarchar(50)", maxLength: 50, nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_CAPReceivedMessage", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "dept", + columns: table => new + { + Id = table.Column(type: "bigint", nullable: false), + Name = table.Column(type: "nvarchar(100)", maxLength: 100, nullable: false), + Remark = table.Column(type: "nvarchar(500)", maxLength: 500, nullable: false), + ParentId = table.Column(type: "bigint", nullable: false), + Status = table.Column(type: "int", nullable: false), + CreatedAt = table.Column(type: "datetimeoffset", nullable: false), + IsDeleted = table.Column(type: "bit", nullable: false), + DeletedAt = table.Column(type: "datetimeoffset", nullable: false), + UpdateTime = table.Column(type: "datetimeoffset", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_dept", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "role", + columns: table => new + { + Id = table.Column(type: "uniqueidentifier", nullable: false), + Name = table.Column(type: "nvarchar(50)", maxLength: 50, nullable: false), + Description = table.Column(type: "nvarchar(200)", maxLength: 200, nullable: false), + CreatedAt = table.Column(type: "datetimeoffset", nullable: false), + IsActive = table.Column(type: "bit", nullable: false), + IsDeleted = table.Column(type: "bit", nullable: false), + DeletedAt = table.Column(type: "datetimeoffset", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_role", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "user", + columns: table => new + { + Id = table.Column(type: "bigint", nullable: false), + Name = table.Column(type: "nvarchar(50)", maxLength: 50, nullable: false), + Email = table.Column(type: "nvarchar(100)", maxLength: 100, nullable: false), + Phone = table.Column(type: "nvarchar(20)", maxLength: 20, nullable: false), + RealName = table.Column(type: "nvarchar(50)", maxLength: 50, nullable: false), + Status = table.Column(type: "int", nullable: false), + PasswordHash = table.Column(type: "nvarchar(255)", maxLength: 255, nullable: false), + IsActive = table.Column(type: "bit", nullable: false), + CreatedAt = table.Column(type: "datetimeoffset", nullable: false), + LastLoginTime = table.Column(type: "datetimeoffset", nullable: true), + UpdateTime = table.Column(type: "datetimeoffset", nullable: false), + IsDeleted = table.Column(type: "bit", nullable: false), + DeletedAt = table.Column(type: "datetimeoffset", nullable: false), + Gender = table.Column(type: "nvarchar(10)", maxLength: 10, nullable: false), + Age = table.Column(type: "int", nullable: false), + BirthDate = table.Column(type: "datetimeoffset", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_user", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "role_permission", + columns: table => new + { + RoleId = table.Column(type: "uniqueidentifier", nullable: false), + PermissionCode = table.Column(type: "nvarchar(100)", maxLength: 100, nullable: false), + PermissionName = table.Column(type: "nvarchar(100)", maxLength: 100, nullable: false), + PermissionDescription = table.Column(type: "nvarchar(200)", maxLength: 200, nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_role_permission", x => new { x.RoleId, x.PermissionCode }); + table.ForeignKey( + name: "FK_role_permission_role_RoleId", + column: x => x.RoleId, + principalTable: "role", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "user_dept", + columns: table => new + { + UserId = table.Column(type: "bigint", nullable: false), + DeptId = table.Column(type: "bigint", nullable: false), + DeptName = table.Column(type: "nvarchar(100)", maxLength: 100, nullable: false), + AssignedAt = table.Column(type: "datetimeoffset", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_user_dept", x => x.UserId); + table.ForeignKey( + name: "FK_user_dept_user_UserId", + column: x => x.UserId, + principalTable: "user", + principalColumn: "Id"); + }); + + migrationBuilder.CreateTable( + name: "user_refresh_token", + columns: table => new + { + Id = table.Column(type: "bigint", nullable: false), + UserId = table.Column(type: "bigint", nullable: false), + Token = table.Column(type: "nvarchar(500)", maxLength: 500, nullable: false), + CreatedTime = table.Column(type: "datetimeoffset", nullable: false), + ExpiresTime = table.Column(type: "datetimeoffset", nullable: false), + IsUsed = table.Column(type: "bit", nullable: false), + IsRevoked = table.Column(type: "bit", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_user_refresh_token", x => x.Id); + table.ForeignKey( + name: "FK_user_refresh_token_user_UserId", + column: x => x.UserId, + principalTable: "user", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "user_role", + columns: table => new + { + UserId = table.Column(type: "bigint", nullable: false), + RoleId = table.Column(type: "uniqueidentifier", nullable: false), + RoleName = table.Column(type: "nvarchar(50)", maxLength: 50, nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_user_role", x => new { x.UserId, x.RoleId }); + table.ForeignKey( + name: "FK_user_role_user_UserId", + column: x => x.UserId, + principalTable: "user", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_ExpiresAt_StatusName", + table: "CAPPublishedMessage", + columns: new[] { "ExpiresAt", "StatusName" }); + + migrationBuilder.CreateIndex( + name: "IX_Version_ExpiresAt_StatusName", + table: "CAPPublishedMessage", + columns: new[] { "Version", "ExpiresAt", "StatusName" }); + + migrationBuilder.CreateIndex( + name: "IX_ExpiresAt_StatusName", + table: "CAPReceivedMessage", + columns: new[] { "ExpiresAt", "StatusName" }); + + migrationBuilder.CreateIndex( + name: "IX_Version_ExpiresAt_StatusName", + table: "CAPReceivedMessage", + columns: new[] { "Version", "ExpiresAt", "StatusName" }); + + migrationBuilder.CreateIndex( + name: "IX_dept_IsDeleted", + table: "dept", + column: "IsDeleted"); + + migrationBuilder.CreateIndex( + name: "IX_dept_ParentId", + table: "dept", + column: "ParentId"); + + migrationBuilder.CreateIndex( + name: "IX_dept_Status", + table: "dept", + column: "Status"); + + migrationBuilder.CreateIndex( + name: "IX_role_Name", + table: "role", + column: "Name", + unique: true); + + migrationBuilder.CreateIndex( + name: "IX_user_Email", + table: "user", + column: "Email"); + + migrationBuilder.CreateIndex( + name: "IX_user_Name", + table: "user", + column: "Name"); + + migrationBuilder.CreateIndex( + name: "IX_user_dept_DeptId", + table: "user_dept", + column: "DeptId"); + + migrationBuilder.CreateIndex( + name: "IX_user_dept_UserId", + table: "user_dept", + column: "UserId"); + + migrationBuilder.CreateIndex( + name: "IX_user_refresh_token_UserId", + table: "user_refresh_token", + column: "UserId"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "CAPLock"); + + migrationBuilder.DropTable( + name: "CAPPublishedMessage"); + + migrationBuilder.DropTable( + name: "CAPReceivedMessage"); + + migrationBuilder.DropTable( + name: "dept"); + + migrationBuilder.DropTable( + name: "role_permission"); + + migrationBuilder.DropTable( + name: "user_dept"); + + migrationBuilder.DropTable( + name: "user_refresh_token"); + + migrationBuilder.DropTable( + name: "user_role"); + + migrationBuilder.DropTable( + name: "role"); + + migrationBuilder.DropTable( + name: "user"); + } + } +} diff --git a/template/src/ABC.Template.Infrastructure/MigrationsAll/SqlServer-net9.0-admin/ApplicationDbContextModelSnapshot.cs b/template/src/ABC.Template.Infrastructure/MigrationsAll/SqlServer-net9.0-admin/ApplicationDbContextModelSnapshot.cs new file mode 100644 index 00000000..03c8242f --- /dev/null +++ b/template/src/ABC.Template.Infrastructure/MigrationsAll/SqlServer-net9.0-admin/ApplicationDbContextModelSnapshot.cs @@ -0,0 +1,429 @@ +// +using System; +using ABC.Template.Infrastructure; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace ABC.Template.Infrastructure.Migrations +{ + [DbContext(typeof(ApplicationDbContext))] + partial class ApplicationDbContextModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "9.0.0") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.DeptAggregate.Dept", b => + { + b.Property("Id") + .HasColumnType("bigint"); + + b.Property("CreatedAt") + .HasColumnType("datetimeoffset"); + + b.Property("DeletedAt") + .HasColumnType("datetimeoffset"); + + b.Property("IsDeleted") + .HasColumnType("bit"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.Property("ParentId") + .HasColumnType("bigint"); + + b.Property("Remark") + .IsRequired() + .HasMaxLength(500) + .HasColumnType("nvarchar(500)"); + + b.Property("Status") + .HasColumnType("int"); + + b.Property("UpdateTime") + .HasColumnType("datetimeoffset"); + + b.HasKey("Id"); + + b.HasIndex("IsDeleted"); + + b.HasIndex("ParentId"); + + b.HasIndex("Status"); + + b.ToTable("dept", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.Role", b => + { + b.Property("Id") + .HasColumnType("uniqueidentifier"); + + b.Property("CreatedAt") + .HasColumnType("datetimeoffset"); + + b.Property("DeletedAt") + .HasColumnType("datetimeoffset"); + + b.Property("Description") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.Property("IsActive") + .HasColumnType("bit"); + + b.Property("IsDeleted") + .HasColumnType("bit"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.HasKey("Id"); + + b.HasIndex("Name") + .IsUnique(); + + b.ToTable("role", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.RolePermission", b => + { + b.Property("RoleId") + .HasColumnType("uniqueidentifier"); + + b.Property("PermissionCode") + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.Property("PermissionDescription") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.Property("PermissionName") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.HasKey("RoleId", "PermissionCode"); + + b.ToTable("role_permission", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.User", b => + { + b.Property("Id") + .HasColumnType("bigint"); + + b.Property("Age") + .HasColumnType("int"); + + b.Property("BirthDate") + .HasColumnType("datetimeoffset"); + + b.Property("CreatedAt") + .HasColumnType("datetimeoffset"); + + b.Property("DeletedAt") + .HasColumnType("datetimeoffset"); + + b.Property("Email") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.Property("Gender") + .IsRequired() + .HasMaxLength(10) + .HasColumnType("nvarchar(10)"); + + b.Property("IsActive") + .HasColumnType("bit"); + + b.Property("IsDeleted") + .HasColumnType("bit"); + + b.Property("LastLoginTime") + .HasColumnType("datetimeoffset"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.Property("PasswordHash") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("nvarchar(255)"); + + b.Property("Phone") + .IsRequired() + .HasMaxLength(20) + .HasColumnType("nvarchar(20)"); + + b.Property("RealName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.Property("Status") + .HasColumnType("int"); + + b.Property("UpdateTime") + .HasColumnType("datetimeoffset"); + + b.HasKey("Id"); + + b.HasIndex("Email"); + + b.HasIndex("Name"); + + b.ToTable("user", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserDept", b => + { + b.Property("UserId") + .HasColumnType("bigint"); + + b.Property("AssignedAt") + .HasColumnType("datetimeoffset"); + + b.Property("DeptId") + .HasColumnType("bigint"); + + b.Property("DeptName") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.HasKey("UserId"); + + b.HasIndex("DeptId"); + + b.HasIndex("UserId"); + + b.ToTable("user_dept", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRefreshToken", b => + { + b.Property("Id") + .HasColumnType("bigint"); + + b.Property("CreatedTime") + .HasColumnType("datetimeoffset"); + + b.Property("ExpiresTime") + .HasColumnType("datetimeoffset"); + + b.Property("IsRevoked") + .HasColumnType("bit"); + + b.Property("IsUsed") + .HasColumnType("bit"); + + b.Property("Token") + .IsRequired() + .HasMaxLength(500) + .HasColumnType("nvarchar(500)"); + + b.Property("UserId") + .HasColumnType("bigint"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("user_refresh_token", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRole", b => + { + b.Property("UserId") + .HasColumnType("bigint"); + + b.Property("RoleId") + .HasColumnType("uniqueidentifier"); + + b.Property("RoleName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.HasKey("UserId", "RoleId"); + + b.ToTable("user_role", (string)null); + }); + + modelBuilder.Entity("NetCorePal.Extensions.DistributedTransactions.CAP.Persistence.CapLock", b => + { + b.Property("Key") + .HasMaxLength(128) + .HasColumnType("nvarchar(128)"); + + b.Property("Instance") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.Property("LastLockTime") + .HasColumnType("datetime2(7)"); + + b.HasKey("Key"); + + b.ToTable("CAPLock", (string)null); + }); + + modelBuilder.Entity("NetCorePal.Extensions.DistributedTransactions.CAP.Persistence.PublishedMessage", b => + { + b.Property("Id") + .HasColumnType("bigint"); + + b.Property("Added") + .HasColumnType("datetime2(7)"); + + b.Property("Content") + .HasColumnType("nvarchar(max)"); + + b.Property("ExpiresAt") + .HasColumnType("datetime2(7)"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.Property("Retries") + .HasColumnType("int"); + + b.Property("StatusName") + .IsRequired() + .HasMaxLength(40) + .HasColumnType("nvarchar(40)"); + + b.Property("Version") + .HasMaxLength(20) + .HasColumnType("nvarchar(20)"); + + b.HasKey("Id"); + + b.HasIndex(new[] { "ExpiresAt", "StatusName" }, "IX_ExpiresAt_StatusName"); + + b.HasIndex(new[] { "Version", "ExpiresAt", "StatusName" }, "IX_Version_ExpiresAt_StatusName"); + + b.ToTable("CAPPublishedMessage", (string)null); + }); + + modelBuilder.Entity("NetCorePal.Extensions.DistributedTransactions.CAP.Persistence.ReceivedMessage", b => + { + b.Property("Id") + .HasColumnType("bigint"); + + b.Property("Added") + .HasColumnType("datetime2(7)"); + + b.Property("Content") + .HasColumnType("nvarchar(max)"); + + b.Property("ExpiresAt") + .HasColumnType("datetime2(7)"); + + b.Property("Group") + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(400) + .HasColumnType("nvarchar(400)"); + + b.Property("Retries") + .HasColumnType("int"); + + b.Property("StatusName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.Property("Version") + .HasMaxLength(20) + .HasColumnType("nvarchar(20)"); + + b.HasKey("Id"); + + b.HasIndex(new[] { "ExpiresAt", "StatusName" }, "IX_ExpiresAt_StatusName"); + + b.HasIndex(new[] { "Version", "ExpiresAt", "StatusName" }, "IX_Version_ExpiresAt_StatusName"); + + b.ToTable("CAPReceivedMessage", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.RolePermission", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.RoleAggregate.Role", null) + .WithMany("Permissions") + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserDept", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.UserAggregate.User", null) + .WithOne("Dept") + .HasForeignKey("ABC.Template.Domain.AggregatesModel.UserAggregate.UserDept", "UserId") + .OnDelete(DeleteBehavior.ClientCascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRefreshToken", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.UserAggregate.User", null) + .WithMany("RefreshTokens") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRole", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.UserAggregate.User", null) + .WithMany("Roles") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.Role", b => + { + b.Navigation("Permissions"); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.User", b => + { + b.Navigation("Dept") + .IsRequired(); + + b.Navigation("RefreshTokens"); + + b.Navigation("Roles"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/template/src/ABC.Template.Infrastructure/MigrationsAll/SqlServer-net10.0/20251225065040_Init.Designer.cs b/template/src/ABC.Template.Infrastructure/MigrationsAll/SqlServer-net9.0/20260122054530_Init.Designer.cs similarity index 76% rename from template/src/ABC.Template.Infrastructure/MigrationsAll/SqlServer-net10.0/20251225065040_Init.Designer.cs rename to template/src/ABC.Template.Infrastructure/MigrationsAll/SqlServer-net9.0/20260122054530_Init.Designer.cs index 44c5aed4..d6a60519 100644 --- a/template/src/ABC.Template.Infrastructure/MigrationsAll/SqlServer-net10.0/20251225065040_Init.Designer.cs +++ b/template/src/ABC.Template.Infrastructure/MigrationsAll/SqlServer-net9.0/20260122054530_Init.Designer.cs @@ -1,18 +1,18 @@ // using System; +using ABC.Template.Infrastructure; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using ABC.Template.Infrastructure; #nullable disable namespace ABC.Template.Infrastructure.Migrations { [DbContext(typeof(ApplicationDbContext))] - [Migration("20251225065040_Init")] + [Migration("20260122054530_Init")] partial class Init { /// @@ -126,47 +126,6 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.ToTable("CAPReceivedMessage", (string)null); }); - - modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.DeliverAggregate.DeliverRecord", b => - { - b.Property("Id") - .HasColumnType("uniqueidentifier"); - - b.Property("OrderId") - .HasColumnType("uniqueidentifier"); - - b.HasKey("Id"); - - b.ToTable("deliverrecord", (string)null); - }); - - modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.OrderAggregate.Order", b => - { - b.Property("Id") - .HasColumnType("uniqueidentifier"); - - b.Property("Count") - .HasColumnType("int"); - - b.Property("Name") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("nvarchar(100)"); - - b.Property("Paid") - .HasColumnType("bit"); - - b.Property("RowVersion") - .IsConcurrencyToken() - .HasColumnType("int"); - - b.Property("UpdateTime") - .HasColumnType("datetimeoffset"); - - b.HasKey("Id"); - - b.ToTable("order", (string)null); - }); #pragma warning restore 612, 618 } } diff --git a/template/src/ABC.Template.Infrastructure/MigrationsAll/SqlServer-net10.0/20251225065040_Init.cs b/template/src/ABC.Template.Infrastructure/MigrationsAll/SqlServer-net9.0/20260122054530_Init.cs similarity index 75% rename from template/src/ABC.Template.Infrastructure/MigrationsAll/SqlServer-net10.0/20251225065040_Init.cs rename to template/src/ABC.Template.Infrastructure/MigrationsAll/SqlServer-net9.0/20260122054530_Init.cs index 00cc1805..dabb2f4f 100644 --- a/template/src/ABC.Template.Infrastructure/MigrationsAll/SqlServer-net10.0/20251225065040_Init.cs +++ b/template/src/ABC.Template.Infrastructure/MigrationsAll/SqlServer-net9.0/20260122054530_Init.cs @@ -61,34 +61,6 @@ protected override void Up(MigrationBuilder migrationBuilder) table.PrimaryKey("PK_CAPReceivedMessage", x => x.Id); }); - migrationBuilder.CreateTable( - name: "deliverrecord", - columns: table => new - { - Id = table.Column(type: "uniqueidentifier", nullable: false), - OrderId = table.Column(type: "uniqueidentifier", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_deliverrecord", x => x.Id); - }); - - migrationBuilder.CreateTable( - name: "order", - columns: table => new - { - Id = table.Column(type: "uniqueidentifier", nullable: false), - Paid = table.Column(type: "bit", nullable: false), - Name = table.Column(type: "nvarchar(100)", maxLength: 100, nullable: false), - Count = table.Column(type: "int", nullable: false), - RowVersion = table.Column(type: "int", nullable: false), - UpdateTime = table.Column(type: "datetimeoffset", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_order", x => x.Id); - }); - migrationBuilder.CreateIndex( name: "IX_ExpiresAt_StatusName", table: "CAPPublishedMessage", @@ -121,12 +93,6 @@ protected override void Down(MigrationBuilder migrationBuilder) migrationBuilder.DropTable( name: "CAPReceivedMessage"); - - migrationBuilder.DropTable( - name: "deliverrecord"); - - migrationBuilder.DropTable( - name: "order"); } } } diff --git a/template/src/ABC.Template.Infrastructure/MigrationsAll/SqlServer-net9.0/ApplicationDbContextModelSnapshot.cs b/template/src/ABC.Template.Infrastructure/MigrationsAll/SqlServer-net9.0/ApplicationDbContextModelSnapshot.cs index cd78fe21..619a9cef 100644 --- a/template/src/ABC.Template.Infrastructure/MigrationsAll/SqlServer-net9.0/ApplicationDbContextModelSnapshot.cs +++ b/template/src/ABC.Template.Infrastructure/MigrationsAll/SqlServer-net9.0/ApplicationDbContextModelSnapshot.cs @@ -1,10 +1,10 @@ // using System; +using ABC.Template.Infrastructure; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using ABC.Template.Infrastructure; #nullable disable @@ -123,47 +123,6 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.ToTable("CAPReceivedMessage", (string)null); }); - - modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.DeliverAggregate.DeliverRecord", b => - { - b.Property("Id") - .HasColumnType("uniqueidentifier"); - - b.Property("OrderId") - .HasColumnType("uniqueidentifier"); - - b.HasKey("Id"); - - b.ToTable("deliverrecord", (string)null); - }); - - modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.OrderAggregate.Order", b => - { - b.Property("Id") - .HasColumnType("uniqueidentifier"); - - b.Property("Count") - .HasColumnType("int"); - - b.Property("Name") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("nvarchar(100)"); - - b.Property("Paid") - .HasColumnType("bit"); - - b.Property("RowVersion") - .IsConcurrencyToken() - .HasColumnType("int"); - - b.Property("UpdateTime") - .HasColumnType("datetimeoffset"); - - b.HasKey("Id"); - - b.ToTable("order", (string)null); - }); #pragma warning restore 612, 618 } } diff --git a/template/src/ABC.Template.Infrastructure/MigrationsAll/Sqlite-net10.0-admin/20260122054914_Init.Designer.cs b/template/src/ABC.Template.Infrastructure/MigrationsAll/Sqlite-net10.0-admin/20260122054914_Init.Designer.cs new file mode 100644 index 00000000..70aa3b3b --- /dev/null +++ b/template/src/ABC.Template.Infrastructure/MigrationsAll/Sqlite-net10.0-admin/20260122054914_Init.Designer.cs @@ -0,0 +1,431 @@ +// +using System; +using ABC.Template.Infrastructure; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace ABC.Template.Infrastructure.Migrations +{ + [DbContext(typeof(ApplicationDbContext))] + [Migration("20260122054914_Init")] + partial class Init + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder.HasAnnotation("ProductVersion", "9.0.0"); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.DeptAggregate.Dept", b => + { + b.Property("Id") + .HasColumnType("INTEGER"); + + b.Property("CreatedAt") + .HasColumnType("TEXT"); + + b.Property("DeletedAt") + .HasColumnType("TEXT"); + + b.Property("IsDeleted") + .HasColumnType("INTEGER"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("TEXT"); + + b.Property("ParentId") + .HasColumnType("INTEGER"); + + b.Property("Remark") + .IsRequired() + .HasMaxLength(500) + .HasColumnType("TEXT"); + + b.Property("Status") + .HasColumnType("INTEGER"); + + b.Property("UpdateTime") + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("IsDeleted"); + + b.HasIndex("ParentId"); + + b.HasIndex("Status"); + + b.ToTable("dept", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.Role", b => + { + b.Property("Id") + .HasColumnType("TEXT"); + + b.Property("CreatedAt") + .HasColumnType("TEXT"); + + b.Property("DeletedAt") + .HasColumnType("TEXT"); + + b.Property("Description") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("TEXT"); + + b.Property("IsActive") + .HasColumnType("INTEGER"); + + b.Property("IsDeleted") + .HasColumnType("INTEGER"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("Name") + .IsUnique(); + + b.ToTable("role", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.RolePermission", b => + { + b.Property("RoleId") + .HasColumnType("TEXT"); + + b.Property("PermissionCode") + .HasMaxLength(100) + .HasColumnType("TEXT"); + + b.Property("PermissionDescription") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("TEXT"); + + b.Property("PermissionName") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("TEXT"); + + b.HasKey("RoleId", "PermissionCode"); + + b.ToTable("role_permission", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.User", b => + { + b.Property("Id") + .HasColumnType("INTEGER"); + + b.Property("Age") + .HasColumnType("INTEGER"); + + b.Property("BirthDate") + .HasColumnType("TEXT"); + + b.Property("CreatedAt") + .HasColumnType("TEXT"); + + b.Property("DeletedAt") + .HasColumnType("TEXT"); + + b.Property("Email") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("TEXT"); + + b.Property("Gender") + .IsRequired() + .HasMaxLength(10) + .HasColumnType("TEXT"); + + b.Property("IsActive") + .HasColumnType("INTEGER"); + + b.Property("IsDeleted") + .HasColumnType("INTEGER"); + + b.Property("LastLoginTime") + .HasColumnType("TEXT"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("TEXT"); + + b.Property("PasswordHash") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("TEXT"); + + b.Property("Phone") + .IsRequired() + .HasMaxLength(20) + .HasColumnType("TEXT"); + + b.Property("RealName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("TEXT"); + + b.Property("Status") + .HasColumnType("INTEGER"); + + b.Property("UpdateTime") + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("Email"); + + b.HasIndex("Name"); + + b.ToTable("user", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserDept", b => + { + b.Property("UserId") + .HasColumnType("INTEGER"); + + b.Property("AssignedAt") + .HasColumnType("TEXT"); + + b.Property("DeptId") + .HasColumnType("INTEGER"); + + b.Property("DeptName") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("TEXT"); + + b.HasKey("UserId"); + + b.HasIndex("DeptId"); + + b.HasIndex("UserId"); + + b.ToTable("user_dept", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRefreshToken", b => + { + b.Property("Id") + .HasColumnType("INTEGER"); + + b.Property("CreatedTime") + .HasColumnType("TEXT"); + + b.Property("ExpiresTime") + .HasColumnType("TEXT"); + + b.Property("IsRevoked") + .HasColumnType("INTEGER"); + + b.Property("IsUsed") + .HasColumnType("INTEGER"); + + b.Property("Token") + .IsRequired() + .HasMaxLength(500) + .HasColumnType("TEXT"); + + b.Property("UserId") + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("user_refresh_token", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRole", b => + { + b.Property("UserId") + .HasColumnType("INTEGER"); + + b.Property("RoleId") + .HasColumnType("TEXT"); + + b.Property("RoleName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("TEXT"); + + b.HasKey("UserId", "RoleId"); + + b.ToTable("user_role", (string)null); + }); + + modelBuilder.Entity("NetCorePal.Extensions.DistributedTransactions.CAP.Persistence.CapLock", b => + { + b.Property("Key") + .HasMaxLength(128) + .HasColumnType("TEXT"); + + b.Property("Instance") + .HasMaxLength(256) + .HasColumnType("TEXT"); + + b.Property("LastLockTime") + .HasColumnType("TEXT"); + + b.HasKey("Key"); + + b.ToTable("CAPLock", (string)null); + }); + + modelBuilder.Entity("NetCorePal.Extensions.DistributedTransactions.CAP.Persistence.PublishedMessage", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Added") + .HasColumnType("TEXT"); + + b.Property("Content") + .HasColumnType("TEXT"); + + b.Property("ExpiresAt") + .HasColumnType("TEXT"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("TEXT"); + + b.Property("Retries") + .HasColumnType("INTEGER"); + + b.Property("StatusName") + .IsRequired() + .HasMaxLength(40) + .HasColumnType("TEXT"); + + b.Property("Version") + .HasMaxLength(20) + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex(new[] { "ExpiresAt", "StatusName" }, "IX_ExpiresAt_StatusName"); + + b.HasIndex(new[] { "Version", "ExpiresAt", "StatusName" }, "IX_Version_ExpiresAt_StatusName"); + + b.ToTable("CAPPublishedMessage", (string)null); + }); + + modelBuilder.Entity("NetCorePal.Extensions.DistributedTransactions.CAP.Persistence.ReceivedMessage", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Added") + .HasColumnType("TEXT"); + + b.Property("Content") + .HasColumnType("TEXT"); + + b.Property("ExpiresAt") + .HasColumnType("TEXT"); + + b.Property("Group") + .HasMaxLength(200) + .HasColumnType("TEXT"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(400) + .HasColumnType("TEXT"); + + b.Property("Retries") + .HasColumnType("INTEGER"); + + b.Property("StatusName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("TEXT"); + + b.Property("Version") + .HasMaxLength(20) + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex(new[] { "ExpiresAt", "StatusName" }, "IX_ExpiresAt_StatusName") + .HasDatabaseName("IX_ExpiresAt_StatusName1"); + + b.HasIndex(new[] { "Version", "ExpiresAt", "StatusName" }, "IX_Version_ExpiresAt_StatusName") + .HasDatabaseName("IX_Version_ExpiresAt_StatusName1"); + + b.ToTable("CAPReceivedMessage", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.RolePermission", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.RoleAggregate.Role", null) + .WithMany("Permissions") + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserDept", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.UserAggregate.User", null) + .WithOne("Dept") + .HasForeignKey("ABC.Template.Domain.AggregatesModel.UserAggregate.UserDept", "UserId") + .OnDelete(DeleteBehavior.ClientCascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRefreshToken", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.UserAggregate.User", null) + .WithMany("RefreshTokens") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRole", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.UserAggregate.User", null) + .WithMany("Roles") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.Role", b => + { + b.Navigation("Permissions"); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.User", b => + { + b.Navigation("Dept") + .IsRequired(); + + b.Navigation("RefreshTokens"); + + b.Navigation("Roles"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/template/src/ABC.Template.Infrastructure/MigrationsAll/Sqlite-net10.0-admin/20260122054914_Init.cs b/template/src/ABC.Template.Infrastructure/MigrationsAll/Sqlite-net10.0-admin/20260122054914_Init.cs new file mode 100644 index 00000000..aaab0e3f --- /dev/null +++ b/template/src/ABC.Template.Infrastructure/MigrationsAll/Sqlite-net10.0-admin/20260122054914_Init.cs @@ -0,0 +1,310 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace ABC.Template.Infrastructure.Migrations +{ + /// + public partial class Init : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "CAPLock", + columns: table => new + { + Key = table.Column(type: "TEXT", maxLength: 128, nullable: false), + Instance = table.Column(type: "TEXT", maxLength: 256, nullable: true), + LastLockTime = table.Column(type: "TEXT", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_CAPLock", x => x.Key); + }); + + migrationBuilder.CreateTable( + name: "CAPPublishedMessage", + columns: table => new + { + Id = table.Column(type: "INTEGER", nullable: false) + .Annotation("Sqlite:Autoincrement", true), + Version = table.Column(type: "TEXT", maxLength: 20, nullable: true), + Name = table.Column(type: "TEXT", maxLength: 200, nullable: false), + Content = table.Column(type: "TEXT", nullable: true), + Retries = table.Column(type: "INTEGER", nullable: true), + Added = table.Column(type: "TEXT", nullable: false), + ExpiresAt = table.Column(type: "TEXT", nullable: true), + StatusName = table.Column(type: "TEXT", maxLength: 40, nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_CAPPublishedMessage", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "CAPReceivedMessage", + columns: table => new + { + Id = table.Column(type: "INTEGER", nullable: false) + .Annotation("Sqlite:Autoincrement", true), + Version = table.Column(type: "TEXT", maxLength: 20, nullable: true), + Name = table.Column(type: "TEXT", maxLength: 400, nullable: false), + Group = table.Column(type: "TEXT", maxLength: 200, nullable: true), + Content = table.Column(type: "TEXT", nullable: true), + Retries = table.Column(type: "INTEGER", nullable: true), + Added = table.Column(type: "TEXT", nullable: false), + ExpiresAt = table.Column(type: "TEXT", nullable: true), + StatusName = table.Column(type: "TEXT", maxLength: 50, nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_CAPReceivedMessage", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "dept", + columns: table => new + { + Id = table.Column(type: "INTEGER", nullable: false), + Name = table.Column(type: "TEXT", maxLength: 100, nullable: false), + Remark = table.Column(type: "TEXT", maxLength: 500, nullable: false), + ParentId = table.Column(type: "INTEGER", nullable: false), + Status = table.Column(type: "INTEGER", nullable: false), + CreatedAt = table.Column(type: "TEXT", nullable: false), + IsDeleted = table.Column(type: "INTEGER", nullable: false), + DeletedAt = table.Column(type: "TEXT", nullable: false), + UpdateTime = table.Column(type: "TEXT", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_dept", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "role", + columns: table => new + { + Id = table.Column(type: "TEXT", nullable: false), + Name = table.Column(type: "TEXT", maxLength: 50, nullable: false), + Description = table.Column(type: "TEXT", maxLength: 200, nullable: false), + CreatedAt = table.Column(type: "TEXT", nullable: false), + IsActive = table.Column(type: "INTEGER", nullable: false), + IsDeleted = table.Column(type: "INTEGER", nullable: false), + DeletedAt = table.Column(type: "TEXT", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_role", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "user", + columns: table => new + { + Id = table.Column(type: "INTEGER", nullable: false), + Name = table.Column(type: "TEXT", maxLength: 50, nullable: false), + Email = table.Column(type: "TEXT", maxLength: 100, nullable: false), + Phone = table.Column(type: "TEXT", maxLength: 20, nullable: false), + RealName = table.Column(type: "TEXT", maxLength: 50, nullable: false), + Status = table.Column(type: "INTEGER", nullable: false), + PasswordHash = table.Column(type: "TEXT", maxLength: 255, nullable: false), + IsActive = table.Column(type: "INTEGER", nullable: false), + CreatedAt = table.Column(type: "TEXT", nullable: false), + LastLoginTime = table.Column(type: "TEXT", nullable: true), + UpdateTime = table.Column(type: "TEXT", nullable: false), + IsDeleted = table.Column(type: "INTEGER", nullable: false), + DeletedAt = table.Column(type: "TEXT", nullable: false), + Gender = table.Column(type: "TEXT", maxLength: 10, nullable: false), + Age = table.Column(type: "INTEGER", nullable: false), + BirthDate = table.Column(type: "TEXT", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_user", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "role_permission", + columns: table => new + { + RoleId = table.Column(type: "TEXT", nullable: false), + PermissionCode = table.Column(type: "TEXT", maxLength: 100, nullable: false), + PermissionName = table.Column(type: "TEXT", maxLength: 100, nullable: false), + PermissionDescription = table.Column(type: "TEXT", maxLength: 200, nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_role_permission", x => new { x.RoleId, x.PermissionCode }); + table.ForeignKey( + name: "FK_role_permission_role_RoleId", + column: x => x.RoleId, + principalTable: "role", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "user_dept", + columns: table => new + { + UserId = table.Column(type: "INTEGER", nullable: false), + DeptId = table.Column(type: "INTEGER", nullable: false), + DeptName = table.Column(type: "TEXT", maxLength: 100, nullable: false), + AssignedAt = table.Column(type: "TEXT", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_user_dept", x => x.UserId); + table.ForeignKey( + name: "FK_user_dept_user_UserId", + column: x => x.UserId, + principalTable: "user", + principalColumn: "Id"); + }); + + migrationBuilder.CreateTable( + name: "user_refresh_token", + columns: table => new + { + Id = table.Column(type: "INTEGER", nullable: false), + UserId = table.Column(type: "INTEGER", nullable: false), + Token = table.Column(type: "TEXT", maxLength: 500, nullable: false), + CreatedTime = table.Column(type: "TEXT", nullable: false), + ExpiresTime = table.Column(type: "TEXT", nullable: false), + IsUsed = table.Column(type: "INTEGER", nullable: false), + IsRevoked = table.Column(type: "INTEGER", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_user_refresh_token", x => x.Id); + table.ForeignKey( + name: "FK_user_refresh_token_user_UserId", + column: x => x.UserId, + principalTable: "user", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "user_role", + columns: table => new + { + UserId = table.Column(type: "INTEGER", nullable: false), + RoleId = table.Column(type: "TEXT", nullable: false), + RoleName = table.Column(type: "TEXT", maxLength: 50, nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_user_role", x => new { x.UserId, x.RoleId }); + table.ForeignKey( + name: "FK_user_role_user_UserId", + column: x => x.UserId, + principalTable: "user", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_ExpiresAt_StatusName", + table: "CAPPublishedMessage", + columns: new[] { "ExpiresAt", "StatusName" }); + + migrationBuilder.CreateIndex( + name: "IX_Version_ExpiresAt_StatusName", + table: "CAPPublishedMessage", + columns: new[] { "Version", "ExpiresAt", "StatusName" }); + + migrationBuilder.CreateIndex( + name: "IX_ExpiresAt_StatusName1", + table: "CAPReceivedMessage", + columns: new[] { "ExpiresAt", "StatusName" }); + + migrationBuilder.CreateIndex( + name: "IX_Version_ExpiresAt_StatusName1", + table: "CAPReceivedMessage", + columns: new[] { "Version", "ExpiresAt", "StatusName" }); + + migrationBuilder.CreateIndex( + name: "IX_dept_IsDeleted", + table: "dept", + column: "IsDeleted"); + + migrationBuilder.CreateIndex( + name: "IX_dept_ParentId", + table: "dept", + column: "ParentId"); + + migrationBuilder.CreateIndex( + name: "IX_dept_Status", + table: "dept", + column: "Status"); + + migrationBuilder.CreateIndex( + name: "IX_role_Name", + table: "role", + column: "Name", + unique: true); + + migrationBuilder.CreateIndex( + name: "IX_user_Email", + table: "user", + column: "Email"); + + migrationBuilder.CreateIndex( + name: "IX_user_Name", + table: "user", + column: "Name"); + + migrationBuilder.CreateIndex( + name: "IX_user_dept_DeptId", + table: "user_dept", + column: "DeptId"); + + migrationBuilder.CreateIndex( + name: "IX_user_dept_UserId", + table: "user_dept", + column: "UserId"); + + migrationBuilder.CreateIndex( + name: "IX_user_refresh_token_UserId", + table: "user_refresh_token", + column: "UserId"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "CAPLock"); + + migrationBuilder.DropTable( + name: "CAPPublishedMessage"); + + migrationBuilder.DropTable( + name: "CAPReceivedMessage"); + + migrationBuilder.DropTable( + name: "dept"); + + migrationBuilder.DropTable( + name: "role_permission"); + + migrationBuilder.DropTable( + name: "user_dept"); + + migrationBuilder.DropTable( + name: "user_refresh_token"); + + migrationBuilder.DropTable( + name: "user_role"); + + migrationBuilder.DropTable( + name: "role"); + + migrationBuilder.DropTable( + name: "user"); + } + } +} diff --git a/template/src/ABC.Template.Infrastructure/MigrationsAll/Sqlite-net10.0-admin/ApplicationDbContextModelSnapshot.cs b/template/src/ABC.Template.Infrastructure/MigrationsAll/Sqlite-net10.0-admin/ApplicationDbContextModelSnapshot.cs new file mode 100644 index 00000000..2560f52b --- /dev/null +++ b/template/src/ABC.Template.Infrastructure/MigrationsAll/Sqlite-net10.0-admin/ApplicationDbContextModelSnapshot.cs @@ -0,0 +1,428 @@ +// +using System; +using ABC.Template.Infrastructure; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace ABC.Template.Infrastructure.Migrations +{ + [DbContext(typeof(ApplicationDbContext))] + partial class ApplicationDbContextModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder.HasAnnotation("ProductVersion", "9.0.0"); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.DeptAggregate.Dept", b => + { + b.Property("Id") + .HasColumnType("INTEGER"); + + b.Property("CreatedAt") + .HasColumnType("TEXT"); + + b.Property("DeletedAt") + .HasColumnType("TEXT"); + + b.Property("IsDeleted") + .HasColumnType("INTEGER"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("TEXT"); + + b.Property("ParentId") + .HasColumnType("INTEGER"); + + b.Property("Remark") + .IsRequired() + .HasMaxLength(500) + .HasColumnType("TEXT"); + + b.Property("Status") + .HasColumnType("INTEGER"); + + b.Property("UpdateTime") + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("IsDeleted"); + + b.HasIndex("ParentId"); + + b.HasIndex("Status"); + + b.ToTable("dept", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.Role", b => + { + b.Property("Id") + .HasColumnType("TEXT"); + + b.Property("CreatedAt") + .HasColumnType("TEXT"); + + b.Property("DeletedAt") + .HasColumnType("TEXT"); + + b.Property("Description") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("TEXT"); + + b.Property("IsActive") + .HasColumnType("INTEGER"); + + b.Property("IsDeleted") + .HasColumnType("INTEGER"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("Name") + .IsUnique(); + + b.ToTable("role", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.RolePermission", b => + { + b.Property("RoleId") + .HasColumnType("TEXT"); + + b.Property("PermissionCode") + .HasMaxLength(100) + .HasColumnType("TEXT"); + + b.Property("PermissionDescription") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("TEXT"); + + b.Property("PermissionName") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("TEXT"); + + b.HasKey("RoleId", "PermissionCode"); + + b.ToTable("role_permission", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.User", b => + { + b.Property("Id") + .HasColumnType("INTEGER"); + + b.Property("Age") + .HasColumnType("INTEGER"); + + b.Property("BirthDate") + .HasColumnType("TEXT"); + + b.Property("CreatedAt") + .HasColumnType("TEXT"); + + b.Property("DeletedAt") + .HasColumnType("TEXT"); + + b.Property("Email") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("TEXT"); + + b.Property("Gender") + .IsRequired() + .HasMaxLength(10) + .HasColumnType("TEXT"); + + b.Property("IsActive") + .HasColumnType("INTEGER"); + + b.Property("IsDeleted") + .HasColumnType("INTEGER"); + + b.Property("LastLoginTime") + .HasColumnType("TEXT"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("TEXT"); + + b.Property("PasswordHash") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("TEXT"); + + b.Property("Phone") + .IsRequired() + .HasMaxLength(20) + .HasColumnType("TEXT"); + + b.Property("RealName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("TEXT"); + + b.Property("Status") + .HasColumnType("INTEGER"); + + b.Property("UpdateTime") + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("Email"); + + b.HasIndex("Name"); + + b.ToTable("user", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserDept", b => + { + b.Property("UserId") + .HasColumnType("INTEGER"); + + b.Property("AssignedAt") + .HasColumnType("TEXT"); + + b.Property("DeptId") + .HasColumnType("INTEGER"); + + b.Property("DeptName") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("TEXT"); + + b.HasKey("UserId"); + + b.HasIndex("DeptId"); + + b.HasIndex("UserId"); + + b.ToTable("user_dept", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRefreshToken", b => + { + b.Property("Id") + .HasColumnType("INTEGER"); + + b.Property("CreatedTime") + .HasColumnType("TEXT"); + + b.Property("ExpiresTime") + .HasColumnType("TEXT"); + + b.Property("IsRevoked") + .HasColumnType("INTEGER"); + + b.Property("IsUsed") + .HasColumnType("INTEGER"); + + b.Property("Token") + .IsRequired() + .HasMaxLength(500) + .HasColumnType("TEXT"); + + b.Property("UserId") + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("user_refresh_token", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRole", b => + { + b.Property("UserId") + .HasColumnType("INTEGER"); + + b.Property("RoleId") + .HasColumnType("TEXT"); + + b.Property("RoleName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("TEXT"); + + b.HasKey("UserId", "RoleId"); + + b.ToTable("user_role", (string)null); + }); + + modelBuilder.Entity("NetCorePal.Extensions.DistributedTransactions.CAP.Persistence.CapLock", b => + { + b.Property("Key") + .HasMaxLength(128) + .HasColumnType("TEXT"); + + b.Property("Instance") + .HasMaxLength(256) + .HasColumnType("TEXT"); + + b.Property("LastLockTime") + .HasColumnType("TEXT"); + + b.HasKey("Key"); + + b.ToTable("CAPLock", (string)null); + }); + + modelBuilder.Entity("NetCorePal.Extensions.DistributedTransactions.CAP.Persistence.PublishedMessage", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Added") + .HasColumnType("TEXT"); + + b.Property("Content") + .HasColumnType("TEXT"); + + b.Property("ExpiresAt") + .HasColumnType("TEXT"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("TEXT"); + + b.Property("Retries") + .HasColumnType("INTEGER"); + + b.Property("StatusName") + .IsRequired() + .HasMaxLength(40) + .HasColumnType("TEXT"); + + b.Property("Version") + .HasMaxLength(20) + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex(new[] { "ExpiresAt", "StatusName" }, "IX_ExpiresAt_StatusName"); + + b.HasIndex(new[] { "Version", "ExpiresAt", "StatusName" }, "IX_Version_ExpiresAt_StatusName"); + + b.ToTable("CAPPublishedMessage", (string)null); + }); + + modelBuilder.Entity("NetCorePal.Extensions.DistributedTransactions.CAP.Persistence.ReceivedMessage", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Added") + .HasColumnType("TEXT"); + + b.Property("Content") + .HasColumnType("TEXT"); + + b.Property("ExpiresAt") + .HasColumnType("TEXT"); + + b.Property("Group") + .HasMaxLength(200) + .HasColumnType("TEXT"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(400) + .HasColumnType("TEXT"); + + b.Property("Retries") + .HasColumnType("INTEGER"); + + b.Property("StatusName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("TEXT"); + + b.Property("Version") + .HasMaxLength(20) + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex(new[] { "ExpiresAt", "StatusName" }, "IX_ExpiresAt_StatusName") + .HasDatabaseName("IX_ExpiresAt_StatusName1"); + + b.HasIndex(new[] { "Version", "ExpiresAt", "StatusName" }, "IX_Version_ExpiresAt_StatusName") + .HasDatabaseName("IX_Version_ExpiresAt_StatusName1"); + + b.ToTable("CAPReceivedMessage", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.RolePermission", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.RoleAggregate.Role", null) + .WithMany("Permissions") + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserDept", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.UserAggregate.User", null) + .WithOne("Dept") + .HasForeignKey("ABC.Template.Domain.AggregatesModel.UserAggregate.UserDept", "UserId") + .OnDelete(DeleteBehavior.ClientCascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRefreshToken", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.UserAggregate.User", null) + .WithMany("RefreshTokens") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRole", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.UserAggregate.User", null) + .WithMany("Roles") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.Role", b => + { + b.Navigation("Permissions"); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.User", b => + { + b.Navigation("Dept") + .IsRequired(); + + b.Navigation("RefreshTokens"); + + b.Navigation("Roles"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/template/src/ABC.Template.Infrastructure/MigrationsAll/Sqlite-net9.0/20251225065129_Init.Designer.cs b/template/src/ABC.Template.Infrastructure/MigrationsAll/Sqlite-net10.0/20260122054854_Init.Designer.cs similarity index 76% rename from template/src/ABC.Template.Infrastructure/MigrationsAll/Sqlite-net9.0/20251225065129_Init.Designer.cs rename to template/src/ABC.Template.Infrastructure/MigrationsAll/Sqlite-net10.0/20260122054854_Init.Designer.cs index 224708ba..8b91f307 100644 --- a/template/src/ABC.Template.Infrastructure/MigrationsAll/Sqlite-net9.0/20251225065129_Init.Designer.cs +++ b/template/src/ABC.Template.Infrastructure/MigrationsAll/Sqlite-net10.0/20260122054854_Init.Designer.cs @@ -1,17 +1,17 @@ // using System; +using ABC.Template.Infrastructure; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using ABC.Template.Infrastructure; #nullable disable namespace ABC.Template.Infrastructure.Migrations { [DbContext(typeof(ApplicationDbContext))] - [Migration("20251225065129_Init")] + [Migration("20260122054854_Init")] partial class Init { /// @@ -125,47 +125,6 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.ToTable("CAPReceivedMessage", (string)null); }); - - modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.DeliverAggregate.DeliverRecord", b => - { - b.Property("Id") - .HasColumnType("TEXT"); - - b.Property("OrderId") - .HasColumnType("TEXT"); - - b.HasKey("Id"); - - b.ToTable("deliverrecord", (string)null); - }); - - modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.OrderAggregate.Order", b => - { - b.Property("Id") - .HasColumnType("TEXT"); - - b.Property("Count") - .HasColumnType("INTEGER"); - - b.Property("Name") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("TEXT"); - - b.Property("Paid") - .HasColumnType("INTEGER"); - - b.Property("RowVersion") - .IsConcurrencyToken() - .HasColumnType("INTEGER"); - - b.Property("UpdateTime") - .HasColumnType("TEXT"); - - b.HasKey("Id"); - - b.ToTable("order", (string)null); - }); #pragma warning restore 612, 618 } } diff --git a/template/src/ABC.Template.Infrastructure/MigrationsAll/Sqlite-net8.0/20251225065119_Init.cs b/template/src/ABC.Template.Infrastructure/MigrationsAll/Sqlite-net10.0/20260122054854_Init.cs similarity index 75% rename from template/src/ABC.Template.Infrastructure/MigrationsAll/Sqlite-net8.0/20251225065119_Init.cs rename to template/src/ABC.Template.Infrastructure/MigrationsAll/Sqlite-net10.0/20260122054854_Init.cs index cbe4a168..b3cf0f21 100644 --- a/template/src/ABC.Template.Infrastructure/MigrationsAll/Sqlite-net8.0/20251225065119_Init.cs +++ b/template/src/ABC.Template.Infrastructure/MigrationsAll/Sqlite-net10.0/20260122054854_Init.cs @@ -63,34 +63,6 @@ protected override void Up(MigrationBuilder migrationBuilder) table.PrimaryKey("PK_CAPReceivedMessage", x => x.Id); }); - migrationBuilder.CreateTable( - name: "deliverrecord", - columns: table => new - { - Id = table.Column(type: "TEXT", nullable: false), - OrderId = table.Column(type: "TEXT", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_deliverrecord", x => x.Id); - }); - - migrationBuilder.CreateTable( - name: "order", - columns: table => new - { - Id = table.Column(type: "TEXT", nullable: false), - Paid = table.Column(type: "INTEGER", nullable: false), - Name = table.Column(type: "TEXT", maxLength: 100, nullable: false), - Count = table.Column(type: "INTEGER", nullable: false), - RowVersion = table.Column(type: "INTEGER", nullable: false), - UpdateTime = table.Column(type: "TEXT", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_order", x => x.Id); - }); - migrationBuilder.CreateIndex( name: "IX_ExpiresAt_StatusName", table: "CAPPublishedMessage", @@ -123,12 +95,6 @@ protected override void Down(MigrationBuilder migrationBuilder) migrationBuilder.DropTable( name: "CAPReceivedMessage"); - - migrationBuilder.DropTable( - name: "deliverrecord"); - - migrationBuilder.DropTable( - name: "order"); } } } diff --git a/template/src/ABC.Template.Infrastructure/MigrationsAll/Sqlite-net10.0/ApplicationDbContextModelSnapshot.cs b/template/src/ABC.Template.Infrastructure/MigrationsAll/Sqlite-net10.0/ApplicationDbContextModelSnapshot.cs index 40255e29..5e0abc7a 100644 --- a/template/src/ABC.Template.Infrastructure/MigrationsAll/Sqlite-net10.0/ApplicationDbContextModelSnapshot.cs +++ b/template/src/ABC.Template.Infrastructure/MigrationsAll/Sqlite-net10.0/ApplicationDbContextModelSnapshot.cs @@ -1,9 +1,9 @@ // using System; +using ABC.Template.Infrastructure; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using ABC.Template.Infrastructure; #nullable disable @@ -122,47 +122,6 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.ToTable("CAPReceivedMessage", (string)null); }); - - modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.DeliverAggregate.DeliverRecord", b => - { - b.Property("Id") - .HasColumnType("TEXT"); - - b.Property("OrderId") - .HasColumnType("TEXT"); - - b.HasKey("Id"); - - b.ToTable("deliverrecord", (string)null); - }); - - modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.OrderAggregate.Order", b => - { - b.Property("Id") - .HasColumnType("TEXT"); - - b.Property("Count") - .HasColumnType("INTEGER"); - - b.Property("Name") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("TEXT"); - - b.Property("Paid") - .HasColumnType("INTEGER"); - - b.Property("RowVersion") - .IsConcurrencyToken() - .HasColumnType("INTEGER"); - - b.Property("UpdateTime") - .HasColumnType("TEXT"); - - b.HasKey("Id"); - - b.ToTable("order", (string)null); - }); #pragma warning restore 612, 618 } } diff --git a/template/src/ABC.Template.Infrastructure/MigrationsAll/Sqlite-net8.0-admin/20260122054822_Init.Designer.cs b/template/src/ABC.Template.Infrastructure/MigrationsAll/Sqlite-net8.0-admin/20260122054822_Init.Designer.cs new file mode 100644 index 00000000..0ebd567d --- /dev/null +++ b/template/src/ABC.Template.Infrastructure/MigrationsAll/Sqlite-net8.0-admin/20260122054822_Init.Designer.cs @@ -0,0 +1,431 @@ +// +using System; +using ABC.Template.Infrastructure; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace ABC.Template.Infrastructure.Migrations +{ + [DbContext(typeof(ApplicationDbContext))] + [Migration("20260122054822_Init")] + partial class Init + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder.HasAnnotation("ProductVersion", "8.0.10"); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.DeptAggregate.Dept", b => + { + b.Property("Id") + .HasColumnType("INTEGER"); + + b.Property("CreatedAt") + .HasColumnType("TEXT"); + + b.Property("DeletedAt") + .HasColumnType("TEXT"); + + b.Property("IsDeleted") + .HasColumnType("INTEGER"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("TEXT"); + + b.Property("ParentId") + .HasColumnType("INTEGER"); + + b.Property("Remark") + .IsRequired() + .HasMaxLength(500) + .HasColumnType("TEXT"); + + b.Property("Status") + .HasColumnType("INTEGER"); + + b.Property("UpdateTime") + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("IsDeleted"); + + b.HasIndex("ParentId"); + + b.HasIndex("Status"); + + b.ToTable("dept", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.Role", b => + { + b.Property("Id") + .HasColumnType("TEXT"); + + b.Property("CreatedAt") + .HasColumnType("TEXT"); + + b.Property("DeletedAt") + .HasColumnType("TEXT"); + + b.Property("Description") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("TEXT"); + + b.Property("IsActive") + .HasColumnType("INTEGER"); + + b.Property("IsDeleted") + .HasColumnType("INTEGER"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("Name") + .IsUnique(); + + b.ToTable("role", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.RolePermission", b => + { + b.Property("RoleId") + .HasColumnType("TEXT"); + + b.Property("PermissionCode") + .HasMaxLength(100) + .HasColumnType("TEXT"); + + b.Property("PermissionDescription") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("TEXT"); + + b.Property("PermissionName") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("TEXT"); + + b.HasKey("RoleId", "PermissionCode"); + + b.ToTable("role_permission", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.User", b => + { + b.Property("Id") + .HasColumnType("INTEGER"); + + b.Property("Age") + .HasColumnType("INTEGER"); + + b.Property("BirthDate") + .HasColumnType("TEXT"); + + b.Property("CreatedAt") + .HasColumnType("TEXT"); + + b.Property("DeletedAt") + .HasColumnType("TEXT"); + + b.Property("Email") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("TEXT"); + + b.Property("Gender") + .IsRequired() + .HasMaxLength(10) + .HasColumnType("TEXT"); + + b.Property("IsActive") + .HasColumnType("INTEGER"); + + b.Property("IsDeleted") + .HasColumnType("INTEGER"); + + b.Property("LastLoginTime") + .HasColumnType("TEXT"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("TEXT"); + + b.Property("PasswordHash") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("TEXT"); + + b.Property("Phone") + .IsRequired() + .HasMaxLength(20) + .HasColumnType("TEXT"); + + b.Property("RealName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("TEXT"); + + b.Property("Status") + .HasColumnType("INTEGER"); + + b.Property("UpdateTime") + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("Email"); + + b.HasIndex("Name"); + + b.ToTable("user", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserDept", b => + { + b.Property("UserId") + .HasColumnType("INTEGER"); + + b.Property("AssignedAt") + .HasColumnType("TEXT"); + + b.Property("DeptId") + .HasColumnType("INTEGER"); + + b.Property("DeptName") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("TEXT"); + + b.HasKey("UserId"); + + b.HasIndex("DeptId"); + + b.HasIndex("UserId"); + + b.ToTable("user_dept", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRefreshToken", b => + { + b.Property("Id") + .HasColumnType("INTEGER"); + + b.Property("CreatedTime") + .HasColumnType("TEXT"); + + b.Property("ExpiresTime") + .HasColumnType("TEXT"); + + b.Property("IsRevoked") + .HasColumnType("INTEGER"); + + b.Property("IsUsed") + .HasColumnType("INTEGER"); + + b.Property("Token") + .IsRequired() + .HasMaxLength(500) + .HasColumnType("TEXT"); + + b.Property("UserId") + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("user_refresh_token", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRole", b => + { + b.Property("UserId") + .HasColumnType("INTEGER"); + + b.Property("RoleId") + .HasColumnType("TEXT"); + + b.Property("RoleName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("TEXT"); + + b.HasKey("UserId", "RoleId"); + + b.ToTable("user_role", (string)null); + }); + + modelBuilder.Entity("NetCorePal.Extensions.DistributedTransactions.CAP.Persistence.CapLock", b => + { + b.Property("Key") + .HasMaxLength(128) + .HasColumnType("TEXT"); + + b.Property("Instance") + .HasMaxLength(256) + .HasColumnType("TEXT"); + + b.Property("LastLockTime") + .HasColumnType("TEXT"); + + b.HasKey("Key"); + + b.ToTable("CAPLock", (string)null); + }); + + modelBuilder.Entity("NetCorePal.Extensions.DistributedTransactions.CAP.Persistence.PublishedMessage", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Added") + .HasColumnType("TEXT"); + + b.Property("Content") + .HasColumnType("TEXT"); + + b.Property("ExpiresAt") + .HasColumnType("TEXT"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("TEXT"); + + b.Property("Retries") + .HasColumnType("INTEGER"); + + b.Property("StatusName") + .IsRequired() + .HasMaxLength(40) + .HasColumnType("TEXT"); + + b.Property("Version") + .HasMaxLength(20) + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex(new[] { "ExpiresAt", "StatusName" }, "IX_ExpiresAt_StatusName"); + + b.HasIndex(new[] { "Version", "ExpiresAt", "StatusName" }, "IX_Version_ExpiresAt_StatusName"); + + b.ToTable("CAPPublishedMessage", (string)null); + }); + + modelBuilder.Entity("NetCorePal.Extensions.DistributedTransactions.CAP.Persistence.ReceivedMessage", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Added") + .HasColumnType("TEXT"); + + b.Property("Content") + .HasColumnType("TEXT"); + + b.Property("ExpiresAt") + .HasColumnType("TEXT"); + + b.Property("Group") + .HasMaxLength(200) + .HasColumnType("TEXT"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(400) + .HasColumnType("TEXT"); + + b.Property("Retries") + .HasColumnType("INTEGER"); + + b.Property("StatusName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("TEXT"); + + b.Property("Version") + .HasMaxLength(20) + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex(new[] { "ExpiresAt", "StatusName" }, "IX_ExpiresAt_StatusName") + .HasDatabaseName("IX_ExpiresAt_StatusName1"); + + b.HasIndex(new[] { "Version", "ExpiresAt", "StatusName" }, "IX_Version_ExpiresAt_StatusName") + .HasDatabaseName("IX_Version_ExpiresAt_StatusName1"); + + b.ToTable("CAPReceivedMessage", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.RolePermission", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.RoleAggregate.Role", null) + .WithMany("Permissions") + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserDept", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.UserAggregate.User", null) + .WithOne("Dept") + .HasForeignKey("ABC.Template.Domain.AggregatesModel.UserAggregate.UserDept", "UserId") + .OnDelete(DeleteBehavior.ClientCascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRefreshToken", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.UserAggregate.User", null) + .WithMany("RefreshTokens") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRole", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.UserAggregate.User", null) + .WithMany("Roles") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.Role", b => + { + b.Navigation("Permissions"); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.User", b => + { + b.Navigation("Dept") + .IsRequired(); + + b.Navigation("RefreshTokens"); + + b.Navigation("Roles"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/template/src/ABC.Template.Infrastructure/MigrationsAll/Sqlite-net8.0-admin/20260122054822_Init.cs b/template/src/ABC.Template.Infrastructure/MigrationsAll/Sqlite-net8.0-admin/20260122054822_Init.cs new file mode 100644 index 00000000..aaab0e3f --- /dev/null +++ b/template/src/ABC.Template.Infrastructure/MigrationsAll/Sqlite-net8.0-admin/20260122054822_Init.cs @@ -0,0 +1,310 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace ABC.Template.Infrastructure.Migrations +{ + /// + public partial class Init : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "CAPLock", + columns: table => new + { + Key = table.Column(type: "TEXT", maxLength: 128, nullable: false), + Instance = table.Column(type: "TEXT", maxLength: 256, nullable: true), + LastLockTime = table.Column(type: "TEXT", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_CAPLock", x => x.Key); + }); + + migrationBuilder.CreateTable( + name: "CAPPublishedMessage", + columns: table => new + { + Id = table.Column(type: "INTEGER", nullable: false) + .Annotation("Sqlite:Autoincrement", true), + Version = table.Column(type: "TEXT", maxLength: 20, nullable: true), + Name = table.Column(type: "TEXT", maxLength: 200, nullable: false), + Content = table.Column(type: "TEXT", nullable: true), + Retries = table.Column(type: "INTEGER", nullable: true), + Added = table.Column(type: "TEXT", nullable: false), + ExpiresAt = table.Column(type: "TEXT", nullable: true), + StatusName = table.Column(type: "TEXT", maxLength: 40, nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_CAPPublishedMessage", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "CAPReceivedMessage", + columns: table => new + { + Id = table.Column(type: "INTEGER", nullable: false) + .Annotation("Sqlite:Autoincrement", true), + Version = table.Column(type: "TEXT", maxLength: 20, nullable: true), + Name = table.Column(type: "TEXT", maxLength: 400, nullable: false), + Group = table.Column(type: "TEXT", maxLength: 200, nullable: true), + Content = table.Column(type: "TEXT", nullable: true), + Retries = table.Column(type: "INTEGER", nullable: true), + Added = table.Column(type: "TEXT", nullable: false), + ExpiresAt = table.Column(type: "TEXT", nullable: true), + StatusName = table.Column(type: "TEXT", maxLength: 50, nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_CAPReceivedMessage", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "dept", + columns: table => new + { + Id = table.Column(type: "INTEGER", nullable: false), + Name = table.Column(type: "TEXT", maxLength: 100, nullable: false), + Remark = table.Column(type: "TEXT", maxLength: 500, nullable: false), + ParentId = table.Column(type: "INTEGER", nullable: false), + Status = table.Column(type: "INTEGER", nullable: false), + CreatedAt = table.Column(type: "TEXT", nullable: false), + IsDeleted = table.Column(type: "INTEGER", nullable: false), + DeletedAt = table.Column(type: "TEXT", nullable: false), + UpdateTime = table.Column(type: "TEXT", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_dept", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "role", + columns: table => new + { + Id = table.Column(type: "TEXT", nullable: false), + Name = table.Column(type: "TEXT", maxLength: 50, nullable: false), + Description = table.Column(type: "TEXT", maxLength: 200, nullable: false), + CreatedAt = table.Column(type: "TEXT", nullable: false), + IsActive = table.Column(type: "INTEGER", nullable: false), + IsDeleted = table.Column(type: "INTEGER", nullable: false), + DeletedAt = table.Column(type: "TEXT", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_role", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "user", + columns: table => new + { + Id = table.Column(type: "INTEGER", nullable: false), + Name = table.Column(type: "TEXT", maxLength: 50, nullable: false), + Email = table.Column(type: "TEXT", maxLength: 100, nullable: false), + Phone = table.Column(type: "TEXT", maxLength: 20, nullable: false), + RealName = table.Column(type: "TEXT", maxLength: 50, nullable: false), + Status = table.Column(type: "INTEGER", nullable: false), + PasswordHash = table.Column(type: "TEXT", maxLength: 255, nullable: false), + IsActive = table.Column(type: "INTEGER", nullable: false), + CreatedAt = table.Column(type: "TEXT", nullable: false), + LastLoginTime = table.Column(type: "TEXT", nullable: true), + UpdateTime = table.Column(type: "TEXT", nullable: false), + IsDeleted = table.Column(type: "INTEGER", nullable: false), + DeletedAt = table.Column(type: "TEXT", nullable: false), + Gender = table.Column(type: "TEXT", maxLength: 10, nullable: false), + Age = table.Column(type: "INTEGER", nullable: false), + BirthDate = table.Column(type: "TEXT", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_user", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "role_permission", + columns: table => new + { + RoleId = table.Column(type: "TEXT", nullable: false), + PermissionCode = table.Column(type: "TEXT", maxLength: 100, nullable: false), + PermissionName = table.Column(type: "TEXT", maxLength: 100, nullable: false), + PermissionDescription = table.Column(type: "TEXT", maxLength: 200, nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_role_permission", x => new { x.RoleId, x.PermissionCode }); + table.ForeignKey( + name: "FK_role_permission_role_RoleId", + column: x => x.RoleId, + principalTable: "role", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "user_dept", + columns: table => new + { + UserId = table.Column(type: "INTEGER", nullable: false), + DeptId = table.Column(type: "INTEGER", nullable: false), + DeptName = table.Column(type: "TEXT", maxLength: 100, nullable: false), + AssignedAt = table.Column(type: "TEXT", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_user_dept", x => x.UserId); + table.ForeignKey( + name: "FK_user_dept_user_UserId", + column: x => x.UserId, + principalTable: "user", + principalColumn: "Id"); + }); + + migrationBuilder.CreateTable( + name: "user_refresh_token", + columns: table => new + { + Id = table.Column(type: "INTEGER", nullable: false), + UserId = table.Column(type: "INTEGER", nullable: false), + Token = table.Column(type: "TEXT", maxLength: 500, nullable: false), + CreatedTime = table.Column(type: "TEXT", nullable: false), + ExpiresTime = table.Column(type: "TEXT", nullable: false), + IsUsed = table.Column(type: "INTEGER", nullable: false), + IsRevoked = table.Column(type: "INTEGER", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_user_refresh_token", x => x.Id); + table.ForeignKey( + name: "FK_user_refresh_token_user_UserId", + column: x => x.UserId, + principalTable: "user", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "user_role", + columns: table => new + { + UserId = table.Column(type: "INTEGER", nullable: false), + RoleId = table.Column(type: "TEXT", nullable: false), + RoleName = table.Column(type: "TEXT", maxLength: 50, nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_user_role", x => new { x.UserId, x.RoleId }); + table.ForeignKey( + name: "FK_user_role_user_UserId", + column: x => x.UserId, + principalTable: "user", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_ExpiresAt_StatusName", + table: "CAPPublishedMessage", + columns: new[] { "ExpiresAt", "StatusName" }); + + migrationBuilder.CreateIndex( + name: "IX_Version_ExpiresAt_StatusName", + table: "CAPPublishedMessage", + columns: new[] { "Version", "ExpiresAt", "StatusName" }); + + migrationBuilder.CreateIndex( + name: "IX_ExpiresAt_StatusName1", + table: "CAPReceivedMessage", + columns: new[] { "ExpiresAt", "StatusName" }); + + migrationBuilder.CreateIndex( + name: "IX_Version_ExpiresAt_StatusName1", + table: "CAPReceivedMessage", + columns: new[] { "Version", "ExpiresAt", "StatusName" }); + + migrationBuilder.CreateIndex( + name: "IX_dept_IsDeleted", + table: "dept", + column: "IsDeleted"); + + migrationBuilder.CreateIndex( + name: "IX_dept_ParentId", + table: "dept", + column: "ParentId"); + + migrationBuilder.CreateIndex( + name: "IX_dept_Status", + table: "dept", + column: "Status"); + + migrationBuilder.CreateIndex( + name: "IX_role_Name", + table: "role", + column: "Name", + unique: true); + + migrationBuilder.CreateIndex( + name: "IX_user_Email", + table: "user", + column: "Email"); + + migrationBuilder.CreateIndex( + name: "IX_user_Name", + table: "user", + column: "Name"); + + migrationBuilder.CreateIndex( + name: "IX_user_dept_DeptId", + table: "user_dept", + column: "DeptId"); + + migrationBuilder.CreateIndex( + name: "IX_user_dept_UserId", + table: "user_dept", + column: "UserId"); + + migrationBuilder.CreateIndex( + name: "IX_user_refresh_token_UserId", + table: "user_refresh_token", + column: "UserId"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "CAPLock"); + + migrationBuilder.DropTable( + name: "CAPPublishedMessage"); + + migrationBuilder.DropTable( + name: "CAPReceivedMessage"); + + migrationBuilder.DropTable( + name: "dept"); + + migrationBuilder.DropTable( + name: "role_permission"); + + migrationBuilder.DropTable( + name: "user_dept"); + + migrationBuilder.DropTable( + name: "user_refresh_token"); + + migrationBuilder.DropTable( + name: "user_role"); + + migrationBuilder.DropTable( + name: "role"); + + migrationBuilder.DropTable( + name: "user"); + } + } +} diff --git a/template/src/ABC.Template.Infrastructure/MigrationsAll/Sqlite-net8.0-admin/ApplicationDbContextModelSnapshot.cs b/template/src/ABC.Template.Infrastructure/MigrationsAll/Sqlite-net8.0-admin/ApplicationDbContextModelSnapshot.cs new file mode 100644 index 00000000..649c8fdf --- /dev/null +++ b/template/src/ABC.Template.Infrastructure/MigrationsAll/Sqlite-net8.0-admin/ApplicationDbContextModelSnapshot.cs @@ -0,0 +1,428 @@ +// +using System; +using ABC.Template.Infrastructure; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace ABC.Template.Infrastructure.Migrations +{ + [DbContext(typeof(ApplicationDbContext))] + partial class ApplicationDbContextModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder.HasAnnotation("ProductVersion", "8.0.10"); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.DeptAggregate.Dept", b => + { + b.Property("Id") + .HasColumnType("INTEGER"); + + b.Property("CreatedAt") + .HasColumnType("TEXT"); + + b.Property("DeletedAt") + .HasColumnType("TEXT"); + + b.Property("IsDeleted") + .HasColumnType("INTEGER"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("TEXT"); + + b.Property("ParentId") + .HasColumnType("INTEGER"); + + b.Property("Remark") + .IsRequired() + .HasMaxLength(500) + .HasColumnType("TEXT"); + + b.Property("Status") + .HasColumnType("INTEGER"); + + b.Property("UpdateTime") + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("IsDeleted"); + + b.HasIndex("ParentId"); + + b.HasIndex("Status"); + + b.ToTable("dept", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.Role", b => + { + b.Property("Id") + .HasColumnType("TEXT"); + + b.Property("CreatedAt") + .HasColumnType("TEXT"); + + b.Property("DeletedAt") + .HasColumnType("TEXT"); + + b.Property("Description") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("TEXT"); + + b.Property("IsActive") + .HasColumnType("INTEGER"); + + b.Property("IsDeleted") + .HasColumnType("INTEGER"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("Name") + .IsUnique(); + + b.ToTable("role", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.RolePermission", b => + { + b.Property("RoleId") + .HasColumnType("TEXT"); + + b.Property("PermissionCode") + .HasMaxLength(100) + .HasColumnType("TEXT"); + + b.Property("PermissionDescription") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("TEXT"); + + b.Property("PermissionName") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("TEXT"); + + b.HasKey("RoleId", "PermissionCode"); + + b.ToTable("role_permission", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.User", b => + { + b.Property("Id") + .HasColumnType("INTEGER"); + + b.Property("Age") + .HasColumnType("INTEGER"); + + b.Property("BirthDate") + .HasColumnType("TEXT"); + + b.Property("CreatedAt") + .HasColumnType("TEXT"); + + b.Property("DeletedAt") + .HasColumnType("TEXT"); + + b.Property("Email") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("TEXT"); + + b.Property("Gender") + .IsRequired() + .HasMaxLength(10) + .HasColumnType("TEXT"); + + b.Property("IsActive") + .HasColumnType("INTEGER"); + + b.Property("IsDeleted") + .HasColumnType("INTEGER"); + + b.Property("LastLoginTime") + .HasColumnType("TEXT"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("TEXT"); + + b.Property("PasswordHash") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("TEXT"); + + b.Property("Phone") + .IsRequired() + .HasMaxLength(20) + .HasColumnType("TEXT"); + + b.Property("RealName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("TEXT"); + + b.Property("Status") + .HasColumnType("INTEGER"); + + b.Property("UpdateTime") + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("Email"); + + b.HasIndex("Name"); + + b.ToTable("user", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserDept", b => + { + b.Property("UserId") + .HasColumnType("INTEGER"); + + b.Property("AssignedAt") + .HasColumnType("TEXT"); + + b.Property("DeptId") + .HasColumnType("INTEGER"); + + b.Property("DeptName") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("TEXT"); + + b.HasKey("UserId"); + + b.HasIndex("DeptId"); + + b.HasIndex("UserId"); + + b.ToTable("user_dept", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRefreshToken", b => + { + b.Property("Id") + .HasColumnType("INTEGER"); + + b.Property("CreatedTime") + .HasColumnType("TEXT"); + + b.Property("ExpiresTime") + .HasColumnType("TEXT"); + + b.Property("IsRevoked") + .HasColumnType("INTEGER"); + + b.Property("IsUsed") + .HasColumnType("INTEGER"); + + b.Property("Token") + .IsRequired() + .HasMaxLength(500) + .HasColumnType("TEXT"); + + b.Property("UserId") + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("user_refresh_token", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRole", b => + { + b.Property("UserId") + .HasColumnType("INTEGER"); + + b.Property("RoleId") + .HasColumnType("TEXT"); + + b.Property("RoleName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("TEXT"); + + b.HasKey("UserId", "RoleId"); + + b.ToTable("user_role", (string)null); + }); + + modelBuilder.Entity("NetCorePal.Extensions.DistributedTransactions.CAP.Persistence.CapLock", b => + { + b.Property("Key") + .HasMaxLength(128) + .HasColumnType("TEXT"); + + b.Property("Instance") + .HasMaxLength(256) + .HasColumnType("TEXT"); + + b.Property("LastLockTime") + .HasColumnType("TEXT"); + + b.HasKey("Key"); + + b.ToTable("CAPLock", (string)null); + }); + + modelBuilder.Entity("NetCorePal.Extensions.DistributedTransactions.CAP.Persistence.PublishedMessage", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Added") + .HasColumnType("TEXT"); + + b.Property("Content") + .HasColumnType("TEXT"); + + b.Property("ExpiresAt") + .HasColumnType("TEXT"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("TEXT"); + + b.Property("Retries") + .HasColumnType("INTEGER"); + + b.Property("StatusName") + .IsRequired() + .HasMaxLength(40) + .HasColumnType("TEXT"); + + b.Property("Version") + .HasMaxLength(20) + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex(new[] { "ExpiresAt", "StatusName" }, "IX_ExpiresAt_StatusName"); + + b.HasIndex(new[] { "Version", "ExpiresAt", "StatusName" }, "IX_Version_ExpiresAt_StatusName"); + + b.ToTable("CAPPublishedMessage", (string)null); + }); + + modelBuilder.Entity("NetCorePal.Extensions.DistributedTransactions.CAP.Persistence.ReceivedMessage", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Added") + .HasColumnType("TEXT"); + + b.Property("Content") + .HasColumnType("TEXT"); + + b.Property("ExpiresAt") + .HasColumnType("TEXT"); + + b.Property("Group") + .HasMaxLength(200) + .HasColumnType("TEXT"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(400) + .HasColumnType("TEXT"); + + b.Property("Retries") + .HasColumnType("INTEGER"); + + b.Property("StatusName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("TEXT"); + + b.Property("Version") + .HasMaxLength(20) + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex(new[] { "ExpiresAt", "StatusName" }, "IX_ExpiresAt_StatusName") + .HasDatabaseName("IX_ExpiresAt_StatusName1"); + + b.HasIndex(new[] { "Version", "ExpiresAt", "StatusName" }, "IX_Version_ExpiresAt_StatusName") + .HasDatabaseName("IX_Version_ExpiresAt_StatusName1"); + + b.ToTable("CAPReceivedMessage", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.RolePermission", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.RoleAggregate.Role", null) + .WithMany("Permissions") + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserDept", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.UserAggregate.User", null) + .WithOne("Dept") + .HasForeignKey("ABC.Template.Domain.AggregatesModel.UserAggregate.UserDept", "UserId") + .OnDelete(DeleteBehavior.ClientCascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRefreshToken", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.UserAggregate.User", null) + .WithMany("RefreshTokens") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRole", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.UserAggregate.User", null) + .WithMany("Roles") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.Role", b => + { + b.Navigation("Permissions"); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.User", b => + { + b.Navigation("Dept") + .IsRequired(); + + b.Navigation("RefreshTokens"); + + b.Navigation("Roles"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/template/src/ABC.Template.Infrastructure/MigrationsAll/Sqlite-net8.0/20251225065119_Init.Designer.cs b/template/src/ABC.Template.Infrastructure/MigrationsAll/Sqlite-net8.0/20260122054811_Init.Designer.cs similarity index 76% rename from template/src/ABC.Template.Infrastructure/MigrationsAll/Sqlite-net8.0/20251225065119_Init.Designer.cs rename to template/src/ABC.Template.Infrastructure/MigrationsAll/Sqlite-net8.0/20260122054811_Init.Designer.cs index 49374508..b7ec4204 100644 --- a/template/src/ABC.Template.Infrastructure/MigrationsAll/Sqlite-net8.0/20251225065119_Init.Designer.cs +++ b/template/src/ABC.Template.Infrastructure/MigrationsAll/Sqlite-net8.0/20260122054811_Init.Designer.cs @@ -1,17 +1,17 @@ // using System; +using ABC.Template.Infrastructure; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using ABC.Template.Infrastructure; #nullable disable namespace ABC.Template.Infrastructure.Migrations { [DbContext(typeof(ApplicationDbContext))] - [Migration("20251225065119_Init")] + [Migration("20260122054811_Init")] partial class Init { /// @@ -125,47 +125,6 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.ToTable("CAPReceivedMessage", (string)null); }); - - modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.DeliverAggregate.DeliverRecord", b => - { - b.Property("Id") - .HasColumnType("TEXT"); - - b.Property("OrderId") - .HasColumnType("TEXT"); - - b.HasKey("Id"); - - b.ToTable("deliverrecord", (string)null); - }); - - modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.OrderAggregate.Order", b => - { - b.Property("Id") - .HasColumnType("TEXT"); - - b.Property("Count") - .HasColumnType("INTEGER"); - - b.Property("Name") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("TEXT"); - - b.Property("Paid") - .HasColumnType("INTEGER"); - - b.Property("RowVersion") - .IsConcurrencyToken() - .HasColumnType("INTEGER"); - - b.Property("UpdateTime") - .HasColumnType("TEXT"); - - b.HasKey("Id"); - - b.ToTable("order", (string)null); - }); #pragma warning restore 612, 618 } } diff --git a/template/src/ABC.Template.Infrastructure/MigrationsAll/Sqlite-net9.0/20251225065129_Init.cs b/template/src/ABC.Template.Infrastructure/MigrationsAll/Sqlite-net8.0/20260122054811_Init.cs similarity index 75% rename from template/src/ABC.Template.Infrastructure/MigrationsAll/Sqlite-net9.0/20251225065129_Init.cs rename to template/src/ABC.Template.Infrastructure/MigrationsAll/Sqlite-net8.0/20260122054811_Init.cs index cbe4a168..b3cf0f21 100644 --- a/template/src/ABC.Template.Infrastructure/MigrationsAll/Sqlite-net9.0/20251225065129_Init.cs +++ b/template/src/ABC.Template.Infrastructure/MigrationsAll/Sqlite-net8.0/20260122054811_Init.cs @@ -63,34 +63,6 @@ protected override void Up(MigrationBuilder migrationBuilder) table.PrimaryKey("PK_CAPReceivedMessage", x => x.Id); }); - migrationBuilder.CreateTable( - name: "deliverrecord", - columns: table => new - { - Id = table.Column(type: "TEXT", nullable: false), - OrderId = table.Column(type: "TEXT", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_deliverrecord", x => x.Id); - }); - - migrationBuilder.CreateTable( - name: "order", - columns: table => new - { - Id = table.Column(type: "TEXT", nullable: false), - Paid = table.Column(type: "INTEGER", nullable: false), - Name = table.Column(type: "TEXT", maxLength: 100, nullable: false), - Count = table.Column(type: "INTEGER", nullable: false), - RowVersion = table.Column(type: "INTEGER", nullable: false), - UpdateTime = table.Column(type: "TEXT", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_order", x => x.Id); - }); - migrationBuilder.CreateIndex( name: "IX_ExpiresAt_StatusName", table: "CAPPublishedMessage", @@ -123,12 +95,6 @@ protected override void Down(MigrationBuilder migrationBuilder) migrationBuilder.DropTable( name: "CAPReceivedMessage"); - - migrationBuilder.DropTable( - name: "deliverrecord"); - - migrationBuilder.DropTable( - name: "order"); } } } diff --git a/template/src/ABC.Template.Infrastructure/MigrationsAll/Sqlite-net8.0/ApplicationDbContextModelSnapshot.cs b/template/src/ABC.Template.Infrastructure/MigrationsAll/Sqlite-net8.0/ApplicationDbContextModelSnapshot.cs index a4e27c64..9a2b64d1 100644 --- a/template/src/ABC.Template.Infrastructure/MigrationsAll/Sqlite-net8.0/ApplicationDbContextModelSnapshot.cs +++ b/template/src/ABC.Template.Infrastructure/MigrationsAll/Sqlite-net8.0/ApplicationDbContextModelSnapshot.cs @@ -1,9 +1,9 @@ // using System; +using ABC.Template.Infrastructure; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using ABC.Template.Infrastructure; #nullable disable @@ -122,47 +122,6 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.ToTable("CAPReceivedMessage", (string)null); }); - - modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.DeliverAggregate.DeliverRecord", b => - { - b.Property("Id") - .HasColumnType("TEXT"); - - b.Property("OrderId") - .HasColumnType("TEXT"); - - b.HasKey("Id"); - - b.ToTable("deliverrecord", (string)null); - }); - - modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.OrderAggregate.Order", b => - { - b.Property("Id") - .HasColumnType("TEXT"); - - b.Property("Count") - .HasColumnType("INTEGER"); - - b.Property("Name") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("TEXT"); - - b.Property("Paid") - .HasColumnType("INTEGER"); - - b.Property("RowVersion") - .IsConcurrencyToken() - .HasColumnType("INTEGER"); - - b.Property("UpdateTime") - .HasColumnType("TEXT"); - - b.HasKey("Id"); - - b.ToTable("order", (string)null); - }); #pragma warning restore 612, 618 } } diff --git a/template/src/ABC.Template.Infrastructure/MigrationsAll/Sqlite-net9.0-admin/20260122054839_Init.Designer.cs b/template/src/ABC.Template.Infrastructure/MigrationsAll/Sqlite-net9.0-admin/20260122054839_Init.Designer.cs new file mode 100644 index 00000000..767ae286 --- /dev/null +++ b/template/src/ABC.Template.Infrastructure/MigrationsAll/Sqlite-net9.0-admin/20260122054839_Init.Designer.cs @@ -0,0 +1,431 @@ +// +using System; +using ABC.Template.Infrastructure; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace ABC.Template.Infrastructure.Migrations +{ + [DbContext(typeof(ApplicationDbContext))] + [Migration("20260122054839_Init")] + partial class Init + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder.HasAnnotation("ProductVersion", "9.0.0"); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.DeptAggregate.Dept", b => + { + b.Property("Id") + .HasColumnType("INTEGER"); + + b.Property("CreatedAt") + .HasColumnType("TEXT"); + + b.Property("DeletedAt") + .HasColumnType("TEXT"); + + b.Property("IsDeleted") + .HasColumnType("INTEGER"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("TEXT"); + + b.Property("ParentId") + .HasColumnType("INTEGER"); + + b.Property("Remark") + .IsRequired() + .HasMaxLength(500) + .HasColumnType("TEXT"); + + b.Property("Status") + .HasColumnType("INTEGER"); + + b.Property("UpdateTime") + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("IsDeleted"); + + b.HasIndex("ParentId"); + + b.HasIndex("Status"); + + b.ToTable("dept", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.Role", b => + { + b.Property("Id") + .HasColumnType("TEXT"); + + b.Property("CreatedAt") + .HasColumnType("TEXT"); + + b.Property("DeletedAt") + .HasColumnType("TEXT"); + + b.Property("Description") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("TEXT"); + + b.Property("IsActive") + .HasColumnType("INTEGER"); + + b.Property("IsDeleted") + .HasColumnType("INTEGER"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("Name") + .IsUnique(); + + b.ToTable("role", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.RolePermission", b => + { + b.Property("RoleId") + .HasColumnType("TEXT"); + + b.Property("PermissionCode") + .HasMaxLength(100) + .HasColumnType("TEXT"); + + b.Property("PermissionDescription") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("TEXT"); + + b.Property("PermissionName") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("TEXT"); + + b.HasKey("RoleId", "PermissionCode"); + + b.ToTable("role_permission", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.User", b => + { + b.Property("Id") + .HasColumnType("INTEGER"); + + b.Property("Age") + .HasColumnType("INTEGER"); + + b.Property("BirthDate") + .HasColumnType("TEXT"); + + b.Property("CreatedAt") + .HasColumnType("TEXT"); + + b.Property("DeletedAt") + .HasColumnType("TEXT"); + + b.Property("Email") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("TEXT"); + + b.Property("Gender") + .IsRequired() + .HasMaxLength(10) + .HasColumnType("TEXT"); + + b.Property("IsActive") + .HasColumnType("INTEGER"); + + b.Property("IsDeleted") + .HasColumnType("INTEGER"); + + b.Property("LastLoginTime") + .HasColumnType("TEXT"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("TEXT"); + + b.Property("PasswordHash") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("TEXT"); + + b.Property("Phone") + .IsRequired() + .HasMaxLength(20) + .HasColumnType("TEXT"); + + b.Property("RealName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("TEXT"); + + b.Property("Status") + .HasColumnType("INTEGER"); + + b.Property("UpdateTime") + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("Email"); + + b.HasIndex("Name"); + + b.ToTable("user", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserDept", b => + { + b.Property("UserId") + .HasColumnType("INTEGER"); + + b.Property("AssignedAt") + .HasColumnType("TEXT"); + + b.Property("DeptId") + .HasColumnType("INTEGER"); + + b.Property("DeptName") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("TEXT"); + + b.HasKey("UserId"); + + b.HasIndex("DeptId"); + + b.HasIndex("UserId"); + + b.ToTable("user_dept", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRefreshToken", b => + { + b.Property("Id") + .HasColumnType("INTEGER"); + + b.Property("CreatedTime") + .HasColumnType("TEXT"); + + b.Property("ExpiresTime") + .HasColumnType("TEXT"); + + b.Property("IsRevoked") + .HasColumnType("INTEGER"); + + b.Property("IsUsed") + .HasColumnType("INTEGER"); + + b.Property("Token") + .IsRequired() + .HasMaxLength(500) + .HasColumnType("TEXT"); + + b.Property("UserId") + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("user_refresh_token", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRole", b => + { + b.Property("UserId") + .HasColumnType("INTEGER"); + + b.Property("RoleId") + .HasColumnType("TEXT"); + + b.Property("RoleName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("TEXT"); + + b.HasKey("UserId", "RoleId"); + + b.ToTable("user_role", (string)null); + }); + + modelBuilder.Entity("NetCorePal.Extensions.DistributedTransactions.CAP.Persistence.CapLock", b => + { + b.Property("Key") + .HasMaxLength(128) + .HasColumnType("TEXT"); + + b.Property("Instance") + .HasMaxLength(256) + .HasColumnType("TEXT"); + + b.Property("LastLockTime") + .HasColumnType("TEXT"); + + b.HasKey("Key"); + + b.ToTable("CAPLock", (string)null); + }); + + modelBuilder.Entity("NetCorePal.Extensions.DistributedTransactions.CAP.Persistence.PublishedMessage", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Added") + .HasColumnType("TEXT"); + + b.Property("Content") + .HasColumnType("TEXT"); + + b.Property("ExpiresAt") + .HasColumnType("TEXT"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("TEXT"); + + b.Property("Retries") + .HasColumnType("INTEGER"); + + b.Property("StatusName") + .IsRequired() + .HasMaxLength(40) + .HasColumnType("TEXT"); + + b.Property("Version") + .HasMaxLength(20) + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex(new[] { "ExpiresAt", "StatusName" }, "IX_ExpiresAt_StatusName"); + + b.HasIndex(new[] { "Version", "ExpiresAt", "StatusName" }, "IX_Version_ExpiresAt_StatusName"); + + b.ToTable("CAPPublishedMessage", (string)null); + }); + + modelBuilder.Entity("NetCorePal.Extensions.DistributedTransactions.CAP.Persistence.ReceivedMessage", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Added") + .HasColumnType("TEXT"); + + b.Property("Content") + .HasColumnType("TEXT"); + + b.Property("ExpiresAt") + .HasColumnType("TEXT"); + + b.Property("Group") + .HasMaxLength(200) + .HasColumnType("TEXT"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(400) + .HasColumnType("TEXT"); + + b.Property("Retries") + .HasColumnType("INTEGER"); + + b.Property("StatusName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("TEXT"); + + b.Property("Version") + .HasMaxLength(20) + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex(new[] { "ExpiresAt", "StatusName" }, "IX_ExpiresAt_StatusName") + .HasDatabaseName("IX_ExpiresAt_StatusName1"); + + b.HasIndex(new[] { "Version", "ExpiresAt", "StatusName" }, "IX_Version_ExpiresAt_StatusName") + .HasDatabaseName("IX_Version_ExpiresAt_StatusName1"); + + b.ToTable("CAPReceivedMessage", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.RolePermission", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.RoleAggregate.Role", null) + .WithMany("Permissions") + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserDept", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.UserAggregate.User", null) + .WithOne("Dept") + .HasForeignKey("ABC.Template.Domain.AggregatesModel.UserAggregate.UserDept", "UserId") + .OnDelete(DeleteBehavior.ClientCascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRefreshToken", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.UserAggregate.User", null) + .WithMany("RefreshTokens") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRole", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.UserAggregate.User", null) + .WithMany("Roles") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.Role", b => + { + b.Navigation("Permissions"); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.User", b => + { + b.Navigation("Dept") + .IsRequired(); + + b.Navigation("RefreshTokens"); + + b.Navigation("Roles"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/template/src/ABC.Template.Infrastructure/MigrationsAll/Sqlite-net9.0-admin/20260122054839_Init.cs b/template/src/ABC.Template.Infrastructure/MigrationsAll/Sqlite-net9.0-admin/20260122054839_Init.cs new file mode 100644 index 00000000..aaab0e3f --- /dev/null +++ b/template/src/ABC.Template.Infrastructure/MigrationsAll/Sqlite-net9.0-admin/20260122054839_Init.cs @@ -0,0 +1,310 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace ABC.Template.Infrastructure.Migrations +{ + /// + public partial class Init : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "CAPLock", + columns: table => new + { + Key = table.Column(type: "TEXT", maxLength: 128, nullable: false), + Instance = table.Column(type: "TEXT", maxLength: 256, nullable: true), + LastLockTime = table.Column(type: "TEXT", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_CAPLock", x => x.Key); + }); + + migrationBuilder.CreateTable( + name: "CAPPublishedMessage", + columns: table => new + { + Id = table.Column(type: "INTEGER", nullable: false) + .Annotation("Sqlite:Autoincrement", true), + Version = table.Column(type: "TEXT", maxLength: 20, nullable: true), + Name = table.Column(type: "TEXT", maxLength: 200, nullable: false), + Content = table.Column(type: "TEXT", nullable: true), + Retries = table.Column(type: "INTEGER", nullable: true), + Added = table.Column(type: "TEXT", nullable: false), + ExpiresAt = table.Column(type: "TEXT", nullable: true), + StatusName = table.Column(type: "TEXT", maxLength: 40, nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_CAPPublishedMessage", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "CAPReceivedMessage", + columns: table => new + { + Id = table.Column(type: "INTEGER", nullable: false) + .Annotation("Sqlite:Autoincrement", true), + Version = table.Column(type: "TEXT", maxLength: 20, nullable: true), + Name = table.Column(type: "TEXT", maxLength: 400, nullable: false), + Group = table.Column(type: "TEXT", maxLength: 200, nullable: true), + Content = table.Column(type: "TEXT", nullable: true), + Retries = table.Column(type: "INTEGER", nullable: true), + Added = table.Column(type: "TEXT", nullable: false), + ExpiresAt = table.Column(type: "TEXT", nullable: true), + StatusName = table.Column(type: "TEXT", maxLength: 50, nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_CAPReceivedMessage", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "dept", + columns: table => new + { + Id = table.Column(type: "INTEGER", nullable: false), + Name = table.Column(type: "TEXT", maxLength: 100, nullable: false), + Remark = table.Column(type: "TEXT", maxLength: 500, nullable: false), + ParentId = table.Column(type: "INTEGER", nullable: false), + Status = table.Column(type: "INTEGER", nullable: false), + CreatedAt = table.Column(type: "TEXT", nullable: false), + IsDeleted = table.Column(type: "INTEGER", nullable: false), + DeletedAt = table.Column(type: "TEXT", nullable: false), + UpdateTime = table.Column(type: "TEXT", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_dept", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "role", + columns: table => new + { + Id = table.Column(type: "TEXT", nullable: false), + Name = table.Column(type: "TEXT", maxLength: 50, nullable: false), + Description = table.Column(type: "TEXT", maxLength: 200, nullable: false), + CreatedAt = table.Column(type: "TEXT", nullable: false), + IsActive = table.Column(type: "INTEGER", nullable: false), + IsDeleted = table.Column(type: "INTEGER", nullable: false), + DeletedAt = table.Column(type: "TEXT", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_role", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "user", + columns: table => new + { + Id = table.Column(type: "INTEGER", nullable: false), + Name = table.Column(type: "TEXT", maxLength: 50, nullable: false), + Email = table.Column(type: "TEXT", maxLength: 100, nullable: false), + Phone = table.Column(type: "TEXT", maxLength: 20, nullable: false), + RealName = table.Column(type: "TEXT", maxLength: 50, nullable: false), + Status = table.Column(type: "INTEGER", nullable: false), + PasswordHash = table.Column(type: "TEXT", maxLength: 255, nullable: false), + IsActive = table.Column(type: "INTEGER", nullable: false), + CreatedAt = table.Column(type: "TEXT", nullable: false), + LastLoginTime = table.Column(type: "TEXT", nullable: true), + UpdateTime = table.Column(type: "TEXT", nullable: false), + IsDeleted = table.Column(type: "INTEGER", nullable: false), + DeletedAt = table.Column(type: "TEXT", nullable: false), + Gender = table.Column(type: "TEXT", maxLength: 10, nullable: false), + Age = table.Column(type: "INTEGER", nullable: false), + BirthDate = table.Column(type: "TEXT", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_user", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "role_permission", + columns: table => new + { + RoleId = table.Column(type: "TEXT", nullable: false), + PermissionCode = table.Column(type: "TEXT", maxLength: 100, nullable: false), + PermissionName = table.Column(type: "TEXT", maxLength: 100, nullable: false), + PermissionDescription = table.Column(type: "TEXT", maxLength: 200, nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_role_permission", x => new { x.RoleId, x.PermissionCode }); + table.ForeignKey( + name: "FK_role_permission_role_RoleId", + column: x => x.RoleId, + principalTable: "role", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "user_dept", + columns: table => new + { + UserId = table.Column(type: "INTEGER", nullable: false), + DeptId = table.Column(type: "INTEGER", nullable: false), + DeptName = table.Column(type: "TEXT", maxLength: 100, nullable: false), + AssignedAt = table.Column(type: "TEXT", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_user_dept", x => x.UserId); + table.ForeignKey( + name: "FK_user_dept_user_UserId", + column: x => x.UserId, + principalTable: "user", + principalColumn: "Id"); + }); + + migrationBuilder.CreateTable( + name: "user_refresh_token", + columns: table => new + { + Id = table.Column(type: "INTEGER", nullable: false), + UserId = table.Column(type: "INTEGER", nullable: false), + Token = table.Column(type: "TEXT", maxLength: 500, nullable: false), + CreatedTime = table.Column(type: "TEXT", nullable: false), + ExpiresTime = table.Column(type: "TEXT", nullable: false), + IsUsed = table.Column(type: "INTEGER", nullable: false), + IsRevoked = table.Column(type: "INTEGER", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_user_refresh_token", x => x.Id); + table.ForeignKey( + name: "FK_user_refresh_token_user_UserId", + column: x => x.UserId, + principalTable: "user", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "user_role", + columns: table => new + { + UserId = table.Column(type: "INTEGER", nullable: false), + RoleId = table.Column(type: "TEXT", nullable: false), + RoleName = table.Column(type: "TEXT", maxLength: 50, nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_user_role", x => new { x.UserId, x.RoleId }); + table.ForeignKey( + name: "FK_user_role_user_UserId", + column: x => x.UserId, + principalTable: "user", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_ExpiresAt_StatusName", + table: "CAPPublishedMessage", + columns: new[] { "ExpiresAt", "StatusName" }); + + migrationBuilder.CreateIndex( + name: "IX_Version_ExpiresAt_StatusName", + table: "CAPPublishedMessage", + columns: new[] { "Version", "ExpiresAt", "StatusName" }); + + migrationBuilder.CreateIndex( + name: "IX_ExpiresAt_StatusName1", + table: "CAPReceivedMessage", + columns: new[] { "ExpiresAt", "StatusName" }); + + migrationBuilder.CreateIndex( + name: "IX_Version_ExpiresAt_StatusName1", + table: "CAPReceivedMessage", + columns: new[] { "Version", "ExpiresAt", "StatusName" }); + + migrationBuilder.CreateIndex( + name: "IX_dept_IsDeleted", + table: "dept", + column: "IsDeleted"); + + migrationBuilder.CreateIndex( + name: "IX_dept_ParentId", + table: "dept", + column: "ParentId"); + + migrationBuilder.CreateIndex( + name: "IX_dept_Status", + table: "dept", + column: "Status"); + + migrationBuilder.CreateIndex( + name: "IX_role_Name", + table: "role", + column: "Name", + unique: true); + + migrationBuilder.CreateIndex( + name: "IX_user_Email", + table: "user", + column: "Email"); + + migrationBuilder.CreateIndex( + name: "IX_user_Name", + table: "user", + column: "Name"); + + migrationBuilder.CreateIndex( + name: "IX_user_dept_DeptId", + table: "user_dept", + column: "DeptId"); + + migrationBuilder.CreateIndex( + name: "IX_user_dept_UserId", + table: "user_dept", + column: "UserId"); + + migrationBuilder.CreateIndex( + name: "IX_user_refresh_token_UserId", + table: "user_refresh_token", + column: "UserId"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "CAPLock"); + + migrationBuilder.DropTable( + name: "CAPPublishedMessage"); + + migrationBuilder.DropTable( + name: "CAPReceivedMessage"); + + migrationBuilder.DropTable( + name: "dept"); + + migrationBuilder.DropTable( + name: "role_permission"); + + migrationBuilder.DropTable( + name: "user_dept"); + + migrationBuilder.DropTable( + name: "user_refresh_token"); + + migrationBuilder.DropTable( + name: "user_role"); + + migrationBuilder.DropTable( + name: "role"); + + migrationBuilder.DropTable( + name: "user"); + } + } +} diff --git a/template/src/ABC.Template.Infrastructure/MigrationsAll/Sqlite-net9.0-admin/ApplicationDbContextModelSnapshot.cs b/template/src/ABC.Template.Infrastructure/MigrationsAll/Sqlite-net9.0-admin/ApplicationDbContextModelSnapshot.cs new file mode 100644 index 00000000..2560f52b --- /dev/null +++ b/template/src/ABC.Template.Infrastructure/MigrationsAll/Sqlite-net9.0-admin/ApplicationDbContextModelSnapshot.cs @@ -0,0 +1,428 @@ +// +using System; +using ABC.Template.Infrastructure; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace ABC.Template.Infrastructure.Migrations +{ + [DbContext(typeof(ApplicationDbContext))] + partial class ApplicationDbContextModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder.HasAnnotation("ProductVersion", "9.0.0"); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.DeptAggregate.Dept", b => + { + b.Property("Id") + .HasColumnType("INTEGER"); + + b.Property("CreatedAt") + .HasColumnType("TEXT"); + + b.Property("DeletedAt") + .HasColumnType("TEXT"); + + b.Property("IsDeleted") + .HasColumnType("INTEGER"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("TEXT"); + + b.Property("ParentId") + .HasColumnType("INTEGER"); + + b.Property("Remark") + .IsRequired() + .HasMaxLength(500) + .HasColumnType("TEXT"); + + b.Property("Status") + .HasColumnType("INTEGER"); + + b.Property("UpdateTime") + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("IsDeleted"); + + b.HasIndex("ParentId"); + + b.HasIndex("Status"); + + b.ToTable("dept", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.Role", b => + { + b.Property("Id") + .HasColumnType("TEXT"); + + b.Property("CreatedAt") + .HasColumnType("TEXT"); + + b.Property("DeletedAt") + .HasColumnType("TEXT"); + + b.Property("Description") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("TEXT"); + + b.Property("IsActive") + .HasColumnType("INTEGER"); + + b.Property("IsDeleted") + .HasColumnType("INTEGER"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("Name") + .IsUnique(); + + b.ToTable("role", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.RolePermission", b => + { + b.Property("RoleId") + .HasColumnType("TEXT"); + + b.Property("PermissionCode") + .HasMaxLength(100) + .HasColumnType("TEXT"); + + b.Property("PermissionDescription") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("TEXT"); + + b.Property("PermissionName") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("TEXT"); + + b.HasKey("RoleId", "PermissionCode"); + + b.ToTable("role_permission", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.User", b => + { + b.Property("Id") + .HasColumnType("INTEGER"); + + b.Property("Age") + .HasColumnType("INTEGER"); + + b.Property("BirthDate") + .HasColumnType("TEXT"); + + b.Property("CreatedAt") + .HasColumnType("TEXT"); + + b.Property("DeletedAt") + .HasColumnType("TEXT"); + + b.Property("Email") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("TEXT"); + + b.Property("Gender") + .IsRequired() + .HasMaxLength(10) + .HasColumnType("TEXT"); + + b.Property("IsActive") + .HasColumnType("INTEGER"); + + b.Property("IsDeleted") + .HasColumnType("INTEGER"); + + b.Property("LastLoginTime") + .HasColumnType("TEXT"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("TEXT"); + + b.Property("PasswordHash") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("TEXT"); + + b.Property("Phone") + .IsRequired() + .HasMaxLength(20) + .HasColumnType("TEXT"); + + b.Property("RealName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("TEXT"); + + b.Property("Status") + .HasColumnType("INTEGER"); + + b.Property("UpdateTime") + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("Email"); + + b.HasIndex("Name"); + + b.ToTable("user", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserDept", b => + { + b.Property("UserId") + .HasColumnType("INTEGER"); + + b.Property("AssignedAt") + .HasColumnType("TEXT"); + + b.Property("DeptId") + .HasColumnType("INTEGER"); + + b.Property("DeptName") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("TEXT"); + + b.HasKey("UserId"); + + b.HasIndex("DeptId"); + + b.HasIndex("UserId"); + + b.ToTable("user_dept", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRefreshToken", b => + { + b.Property("Id") + .HasColumnType("INTEGER"); + + b.Property("CreatedTime") + .HasColumnType("TEXT"); + + b.Property("ExpiresTime") + .HasColumnType("TEXT"); + + b.Property("IsRevoked") + .HasColumnType("INTEGER"); + + b.Property("IsUsed") + .HasColumnType("INTEGER"); + + b.Property("Token") + .IsRequired() + .HasMaxLength(500) + .HasColumnType("TEXT"); + + b.Property("UserId") + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("user_refresh_token", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRole", b => + { + b.Property("UserId") + .HasColumnType("INTEGER"); + + b.Property("RoleId") + .HasColumnType("TEXT"); + + b.Property("RoleName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("TEXT"); + + b.HasKey("UserId", "RoleId"); + + b.ToTable("user_role", (string)null); + }); + + modelBuilder.Entity("NetCorePal.Extensions.DistributedTransactions.CAP.Persistence.CapLock", b => + { + b.Property("Key") + .HasMaxLength(128) + .HasColumnType("TEXT"); + + b.Property("Instance") + .HasMaxLength(256) + .HasColumnType("TEXT"); + + b.Property("LastLockTime") + .HasColumnType("TEXT"); + + b.HasKey("Key"); + + b.ToTable("CAPLock", (string)null); + }); + + modelBuilder.Entity("NetCorePal.Extensions.DistributedTransactions.CAP.Persistence.PublishedMessage", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Added") + .HasColumnType("TEXT"); + + b.Property("Content") + .HasColumnType("TEXT"); + + b.Property("ExpiresAt") + .HasColumnType("TEXT"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("TEXT"); + + b.Property("Retries") + .HasColumnType("INTEGER"); + + b.Property("StatusName") + .IsRequired() + .HasMaxLength(40) + .HasColumnType("TEXT"); + + b.Property("Version") + .HasMaxLength(20) + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex(new[] { "ExpiresAt", "StatusName" }, "IX_ExpiresAt_StatusName"); + + b.HasIndex(new[] { "Version", "ExpiresAt", "StatusName" }, "IX_Version_ExpiresAt_StatusName"); + + b.ToTable("CAPPublishedMessage", (string)null); + }); + + modelBuilder.Entity("NetCorePal.Extensions.DistributedTransactions.CAP.Persistence.ReceivedMessage", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Added") + .HasColumnType("TEXT"); + + b.Property("Content") + .HasColumnType("TEXT"); + + b.Property("ExpiresAt") + .HasColumnType("TEXT"); + + b.Property("Group") + .HasMaxLength(200) + .HasColumnType("TEXT"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(400) + .HasColumnType("TEXT"); + + b.Property("Retries") + .HasColumnType("INTEGER"); + + b.Property("StatusName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("TEXT"); + + b.Property("Version") + .HasMaxLength(20) + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex(new[] { "ExpiresAt", "StatusName" }, "IX_ExpiresAt_StatusName") + .HasDatabaseName("IX_ExpiresAt_StatusName1"); + + b.HasIndex(new[] { "Version", "ExpiresAt", "StatusName" }, "IX_Version_ExpiresAt_StatusName") + .HasDatabaseName("IX_Version_ExpiresAt_StatusName1"); + + b.ToTable("CAPReceivedMessage", (string)null); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.RolePermission", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.RoleAggregate.Role", null) + .WithMany("Permissions") + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserDept", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.UserAggregate.User", null) + .WithOne("Dept") + .HasForeignKey("ABC.Template.Domain.AggregatesModel.UserAggregate.UserDept", "UserId") + .OnDelete(DeleteBehavior.ClientCascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRefreshToken", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.UserAggregate.User", null) + .WithMany("RefreshTokens") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.UserRole", b => + { + b.HasOne("ABC.Template.Domain.AggregatesModel.UserAggregate.User", null) + .WithMany("Roles") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.RoleAggregate.Role", b => + { + b.Navigation("Permissions"); + }); + + modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.UserAggregate.User", b => + { + b.Navigation("Dept") + .IsRequired(); + + b.Navigation("RefreshTokens"); + + b.Navigation("Roles"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/template/src/ABC.Template.Infrastructure/MigrationsAll/Sqlite-net10.0/20251225065139_Init.Designer.cs b/template/src/ABC.Template.Infrastructure/MigrationsAll/Sqlite-net9.0/20260122054830_Init.Designer.cs similarity index 76% rename from template/src/ABC.Template.Infrastructure/MigrationsAll/Sqlite-net10.0/20251225065139_Init.Designer.cs rename to template/src/ABC.Template.Infrastructure/MigrationsAll/Sqlite-net9.0/20260122054830_Init.Designer.cs index 366c6c08..5d63c8c4 100644 --- a/template/src/ABC.Template.Infrastructure/MigrationsAll/Sqlite-net10.0/20251225065139_Init.Designer.cs +++ b/template/src/ABC.Template.Infrastructure/MigrationsAll/Sqlite-net9.0/20260122054830_Init.Designer.cs @@ -1,17 +1,17 @@ // using System; +using ABC.Template.Infrastructure; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using ABC.Template.Infrastructure; #nullable disable namespace ABC.Template.Infrastructure.Migrations { [DbContext(typeof(ApplicationDbContext))] - [Migration("20251225065139_Init")] + [Migration("20260122054830_Init")] partial class Init { /// @@ -125,47 +125,6 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.ToTable("CAPReceivedMessage", (string)null); }); - - modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.DeliverAggregate.DeliverRecord", b => - { - b.Property("Id") - .HasColumnType("TEXT"); - - b.Property("OrderId") - .HasColumnType("TEXT"); - - b.HasKey("Id"); - - b.ToTable("deliverrecord", (string)null); - }); - - modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.OrderAggregate.Order", b => - { - b.Property("Id") - .HasColumnType("TEXT"); - - b.Property("Count") - .HasColumnType("INTEGER"); - - b.Property("Name") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("TEXT"); - - b.Property("Paid") - .HasColumnType("INTEGER"); - - b.Property("RowVersion") - .IsConcurrencyToken() - .HasColumnType("INTEGER"); - - b.Property("UpdateTime") - .HasColumnType("TEXT"); - - b.HasKey("Id"); - - b.ToTable("order", (string)null); - }); #pragma warning restore 612, 618 } } diff --git a/template/src/ABC.Template.Infrastructure/MigrationsAll/Sqlite-net10.0/20251225065139_Init.cs b/template/src/ABC.Template.Infrastructure/MigrationsAll/Sqlite-net9.0/20260122054830_Init.cs similarity index 75% rename from template/src/ABC.Template.Infrastructure/MigrationsAll/Sqlite-net10.0/20251225065139_Init.cs rename to template/src/ABC.Template.Infrastructure/MigrationsAll/Sqlite-net9.0/20260122054830_Init.cs index cbe4a168..b3cf0f21 100644 --- a/template/src/ABC.Template.Infrastructure/MigrationsAll/Sqlite-net10.0/20251225065139_Init.cs +++ b/template/src/ABC.Template.Infrastructure/MigrationsAll/Sqlite-net9.0/20260122054830_Init.cs @@ -63,34 +63,6 @@ protected override void Up(MigrationBuilder migrationBuilder) table.PrimaryKey("PK_CAPReceivedMessage", x => x.Id); }); - migrationBuilder.CreateTable( - name: "deliverrecord", - columns: table => new - { - Id = table.Column(type: "TEXT", nullable: false), - OrderId = table.Column(type: "TEXT", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_deliverrecord", x => x.Id); - }); - - migrationBuilder.CreateTable( - name: "order", - columns: table => new - { - Id = table.Column(type: "TEXT", nullable: false), - Paid = table.Column(type: "INTEGER", nullable: false), - Name = table.Column(type: "TEXT", maxLength: 100, nullable: false), - Count = table.Column(type: "INTEGER", nullable: false), - RowVersion = table.Column(type: "INTEGER", nullable: false), - UpdateTime = table.Column(type: "TEXT", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_order", x => x.Id); - }); - migrationBuilder.CreateIndex( name: "IX_ExpiresAt_StatusName", table: "CAPPublishedMessage", @@ -123,12 +95,6 @@ protected override void Down(MigrationBuilder migrationBuilder) migrationBuilder.DropTable( name: "CAPReceivedMessage"); - - migrationBuilder.DropTable( - name: "deliverrecord"); - - migrationBuilder.DropTable( - name: "order"); } } } diff --git a/template/src/ABC.Template.Infrastructure/MigrationsAll/Sqlite-net9.0/ApplicationDbContextModelSnapshot.cs b/template/src/ABC.Template.Infrastructure/MigrationsAll/Sqlite-net9.0/ApplicationDbContextModelSnapshot.cs index 40255e29..5e0abc7a 100644 --- a/template/src/ABC.Template.Infrastructure/MigrationsAll/Sqlite-net9.0/ApplicationDbContextModelSnapshot.cs +++ b/template/src/ABC.Template.Infrastructure/MigrationsAll/Sqlite-net9.0/ApplicationDbContextModelSnapshot.cs @@ -1,9 +1,9 @@ // using System; +using ABC.Template.Infrastructure; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using ABC.Template.Infrastructure; #nullable disable @@ -122,47 +122,6 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.ToTable("CAPReceivedMessage", (string)null); }); - - modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.DeliverAggregate.DeliverRecord", b => - { - b.Property("Id") - .HasColumnType("TEXT"); - - b.Property("OrderId") - .HasColumnType("TEXT"); - - b.HasKey("Id"); - - b.ToTable("deliverrecord", (string)null); - }); - - modelBuilder.Entity("ABC.Template.Domain.AggregatesModel.OrderAggregate.Order", b => - { - b.Property("Id") - .HasColumnType("TEXT"); - - b.Property("Count") - .HasColumnType("INTEGER"); - - b.Property("Name") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("TEXT"); - - b.Property("Paid") - .HasColumnType("INTEGER"); - - b.Property("RowVersion") - .IsConcurrencyToken() - .HasColumnType("INTEGER"); - - b.Property("UpdateTime") - .HasColumnType("TEXT"); - - b.HasKey("Id"); - - b.ToTable("order", (string)null); - }); #pragma warning restore 612, 618 } } diff --git a/template/src/ABC.Template.Infrastructure/Repositories/DeliverRecordRepository.cs b/template/src/ABC.Template.Infrastructure/Repositories/DeliverRecordRepository.cs deleted file mode 100644 index cec24061..00000000 --- a/template/src/ABC.Template.Infrastructure/Repositories/DeliverRecordRepository.cs +++ /dev/null @@ -1,12 +0,0 @@ -using ABC.Template.Domain.AggregatesModel.DeliverAggregate; - -namespace ABC.Template.Infrastructure.Repositories; - -public interface IDeliverRecordRepository : IRepository -{ -} - -public class DeliverRecordRepository(ApplicationDbContext context) : RepositoryBase(context), IDeliverRecordRepository -{ -} - diff --git a/template/src/ABC.Template.Infrastructure/Repositories/DeptRepository.cs b/template/src/ABC.Template.Infrastructure/Repositories/DeptRepository.cs new file mode 100644 index 00000000..8510f3d1 --- /dev/null +++ b/template/src/ABC.Template.Infrastructure/Repositories/DeptRepository.cs @@ -0,0 +1,32 @@ +using ABC.Template.Domain.AggregatesModel.DeptAggregate; +//#if (UseMongoDB) +using Microsoft.EntityFrameworkCore; +//#endif + +namespace ABC.Template.Infrastructure.Repositories; + +/// +/// 部门仓储接口 +/// +public interface IDeptRepository : IRepository { } + +/// +/// 部门仓储实现 +/// +//#if (UseMongoDB) +/// MongoDB EF Core 不支持 EF.Property,重写 GetAsync 使用直接属性访问 +public class DeptRepository(ApplicationDbContext context) : RepositoryBase(context), IDeptRepository +{ + /// + /// 根据ID获取部门实体 + /// MongoDB EF Core 不支持 EF.Property,使用直接属性访问 d.Id == id + /// + public override async Task GetAsync(DeptId id, CancellationToken cancellationToken = default) + { + return await DbContext.Depts + .FirstOrDefaultAsync(d => d.Id == id, cancellationToken); + } +} +//#else +public class DeptRepository(ApplicationDbContext context) : RepositoryBase(context), IDeptRepository { } +//#endif \ No newline at end of file diff --git a/template/src/ABC.Template.Infrastructure/Repositories/OrderRepository.cs b/template/src/ABC.Template.Infrastructure/Repositories/OrderRepository.cs deleted file mode 100644 index 4d47a938..00000000 --- a/template/src/ABC.Template.Infrastructure/Repositories/OrderRepository.cs +++ /dev/null @@ -1,14 +0,0 @@ -using NetCorePal.Extensions.Repository.EntityFrameworkCore; -using ABC.Template.Domain.AggregatesModel.OrderAggregate; -using NetCorePal.Extensions.Repository; - -namespace ABC.Template.Infrastructure.Repositories; - -public interface IOrderRepository : IRepository -{ -} - -public class OrderRepository(ApplicationDbContext context) : RepositoryBase(context), IOrderRepository -{ -} - diff --git a/template/src/ABC.Template.Infrastructure/Repositories/RoleRepository.cs b/template/src/ABC.Template.Infrastructure/Repositories/RoleRepository.cs new file mode 100644 index 00000000..d8375e1a --- /dev/null +++ b/template/src/ABC.Template.Infrastructure/Repositories/RoleRepository.cs @@ -0,0 +1,30 @@ +using ABC.Template.Domain.AggregatesModel.RoleAggregate; +//#if (UseMongoDB) +using Microsoft.EntityFrameworkCore; +//#endif + +namespace ABC.Template.Infrastructure.Repositories; + +public interface IRoleRepository : IRepository { } + +//#if (UseMongoDB) +/// +/// 角色仓储实现 +/// MongoDB EF Core 不支持 EF.Property,重写 GetAsync 使用直接属性访问 +/// +public class RoleRepository(ApplicationDbContext context) : RepositoryBase(context), IRoleRepository +{ + /// + /// 根据ID获取角色实体 + /// MongoDB EF Core 不支持 EF.Property,使用直接属性访问 r.Id == id + /// + public override async Task GetAsync(RoleId id, CancellationToken cancellationToken = default) + { + return await DbContext.Roles + .IgnoreAutoIncludes() + .FirstOrDefaultAsync(r => r.Id == id, cancellationToken); + } +} +//#else +public class RoleRepository(ApplicationDbContext context) : RepositoryBase(context), IRoleRepository { } +//#endif \ No newline at end of file diff --git a/template/src/ABC.Template.Infrastructure/Repositories/UserRepository.cs b/template/src/ABC.Template.Infrastructure/Repositories/UserRepository.cs new file mode 100644 index 00000000..0d199a2c --- /dev/null +++ b/template/src/ABC.Template.Infrastructure/Repositories/UserRepository.cs @@ -0,0 +1,30 @@ +using ABC.Template.Domain.AggregatesModel.UserAggregate; +//#if (UseMongoDB) +using Microsoft.EntityFrameworkCore; +//#endif + +namespace ABC.Template.Infrastructure.Repositories; + +public interface IUserRepository : IRepository { } + +//#if (UseMongoDB) +/// +/// 用户仓储实现 +/// MongoDB EF Core 不支持 EF.Property,重写 GetAsync 使用直接属性访问 +/// +public class UserRepository(ApplicationDbContext context) : RepositoryBase(context), IUserRepository +{ + /// + /// 根据ID获取用户实体 + /// MongoDB EF Core 不支持 EF.Property,使用直接属性访问 u.Id == id + /// + public override async Task GetAsync(UserId id, CancellationToken cancellationToken = default) + { + return await DbContext.Users + .IgnoreAutoIncludes() + .FirstOrDefaultAsync(u => u.Id == id, cancellationToken); + } +} +//#else +public class UserRepository(ApplicationDbContext context) : RepositoryBase(context), IUserRepository { } +//#endif \ No newline at end of file diff --git a/template/src/ABC.Template.Web/AppPermissions/AppPermission.cs b/template/src/ABC.Template.Web/AppPermissions/AppPermission.cs new file mode 100644 index 00000000..2ecce2af --- /dev/null +++ b/template/src/ABC.Template.Web/AppPermissions/AppPermission.cs @@ -0,0 +1,73 @@ +using System.Collections.Immutable; + +namespace ABC.Template.Web.AppPermissions; + +/// +/// 表示一个权限对象,包含权限的基本信息及子权限 +/// +public sealed class AppPermission +{ + /// + /// 权限的唯一名称(代码) + /// + public string Code { get; } + + /// + /// 权限的显示名称 + /// + public string DisplayName { get; } + + /// + /// 当前权限的所有子权限 + /// 子权限是只读的 + /// + public IReadOnlyList Children => _children.ToImmutableList(); + + private readonly List _children; + + /// + /// 指示当前权限是否启用 + /// 默认情况下权限是启用的 + /// 禁用的权限无法被授予,但仍然可以检查其值(始终为 false) + /// 禁用权限可以用来隐藏相关的应用功能 + /// 默认值:true(启用) + /// + public bool IsEnabled { get; } + + /// + /// 创建一个新的权限对象。 + /// + /// 权限的唯一代码。 + /// 权限的显示名称。 + /// 是否启用此权限,默认为 true。 + internal AppPermission( + string code, + string displayName, + bool isEnabled = true) + { + ArgumentException.ThrowIfNullOrWhiteSpace(code); + ArgumentException.ThrowIfNullOrWhiteSpace(displayName); + + Code = code; + DisplayName = displayName; + IsEnabled = isEnabled; + _children = []; + } + + /// + /// 向当前权限添加一个子权限。 + /// + /// 子权限的唯一代码。 + /// 子权限的显示名称。 + /// 子权限是否启用,默认为 true。 + /// 返回创建的子权限对象。 + public AppPermission AddChild(string code, string displayName, bool isEnabled = true) + { + var child = new AppPermission(code, displayName, isEnabled); + + _children.Add(child); + + return child; + } +} + diff --git a/template/src/ABC.Template.Web/AppPermissions/AppPermissionGroup.cs b/template/src/ABC.Template.Web/AppPermissions/AppPermissionGroup.cs new file mode 100644 index 00000000..2f7adc85 --- /dev/null +++ b/template/src/ABC.Template.Web/AppPermissions/AppPermissionGroup.cs @@ -0,0 +1,46 @@ +using System.Collections.Immutable; + +namespace ABC.Template.Web.AppPermissions; + +/// +/// 表示一个权限组,包含该组的所有权限以及相关操作。 +/// +public sealed class AppPermissionGroup +{ + /// + /// 权限组的唯一名称。 + /// + public string Name { get; } + + /// + /// 权限组内的所有权限,权限是只读的。 + /// + public IReadOnlyList Permissions => _permissions.ToImmutableList(); + + private readonly List _permissions = []; + + /// + /// 创建一个新的权限组。 + /// + /// 权限组的名称。 + internal AppPermissionGroup(string name) + { + // 初始化权限组的名称和权限集合 + Name = name; + } + + /// + /// 向权限组中添加一个权限。 + /// + /// 权限的唯一代码。 + /// 权限的名称。 + /// 是否启用该权限,默认为 true。 + /// 返回创建的权限对象。 + public AppPermission AddPermission(string code, string name, bool isEnabled = true) + { + var permission = new AppPermission(code, name, isEnabled); + _permissions.Add(permission); // 将权限添加到权限组中 + return permission; + } +} + diff --git a/template/src/ABC.Template.Web/AppPermissions/PermissionCodes.cs b/template/src/ABC.Template.Web/AppPermissions/PermissionCodes.cs new file mode 100644 index 00000000..f9a20621 --- /dev/null +++ b/template/src/ABC.Template.Web/AppPermissions/PermissionCodes.cs @@ -0,0 +1,39 @@ +namespace ABC.Template.Web.AppPermissions; + +/// +/// 权限常量定义 +/// +public static class PermissionCodes +{ + #region 角色管理权限 + public const string RoleManagement = nameof(RoleManagement); + public const string RoleCreate = nameof(RoleCreate); + public const string RoleEdit = nameof(RoleEdit); + public const string RoleDelete = nameof(RoleDelete); + public const string RoleView = nameof(RoleView); + public const string RoleUpdatePermissions = nameof(RoleUpdatePermissions); + #endregion + + #region 用户管理权限 + public const string UserManagement = nameof(UserManagement); + public const string UserCreate = nameof(UserCreate); + public const string UserEdit = nameof(UserEdit); + public const string UserDelete = nameof(UserDelete); + public const string UserView = nameof(UserView); + public const string UserRoleAssign = nameof(UserRoleAssign); + public const string UserResetPassword = nameof(UserResetPassword); + #endregion + + #region 部门管理权限 + public const string DeptManagement = nameof(DeptManagement); + public const string DeptCreate = nameof(DeptCreate); + public const string DeptEdit = nameof(DeptEdit); + public const string DeptDelete = nameof(DeptDelete); + public const string DeptView = nameof(DeptView); + #endregion + + #region 所有接口访问权限 + public const string AllApiAccess = nameof(AllApiAccess); + #endregion +} + diff --git a/template/src/ABC.Template.Web/AppPermissions/PermissionDefinitionContext.cs b/template/src/ABC.Template.Web/AppPermissions/PermissionDefinitionContext.cs new file mode 100644 index 00000000..b24de8f2 --- /dev/null +++ b/template/src/ABC.Template.Web/AppPermissions/PermissionDefinitionContext.cs @@ -0,0 +1,69 @@ +using System.Collections.Immutable; + +namespace ABC.Template.Web.AppPermissions; + +/// +/// 管理权限定义的上下文类,负责初始化和提供权限组及其权限项。 +/// +public static class PermissionDefinitionContext +{ + // 存储权限组的字典,键为权限组名称,值为权限组对象 + private static Dictionary Groups { get; } = new(); + + // 静态构造函数,在类初始化时创建默认的权限组和权限项 + static PermissionDefinitionContext() + { + var systemAccess = AddGroup("SystemAccess"); + + // 用户管理权限 + var adminUserManagement = systemAccess.AddPermission(PermissionCodes.UserManagement, "用户管理"); + adminUserManagement.AddChild(PermissionCodes.UserCreate, "创建用户"); + adminUserManagement.AddChild(PermissionCodes.UserEdit, "编辑用户"); + adminUserManagement.AddChild(PermissionCodes.UserDelete, "删除用户"); + adminUserManagement.AddChild(PermissionCodes.UserView, "查看用户"); + adminUserManagement.AddChild(PermissionCodes.UserRoleAssign, "分配用户角色"); + adminUserManagement.AddChild(PermissionCodes.UserResetPassword, "重置用户密码"); + + // 角色管理权限 + var roleManagement = systemAccess.AddPermission(PermissionCodes.RoleManagement, "角色管理"); + roleManagement.AddChild(PermissionCodes.RoleCreate, "创建角色"); + roleManagement.AddChild(PermissionCodes.RoleEdit, "编辑角色"); + roleManagement.AddChild(PermissionCodes.RoleDelete, "删除角色"); + roleManagement.AddChild(PermissionCodes.RoleView, "查看角色"); + roleManagement.AddChild(PermissionCodes.RoleUpdatePermissions, "更新角色权限"); + + // 部门管理权限 + var deptManagement = systemAccess.AddPermission(PermissionCodes.DeptManagement, "部门管理"); + deptManagement.AddChild(PermissionCodes.DeptCreate, "创建部门"); + deptManagement.AddChild(PermissionCodes.DeptEdit, "编辑部门"); + deptManagement.AddChild(PermissionCodes.DeptDelete, "删除部门"); + deptManagement.AddChild(PermissionCodes.DeptView, "查看部门"); + + // 所有接口访问权限 + var allApiAccess = systemAccess.AddPermission(PermissionCodes.AllApiAccess, "所有接口访问权限"); + } + + /// + /// 添加一个新的权限组,如果权限组名称已存在则抛出异常。 + /// + /// 权限组名称 + /// 返回创建的权限组 + /// 如果权限组名称已经存在,则抛出异常 + private static AppPermissionGroup AddGroup(string name) + { + ArgumentException.ThrowIfNullOrWhiteSpace(name); + + if (Groups.ContainsKey(name)) + { + throw new ArgumentException($"There is already an existing permission group with name: {name}"); + } + + return Groups[name] = new AppPermissionGroup(name); + } + + /// + /// 获取所有的权限组。 + /// + public static IReadOnlyList PermissionGroups => Groups.Values.ToImmutableList(); +} + diff --git a/template/src/ABC.Template.Web/AppPermissions/PermissionMapper.cs b/template/src/ABC.Template.Web/AppPermissions/PermissionMapper.cs new file mode 100644 index 00000000..06b189f0 --- /dev/null +++ b/template/src/ABC.Template.Web/AppPermissions/PermissionMapper.cs @@ -0,0 +1,119 @@ +namespace ABC.Template.Web.AppPermissions; + +/// +/// 权限映射辅助类,用于通过权限代码自动获取权限名称和描述 +/// +public static class PermissionMapper +{ + /// + /// 权限代码到权限描述的映射字典 + /// 从 SeedDatabaseExtension.cs 中提取 + /// + private static readonly Dictionary _permissionDescriptionMap = new() + { + // 父权限码(用于菜单和路由权限控制) + { PermissionCodes.UserManagement, "用户管理" }, + { PermissionCodes.RoleManagement, "角色管理" }, + { PermissionCodes.DeptManagement, "部门管理" }, + + // 用户管理权限 + { PermissionCodes.UserCreate, "创建新用户" }, + { PermissionCodes.UserView, "查看用户信息" }, + { PermissionCodes.UserEdit, "更新用户信息" }, + { PermissionCodes.UserDelete, "删除用户" }, + { PermissionCodes.UserRoleAssign, "分配用户角色权限" }, + { PermissionCodes.UserResetPassword, "重置用户密码" }, + + // 角色管理权限 + { PermissionCodes.RoleCreate, "创建新角色" }, + { PermissionCodes.RoleView, "查看角色信息" }, + { PermissionCodes.RoleEdit, "更新角色信息" }, + { PermissionCodes.RoleDelete, "删除角色" }, + { PermissionCodes.RoleUpdatePermissions, "更新角色的权限" }, + + // 部门管理权限 + { PermissionCodes.DeptCreate, "创建部门" }, + { PermissionCodes.DeptView, "查看部门信息" }, + { PermissionCodes.DeptEdit, "更新部门信息" }, + { PermissionCodes.DeptDelete, "删除部门" }, + + // 所有接口访问权限 + { PermissionCodes.AllApiAccess, "所有接口访问权限" }, + }; + + /// + /// 通过权限代码获取权限信息(名称和描述) + /// + /// 权限代码 + /// 返回 (权限名称, 权限描述) 元组 + public static (string Name, string Description) GetPermissionInfo(string permissionCode) + { + ArgumentException.ThrowIfNullOrWhiteSpace(permissionCode); + + // 优先从 PermissionDefinitionContext 获取权限名称(DisplayName) + var permissionName = GetPermissionNameFromContext(permissionCode); + + // 如果 PermissionDefinitionContext 中没有找到,使用权限代码作为名称 + if (string.IsNullOrEmpty(permissionName)) + { + permissionName = permissionCode; + } + + // 从映射字典获取权限描述 + var permissionDescription = _permissionDescriptionMap.TryGetValue(permissionCode, out var description) + ? description + : string.Empty; + + return (permissionName, permissionDescription); + } + + /// + /// 从 PermissionDefinitionContext 中查找权限的 DisplayName + /// + /// 权限代码 + /// 权限的显示名称,如果未找到则返回 null + private static string? GetPermissionNameFromContext(string permissionCode) + { + foreach (var group in PermissionDefinitionContext.PermissionGroups) + { + // 在权限组的所有权限及其子权限中查找 + foreach (var permission in group.Permissions) + { + var found = FindPermissionRecursive(permission, permissionCode); + if (found != null) + { + return found.DisplayName; + } + } + } + + return null; + } + + /// + /// 递归查找权限 + /// + /// 当前权限 + /// 要查找的权限代码 + /// 找到的权限对象,如果未找到则返回 null + private static AppPermission? FindPermissionRecursive(AppPermission permission, string permissionCode) + { + // 检查当前权限是否匹配 + if (permission.Code == permissionCode) + { + return permission; + } + + // 递归查找子权限 + foreach (var child in permission.Children) + { + var found = FindPermissionRecursive(child, permissionCode); + if (found != null) + { + return found; + } + } + + return null; + } +} diff --git a/template/src/ABC.Template.Web/Application/Commands/Delivers/DeliverGoodsCommand.cs b/template/src/ABC.Template.Web/Application/Commands/Delivers/DeliverGoodsCommand.cs deleted file mode 100644 index faf96ad4..00000000 --- a/template/src/ABC.Template.Web/Application/Commands/Delivers/DeliverGoodsCommand.cs +++ /dev/null @@ -1,19 +0,0 @@ -using ABC.Template.Domain.AggregatesModel.DeliverAggregate; -using ABC.Template.Domain.AggregatesModel.OrderAggregate; -using ABC.Template.Infrastructure.Repositories; -using NetCorePal.Extensions.Primitives; - -namespace ABC.Template.Web.Application.Commands.Delivers; - -public record DeliverGoodsCommand(OrderId OrderId) : ICommand; - -public class DeliverGoodsCommandHandler(IDeliverRecordRepository deliverRecordRepository) - : ICommandHandler -{ - public Task Handle(DeliverGoodsCommand request, CancellationToken cancellationToken) - { - var record = new DeliverRecord(request.OrderId); - deliverRecordRepository.Add(record); - return Task.FromResult(record.Id); - } -} \ No newline at end of file diff --git a/template/src/ABC.Template.Web/Application/Commands/Demos/ValidatorCommand.cs b/template/src/ABC.Template.Web/Application/Commands/Demos/ValidatorCommand.cs deleted file mode 100644 index 553ea07e..00000000 --- a/template/src/ABC.Template.Web/Application/Commands/Demos/ValidatorCommand.cs +++ /dev/null @@ -1,23 +0,0 @@ -using FluentValidation; -using NetCorePal.Extensions.Domain; - -namespace ABC.Template.Web.Application.Commands.Demos; - -public record ValidatorCommand(string Name, int Price) : ICommand; - -public class ValidatorCommandValidator : AbstractValidator -{ - public ValidatorCommandValidator() - { - RuleFor(x => x.Name).NotEmpty().WithMessage("不能为空").WithErrorCode("code1"); - RuleFor(x => x.Price).InclusiveBetween(18, 60).WithMessage("价格必须在18-60之间").WithErrorCode("code2"); - } -} - -public class ValidatorCommandHandler : ICommandHandler -{ - public Task Handle(ValidatorCommand request, CancellationToken cancellationToken) - { - return Task.CompletedTask; - } -} \ No newline at end of file diff --git a/template/src/ABC.Template.Web/Application/Commands/Identity/Admin/DeptCommands/CreateDeptCommand.cs b/template/src/ABC.Template.Web/Application/Commands/Identity/Admin/DeptCommands/CreateDeptCommand.cs new file mode 100644 index 00000000..35c7efc2 --- /dev/null +++ b/template/src/ABC.Template.Web/Application/Commands/Identity/Admin/DeptCommands/CreateDeptCommand.cs @@ -0,0 +1,38 @@ +using FluentValidation; +using ABC.Template.Domain.AggregatesModel.DeptAggregate; +using ABC.Template.Infrastructure.Repositories; +using ABC.Template.Web.Application.Queries; + +namespace ABC.Template.Web.Application.Commands.Identity.Admin.DeptCommands; + +/// +/// 创建部门命令 +/// +public record CreateDeptCommand(string Name, string Remark, DeptId? ParentId, int Status) : ICommand; + +public class CreateDeptCommandValidator : AbstractValidator +{ + public CreateDeptCommandValidator(DeptQuery deptQuery) + { + RuleFor(d => d.Name).NotEmpty().WithMessage("部门名称不能为空"); + RuleFor(d => d.Name).MustAsync(async (n, ct) => !await deptQuery.DoesDeptExist(n, ct)) + .WithMessage(d => $"该部门已存在,Name={d.Name}"); + RuleFor(d => d.Status).InclusiveBetween(0, 1).WithMessage("状态值必须为0或1"); + } +} + +/// +/// 创建部门命令处理器 +/// +public class CreateDeptCommandHandler(IDeptRepository deptRepository) : ICommandHandler +{ + public async Task Handle(CreateDeptCommand request, CancellationToken cancellationToken) + { + var parentId = request.ParentId ?? new DeptId(0); + var dept = new Dept(request.Name, request.Remark, parentId, request.Status); + + await deptRepository.AddAsync(dept, cancellationToken); + + return dept.Id; + } +} diff --git a/template/src/ABC.Template.Web/Application/Commands/Identity/Admin/DeptCommands/DeleteDeptCommand.cs b/template/src/ABC.Template.Web/Application/Commands/Identity/Admin/DeptCommands/DeleteDeptCommand.cs new file mode 100644 index 00000000..83517ead --- /dev/null +++ b/template/src/ABC.Template.Web/Application/Commands/Identity/Admin/DeptCommands/DeleteDeptCommand.cs @@ -0,0 +1,35 @@ +using Microsoft.EntityFrameworkCore; +using ABC.Template.Domain.AggregatesModel.DeptAggregate; +using ABC.Template.Infrastructure; +using ABC.Template.Infrastructure.Repositories; +using ABC.Template.Domain; + +namespace ABC.Template.Web.Application.Commands.Identity.Admin.DeptCommands; + +/// +/// 删除部门命令 +/// +public record DeleteDeptCommand(DeptId Id) : ICommand; + +/// +/// 删除部门命令处理器 +/// +public class DeleteDeptCommandHandler(IDeptRepository deptRepository, ApplicationDbContext dbContext) : ICommandHandler +{ + public async Task Handle(DeleteDeptCommand request, CancellationToken cancellationToken) + { + var dept = await deptRepository.GetAsync(request.Id, cancellationToken) + ?? throw new KnownException($"未找到部门,Id = {request.Id}", ErrorCodes.DeptNotFound); + + // 检查是否有子部门 + var hasChildren = await dbContext.Depts + .AnyAsync(d => d.ParentId == request.Id && !d.IsDeleted, cancellationToken); + + if (hasChildren) + { + throw new KnownException("该部门下存在子部门,无法删除", ErrorCodes.DeptHasChildrenCannotDelete); + } + + dept.SoftDelete(); + } +} diff --git a/template/src/ABC.Template.Web/Application/Commands/Identity/Admin/DeptCommands/UpdateDeptCommand.cs b/template/src/ABC.Template.Web/Application/Commands/Identity/Admin/DeptCommands/UpdateDeptCommand.cs new file mode 100644 index 00000000..cb1f1ff1 --- /dev/null +++ b/template/src/ABC.Template.Web/Application/Commands/Identity/Admin/DeptCommands/UpdateDeptCommand.cs @@ -0,0 +1,34 @@ +using FluentValidation; +using ABC.Template.Domain.AggregatesModel.DeptAggregate; +using ABC.Template.Infrastructure.Repositories; +using ABC.Template.Domain; + +namespace ABC.Template.Web.Application.Commands.Identity.Admin.DeptCommands; + +/// +/// 更新部门命令 +/// +public record UpdateDeptCommand(DeptId Id, string Name, string Remark, DeptId ParentId, int Status) : ICommand; + +public class UpdateDeptCommandValidator : AbstractValidator +{ + public UpdateDeptCommandValidator() + { + RuleFor(d => d.Name).NotEmpty().WithMessage("部门名称不能为空"); + RuleFor(d => d.Status).InclusiveBetween(0, 1).WithMessage("状态值必须为0或1"); + } +} + +/// +/// 更新部门命令处理器 +/// +public class UpdateDeptCommandHandler(IDeptRepository deptRepository) : ICommandHandler +{ + public async Task Handle(UpdateDeptCommand request, CancellationToken cancellationToken) + { + var dept = await deptRepository.GetAsync(request.Id, cancellationToken) + ?? throw new KnownException($"未找到部门,Id = {request.Id}", ErrorCodes.DeptNotFound); + + dept.UpdateInfo(request.Name, request.Remark, request.ParentId, request.Status); + } +} diff --git a/template/src/ABC.Template.Web/Application/Commands/Identity/Admin/RoleCommands/ActivateRoleCommand.cs b/template/src/ABC.Template.Web/Application/Commands/Identity/Admin/RoleCommands/ActivateRoleCommand.cs new file mode 100644 index 00000000..38e60eff --- /dev/null +++ b/template/src/ABC.Template.Web/Application/Commands/Identity/Admin/RoleCommands/ActivateRoleCommand.cs @@ -0,0 +1,36 @@ +using FluentValidation; +using ABC.Template.Domain.AggregatesModel.RoleAggregate; +using ABC.Template.Infrastructure.Repositories; +using ABC.Template.Domain; + +namespace ABC.Template.Web.Application.Commands.Identity.Admin.RoleCommands; + +/// +/// 激活角色命令 +/// +/// 角色ID +public record ActivateRoleCommand(RoleId RoleId) : ICommand; + +/// +/// 激活角色命令验证器 +/// +public class ActivateRoleCommandValidator : AbstractValidator +{ + public ActivateRoleCommandValidator() + { + RuleFor(x => x.RoleId).NotEmpty(); + } +} + +/// +/// 激活角色命令处理器 +/// +public class ActivateRoleCommandHandler(IRoleRepository roleRepository) : ICommandHandler +{ + public async Task Handle(ActivateRoleCommand request, CancellationToken cancellationToken) + { + var role = await roleRepository.GetAsync(request.RoleId, cancellationToken) ?? + throw new KnownException($"未找到角色,RoleId = {request.RoleId}", ErrorCodes.RoleNotFound); + role.Activate(); + } +} diff --git a/template/src/ABC.Template.Web/Application/Commands/Identity/Admin/RoleCommands/CreateRoleCommand.cs b/template/src/ABC.Template.Web/Application/Commands/Identity/Admin/RoleCommands/CreateRoleCommand.cs new file mode 100644 index 00000000..35356f76 --- /dev/null +++ b/template/src/ABC.Template.Web/Application/Commands/Identity/Admin/RoleCommands/CreateRoleCommand.cs @@ -0,0 +1,39 @@ +using FluentValidation; +using ABC.Template.Domain.AggregatesModel.RoleAggregate; +using ABC.Template.Infrastructure.Repositories; +using ABC.Template.Web.Application.Queries; +using ABC.Template.Web.AppPermissions; + +namespace ABC.Template.Web.Application.Commands.Identity.Admin.RoleCommands; + +public record CreateRoleCommand(string Name, string Description, IEnumerable PermissionCodes) : ICommand; + +public class CreateRoleCommandValidator : AbstractValidator +{ + public CreateRoleCommandValidator(RoleQuery roleQuery) + { + RuleFor(r => r.Name).NotEmpty().WithMessage("角色名称不能为空"); + RuleFor(r => r.Description).MaximumLength(200).WithMessage("角色描述长度不能超过200个字符"); + RuleFor(r => r.Name).MustAsync(async (n, ct) => !await roleQuery.DoesRoleExist(n, ct)) + .WithMessage(r => $"该角色已存在,Name={r.Name}"); + } +} + +public class CreateRoleCommandHandler(IRoleRepository roleRepository) : ICommandHandler +{ + public async Task Handle(CreateRoleCommand request, CancellationToken cancellationToken) + { + var permissions = request.PermissionCodes.Select(perm => + { + var (name, description) = PermissionMapper.GetPermissionInfo(perm); + return new RolePermission(perm, name, description); + }); + + var role = new Role(request.Name, request.Description, permissions); + + await roleRepository.AddAsync(role, cancellationToken); + + return role.Id; + } +} + diff --git a/template/src/ABC.Template.Web/Application/Commands/Identity/Admin/RoleCommands/DeactivateRoleCommand.cs b/template/src/ABC.Template.Web/Application/Commands/Identity/Admin/RoleCommands/DeactivateRoleCommand.cs new file mode 100644 index 00000000..56e36af1 --- /dev/null +++ b/template/src/ABC.Template.Web/Application/Commands/Identity/Admin/RoleCommands/DeactivateRoleCommand.cs @@ -0,0 +1,36 @@ +using FluentValidation; +using ABC.Template.Domain.AggregatesModel.RoleAggregate; +using ABC.Template.Infrastructure.Repositories; +using ABC.Template.Domain; + +namespace ABC.Template.Web.Application.Commands.Identity.Admin.RoleCommands; + +/// +/// 停用角色命令 +/// +/// 角色ID +public record DeactivateRoleCommand(RoleId RoleId) : ICommand; + +/// +/// 停用角色命令验证器 +/// +public class DeactivateRoleCommandValidator : AbstractValidator +{ + public DeactivateRoleCommandValidator() + { + RuleFor(x => x.RoleId).NotEmpty(); + } +} + +/// +/// 停用角色命令处理器 +/// +public class DeactivateRoleCommandHandler(IRoleRepository roleRepository) : ICommandHandler +{ + public async Task Handle(DeactivateRoleCommand request, CancellationToken cancellationToken) + { + var role = await roleRepository.GetAsync(request.RoleId, cancellationToken) ?? + throw new KnownException($"未找到角色,RoleId = {request.RoleId}", ErrorCodes.RoleNotFound); + role.Deactivate(); + } +} diff --git a/template/src/ABC.Template.Web/Application/Commands/Identity/Admin/RoleCommands/DeleteRoleCommand.cs b/template/src/ABC.Template.Web/Application/Commands/Identity/Admin/RoleCommands/DeleteRoleCommand.cs new file mode 100644 index 00000000..96e29f0b --- /dev/null +++ b/template/src/ABC.Template.Web/Application/Commands/Identity/Admin/RoleCommands/DeleteRoleCommand.cs @@ -0,0 +1,46 @@ +using FluentValidation; +using ABC.Template.Domain.AggregatesModel.RoleAggregate; +using ABC.Template.Infrastructure.Repositories; +using ABC.Template.Domain; + +namespace ABC.Template.Web.Application.Commands.Identity.Admin.RoleCommands; + +/// +/// 删除角色命令 +/// +/// 角色ID +public record DeleteRoleCommand(RoleId RoleId) : ICommand; + +/// +/// 删除角色命令验证器 +/// +public class DeleteRoleCommandValidator : AbstractValidator +{ + public DeleteRoleCommandValidator() + { + RuleFor(x => x.RoleId).NotEmpty().WithMessage("角色ID不能为空"); + } +} + +/// +/// 删除角色命令处理器 +/// +public class DeleteRoleCommandHandler(IRoleRepository roleRepository) : ICommandHandler +{ + public async Task Handle(DeleteRoleCommand request, CancellationToken cancellationToken) + { + var role = await roleRepository.GetAsync(request.RoleId, cancellationToken); + if (role == null) + { + throw new KnownException("角色不存在", ErrorCodes.RoleNotFound); + } + + // 检查是否为管理员用户,防止删除管理员 + if (role.Name.ToLower() == "admin") + { + throw new KnownException("不能删除管理员角色", ErrorCodes.CannotDeleteAdminRole); + } + role.SoftDelete(); + } +} + diff --git a/template/src/ABC.Template.Web/Application/Commands/Identity/Admin/RoleCommands/UpdateRoleInfoCommand.cs b/template/src/ABC.Template.Web/Application/Commands/Identity/Admin/RoleCommands/UpdateRoleInfoCommand.cs new file mode 100644 index 00000000..37bf063a --- /dev/null +++ b/template/src/ABC.Template.Web/Application/Commands/Identity/Admin/RoleCommands/UpdateRoleInfoCommand.cs @@ -0,0 +1,89 @@ +using FluentValidation; +using ABC.Template.Domain.AggregatesModel.RoleAggregate; +using ABC.Template.Infrastructure; +using ABC.Template.Infrastructure.Repositories; +using ABC.Template.Web.Application.Queries; +using ABC.Template.Domain; +using ABC.Template.Web.AppPermissions; +//#if (UseMongoDB) +using Microsoft.EntityFrameworkCore; +//#endif + +namespace ABC.Template.Web.Application.Commands.Identity.Admin.RoleCommands; + +/// +/// 更新角色信息命令 +/// +/// 角色ID +/// 角色名称 +/// 角色描述 +/// 权限代码列表 +public record UpdateRoleInfoCommand(RoleId RoleId, string Name, string Description, IEnumerable PermissionCodes) : ICommand; + +/// +/// 更新角色信息命令验证器 +/// +public class UpdateRoleInfoCommandValidator : AbstractValidator +{ + public UpdateRoleInfoCommandValidator(RoleQuery roleQuery) + { + RuleFor(x => x.RoleId).NotEmpty(); + RuleFor(x => x.Name).NotEmpty(); + } +} + +/// +/// 更新角色信息命令处理器 +/// +//#if (UseMongoDB) +/// MongoDB 不支持通过导航属性保存跨集合实体,需要直接操作 RolePermissions 集合 +public class UpdateRoleInfoCommandHandler(IRoleRepository roleRepository, ApplicationDbContext dbContext) : ICommandHandler +{ + public async Task Handle(UpdateRoleInfoCommand request, CancellationToken cancellationToken) + { + var role = await roleRepository.GetAsync(request.RoleId, cancellationToken) ?? + throw new KnownException($"未找到角色,RoleId = {request.RoleId}", ErrorCodes.RoleNotFound); + role.UpdateRoleInfo(request.Name, request.Description); + + var permissionCodes = request.PermissionCodes.ToList(); + var existingPermissions = await dbContext.RolePermissions + .Where(rp => rp.RoleId == request.RoleId) + .ToListAsync(cancellationToken); + + var existingPermissionMap = existingPermissions.ToDictionary(p => p.PermissionCode); + var targetPermissionCodes = permissionCodes.ToHashSet(); + + foreach (var permissionToRemove in existingPermissions.Where(ep => !targetPermissionCodes.Contains(ep.PermissionCode)).ToList()) + { + dbContext.RolePermissions.Remove(permissionToRemove); + } + + var existingPermissionCodes = existingPermissionMap.Keys.ToHashSet(); + foreach (var pc in permissionCodes.Where(pc => !existingPermissionCodes.Contains(pc))) + { + var (name, description) = PermissionMapper.GetPermissionInfo(pc); + var permissionToAdd = new RolePermission(pc, name, description); + await dbContext.RolePermissions.AddAsync(permissionToAdd, cancellationToken); + dbContext.Entry(permissionToAdd).Property(nameof(RolePermission.RoleId)).CurrentValue = request.RoleId; + } + } +} +//#else +public class UpdateRoleInfoCommandHandler(IRoleRepository roleRepository) : ICommandHandler +{ + public async Task Handle(UpdateRoleInfoCommand request, CancellationToken cancellationToken) + { + var role = await roleRepository.GetAsync(request.RoleId, cancellationToken) ?? + throw new KnownException($"未找到角色,RoleId = {request.RoleId}", ErrorCodes.RoleNotFound); + role.UpdateRoleInfo(request.Name, request.Description); + + var permissions = request.PermissionCodes.Select(perm => + { + var (name, description) = PermissionMapper.GetPermissionInfo(perm); + return new RolePermission(perm, name, description); + }); + role.UpdateRolePermissions(permissions); + } +} +//#endif + diff --git a/template/src/ABC.Template.Web/Application/Commands/Identity/Admin/UserCommands/CreateUserCommand.cs b/template/src/ABC.Template.Web/Application/Commands/Identity/Admin/UserCommands/CreateUserCommand.cs new file mode 100644 index 00000000..86b6d754 --- /dev/null +++ b/template/src/ABC.Template.Web/Application/Commands/Identity/Admin/UserCommands/CreateUserCommand.cs @@ -0,0 +1,54 @@ +using FluentValidation; +using ABC.Template.Domain.AggregatesModel.UserAggregate; +using ABC.Template.Domain.AggregatesModel.DeptAggregate; +using ABC.Template.Infrastructure.Repositories; +using ABC.Template.Web.Application.Queries; +using Serilog; + +namespace ABC.Template.Web.Application.Commands.Identity.Admin.UserCommands; + +/// +/// 创建用户命令 +/// +public record CreateUserCommand(string Name, string Email, string Password, string Phone, string RealName, int Status, string Gender, DateTimeOffset BirthDate, DeptId? DeptId, string? DeptName, IEnumerable RolesToBeAssigned) : ICommand; + +public class CreateUserCommandValidator : AbstractValidator +{ + public CreateUserCommandValidator(UserQuery userQuery) + { + RuleFor(u => u.Name).NotEmpty().WithMessage("用户名不能为空"); + RuleFor(u => u.Password).NotEmpty().WithMessage("密码不能为空"); + RuleFor(u => u.Name).MustAsync(async (n, ct) => !await userQuery.DoesUserExist(n, ct)) + .WithMessage(u => $"该用户已存在,Name={u.Name}"); + } +} + +public class CreateUserCommandHandler(IUserRepository userRepository) : ICommandHandler +{ + public async Task Handle(CreateUserCommand request, CancellationToken cancellationToken) + { + Log.Information("开始创建用户: {UserName}, Email: {Email}", request.Name, request.Email); + + var passwordHash = Utils.PasswordHasher.HashPassword(request.Password); + + var roles = request.RolesToBeAssigned + .Select(r => new UserRole(r.RoleId, r.RoleName)) + .ToList(); + + var user = new User(request.Name, request.Phone, passwordHash, roles, request.RealName, request.Status, request.Email, request.Gender, request.BirthDate); + if (request.DeptId != null && !string.IsNullOrEmpty(request.DeptName)) + { + var dept = new UserDept(user.Id, request.DeptId, request.DeptName); + user.AssignDept(dept); + Log.Debug("为用户分配部门: UserId={UserId}, DeptId={DeptId}, DeptName={DeptName}", user.Id, request.DeptId, request.DeptName); + } + + await userRepository.AddAsync(user, cancellationToken); + + Log.Information("用户创建成功: UserId={UserId}, UserName={UserName}, Email={Email}, RoleCount={RoleCount}", + user.Id, request.Name, request.Email, roles.Count); + + return user.Id; + } +} + diff --git a/template/src/ABC.Template.Web/Application/Commands/Identity/Admin/UserCommands/DeleteUserCommand.cs b/template/src/ABC.Template.Web/Application/Commands/Identity/Admin/UserCommands/DeleteUserCommand.cs new file mode 100644 index 00000000..7c91701f --- /dev/null +++ b/template/src/ABC.Template.Web/Application/Commands/Identity/Admin/UserCommands/DeleteUserCommand.cs @@ -0,0 +1,38 @@ +using FluentValidation; +using ABC.Template.Domain.AggregatesModel.UserAggregate; +using ABC.Template.Infrastructure.Repositories; +using ABC.Template.Domain; + +namespace ABC.Template.Web.Application.Commands.Identity.Admin.UserCommands; + +/// +/// 删除用户命令 +/// +/// 用户ID +public record DeleteUserCommand(UserId UserId) : ICommand; + +/// +/// 删除用户命令验证器 +/// +public class DeleteUserCommandValidator : AbstractValidator +{ + public DeleteUserCommandValidator() + { + RuleFor(x => x.UserId).NotEmpty().WithMessage("用户ID不能为空"); + } +} + +/// +/// 删除用户命令处理器 +/// +public class DeleteUserCommandHandler(IUserRepository userRepository) : ICommandHandler +{ + public async Task Handle(DeleteUserCommand request, CancellationToken cancellationToken) + { + var user = await userRepository.GetAsync(request.UserId, cancellationToken) ?? + throw new KnownException($"未找到用户,UserId = {request.UserId}", ErrorCodes.UserNotFound); + + user.SoftDelete(); + } +} + diff --git a/template/src/ABC.Template.Web/Application/Commands/Identity/Admin/UserCommands/PasswordResetCommand.cs b/template/src/ABC.Template.Web/Application/Commands/Identity/Admin/UserCommands/PasswordResetCommand.cs new file mode 100644 index 00000000..9bc453f2 --- /dev/null +++ b/template/src/ABC.Template.Web/Application/Commands/Identity/Admin/UserCommands/PasswordResetCommand.cs @@ -0,0 +1,39 @@ +using FluentValidation; +using ABC.Template.Domain.AggregatesModel.UserAggregate; +using ABC.Template.Infrastructure.Repositories; +using ABC.Template.Web.Application.Queries; +using ABC.Template.Domain; + +namespace ABC.Template.Web.Application.Commands.Identity.Admin.UserCommands; + +/// +/// 密码重置命令 +/// +public record PasswordResetCommand(UserId UserId, string Password) : ICommand; + +/// +/// 密码重置命令验证器 +/// +public class PasswordResetCommandValidator : AbstractValidator +{ + public PasswordResetCommandValidator(UserQuery userQuery) + { + RuleFor(u => u.UserId).NotEmpty().WithMessage("用户ID不能为空"); + RuleFor(u => u.Password).NotEmpty().WithMessage("密码不能为空"); + } +} + +/// +/// 密码重置命令处理器 +/// +public class PasswordResetCommandHandler(IUserRepository userRepository) : ICommandHandler +{ + public async Task Handle(PasswordResetCommand request, CancellationToken cancellationToken) + { + var user = await userRepository.GetAsync(request.UserId, cancellationToken) + ?? throw new KnownException($"用户不存在,UserId={request.UserId}", ErrorCodes.UserNotFound); + user.PasswordReset(request.Password); + return user.Id; + } +} + diff --git a/template/src/ABC.Template.Web/Application/Commands/Identity/Admin/UserCommands/RevokeUserRefreshTokensCommand.cs b/template/src/ABC.Template.Web/Application/Commands/Identity/Admin/UserCommands/RevokeUserRefreshTokensCommand.cs new file mode 100644 index 00000000..55793633 --- /dev/null +++ b/template/src/ABC.Template.Web/Application/Commands/Identity/Admin/UserCommands/RevokeUserRefreshTokensCommand.cs @@ -0,0 +1,21 @@ +using ABC.Template.Domain.AggregatesModel.UserAggregate; +using ABC.Template.Infrastructure.Repositories; +using ABC.Template.Domain; + +namespace ABC.Template.Web.Application.Commands.Identity.Admin.UserCommands; + +/// +/// 撤销用户所有刷新令牌的命令(用于退出登录) +/// +public record RevokeUserRefreshTokensCommand(UserId UserId) : ICommand; + +public class RevokeUserRefreshTokensCommandHandler(IUserRepository userRepository) : ICommandHandler +{ + public async Task Handle(RevokeUserRefreshTokensCommand request, CancellationToken cancellationToken) + { + var user = await userRepository.GetAsync(request.UserId, cancellationToken) + ?? throw new KnownException($"未找到用户,UserId = {request.UserId}", ErrorCodes.UserNotFound); + + user.RevokeAllRefreshTokens(); + } +} diff --git a/template/src/ABC.Template.Web/Application/Commands/Identity/Admin/UserCommands/UpdateUserCommand.cs b/template/src/ABC.Template.Web/Application/Commands/Identity/Admin/UserCommands/UpdateUserCommand.cs new file mode 100644 index 00000000..7cd92ca6 --- /dev/null +++ b/template/src/ABC.Template.Web/Application/Commands/Identity/Admin/UserCommands/UpdateUserCommand.cs @@ -0,0 +1,93 @@ +using FluentValidation; +using ABC.Template.Domain.AggregatesModel.UserAggregate; +using ABC.Template.Domain.AggregatesModel.DeptAggregate; +using ABC.Template.Infrastructure; +using ABC.Template.Infrastructure.Repositories; +using ABC.Template.Domain; +//#if (UseMongoDB) +using Microsoft.EntityFrameworkCore; +//#endif + +namespace ABC.Template.Web.Application.Commands.Identity.Admin.UserCommands; + +/// +/// 更新用户命令 +/// +public record UpdateUserCommand(UserId UserId, string Name, string Email, string Phone, string RealName, int Status, string Gender, int Age, DateTimeOffset BirthDate, DeptId DeptId, string DeptName, string PasswordHash) : ICommand; + +/// +/// 更新用户命令验证器 +/// +public class UpdateUserCommandValidator : AbstractValidator +{ + public UpdateUserCommandValidator() + { + RuleFor(x => x.UserId).NotEmpty().WithMessage("用户ID不能为空"); + RuleFor(x => x.Name).NotEmpty().WithMessage("用户名不能为空"); + } +} + +/// +/// 更新用户命令处理器 +/// +//#if (UseMongoDB) +/// MongoDB 不支持通过导航属性保存跨集合实体,需要直接操作 UserDepts 集合 +public class UpdateUserCommandHandler(IUserRepository userRepository, ApplicationDbContext dbContext) : ICommandHandler +{ + public async Task Handle(UpdateUserCommand request, CancellationToken cancellationToken) + { + var user = await userRepository.GetAsync(request.UserId, cancellationToken) ?? + throw new KnownException($"未找到用户,UserId = {request.UserId}", ErrorCodes.UserNotFound); + + user.UpdateUserInfo(request.Name, request.Phone, request.RealName, request.Status, request.Email, request.Gender, request.BirthDate); + + if (!string.IsNullOrEmpty(request.PasswordHash)) + { + user.UpdatePassword(request.PasswordHash); + } + + if (request.DeptId != new DeptId(0) && !string.IsNullOrEmpty(request.DeptName)) + { + var existingDept = await dbContext.UserDepts + .FirstOrDefaultAsync(ud => ud.UserId == request.UserId, cancellationToken); + + if (existingDept != null) + { + existingDept.UpdateDept(request.DeptId, request.DeptName); + } + else + { + var newDept = new UserDept(user.Id, request.DeptId, request.DeptName); + await dbContext.UserDepts.AddAsync(newDept, cancellationToken); + } + } + + return user.Id; + } +} +//#else +public class UpdateUserCommandHandler(IUserRepository userRepository) : ICommandHandler +{ + public async Task Handle(UpdateUserCommand request, CancellationToken cancellationToken) + { + var user = await userRepository.GetAsync(request.UserId, cancellationToken) ?? + throw new KnownException($"未找到用户,UserId = {request.UserId}", ErrorCodes.UserNotFound); + + user.UpdateUserInfo(request.Name, request.Phone, request.RealName, request.Status, request.Email, request.Gender, request.BirthDate); + + if (!string.IsNullOrEmpty(request.PasswordHash)) + { + user.UpdatePassword(request.PasswordHash); + } + + if (request.DeptId != new DeptId(0) && !string.IsNullOrEmpty(request.DeptName)) + { + var dept = new UserDept(user.Id, request.DeptId, request.DeptName); + user.AssignDept(dept); + } + + return user.Id; + } +} +//#endif + diff --git a/template/src/ABC.Template.Web/Application/Commands/Identity/Admin/UserCommands/UpdateUserDeptNameCommand.cs b/template/src/ABC.Template.Web/Application/Commands/Identity/Admin/UserCommands/UpdateUserDeptNameCommand.cs new file mode 100644 index 00000000..9a2af22d --- /dev/null +++ b/template/src/ABC.Template.Web/Application/Commands/Identity/Admin/UserCommands/UpdateUserDeptNameCommand.cs @@ -0,0 +1,39 @@ +using FluentValidation; +using ABC.Template.Domain.AggregatesModel.UserAggregate; +using ABC.Template.Infrastructure.Repositories; +using ABC.Template.Domain; + +namespace ABC.Template.Web.Application.Commands.Identity.Admin.UserCommands; + +/// +/// 更新用户部门名称命令 +/// +public record UpdateUserDeptNameCommand(UserId UserId, string DeptName) : ICommand; + +/// +/// 更新用户部门名称命令验证器 +/// +public class UpdateUserDeptNameCommandValidator : AbstractValidator +{ + public UpdateUserDeptNameCommandValidator() + { + RuleFor(x => x.UserId).NotEmpty().WithMessage("用户ID不能为空"); + RuleFor(x => x.DeptName).NotEmpty().WithMessage("部门名称不能为空"); + } +} + +/// +/// 更新用户部门名称命令处理器 +/// +public class UpdateUserDeptNameCommandHandler(IUserRepository userRepository) : ICommandHandler +{ + public async Task Handle(UpdateUserDeptNameCommand request, CancellationToken cancellationToken) + { + var user = await userRepository.GetAsync(request.UserId, cancellationToken) ?? + throw new KnownException($"未找到用户,UserId = {request.UserId}", ErrorCodes.UserNotFound); + + user.UpdateDeptName(request.DeptName); + + return user.Id; + } +} diff --git a/template/src/ABC.Template.Web/Application/Commands/Identity/Admin/UserCommands/UpdateUserLoginTimeCommand.cs b/template/src/ABC.Template.Web/Application/Commands/Identity/Admin/UserCommands/UpdateUserLoginTimeCommand.cs new file mode 100644 index 00000000..8e767b8d --- /dev/null +++ b/template/src/ABC.Template.Web/Application/Commands/Identity/Admin/UserCommands/UpdateUserLoginTimeCommand.cs @@ -0,0 +1,20 @@ +using ABC.Template.Domain.AggregatesModel.UserAggregate; +using ABC.Template.Infrastructure.Repositories; +using ABC.Template.Domain; + +namespace ABC.Template.Web.Application.Commands.Identity.Admin.UserCommands; + +public record UpdateUserLoginTimeCommand(UserId UserId, DateTimeOffset LoginTime, string RefreshToken) : ICommand; + +public class UpdateUserLoginTimeCommandHandler(IUserRepository userRepository) : ICommandHandler +{ + public async Task Handle(UpdateUserLoginTimeCommand request, CancellationToken cancellationToken) + { + var user = await userRepository.GetAsync(request.UserId, cancellationToken) + ?? throw new KnownException($"未找到用户,UserId = {request.UserId}", ErrorCodes.UserNotFound); + + user.UpdateLastLoginTime(request.LoginTime); + user.SetUserRefreshToken(request.RefreshToken); + } +} + diff --git a/template/src/ABC.Template.Web/Application/Commands/Identity/Admin/UserCommands/UpdateUserRoleNameCommand.cs b/template/src/ABC.Template.Web/Application/Commands/Identity/Admin/UserCommands/UpdateUserRoleNameCommand.cs new file mode 100644 index 00000000..9faaed9e --- /dev/null +++ b/template/src/ABC.Template.Web/Application/Commands/Identity/Admin/UserCommands/UpdateUserRoleNameCommand.cs @@ -0,0 +1,41 @@ +using FluentValidation; +using ABC.Template.Domain.AggregatesModel.UserAggregate; +using ABC.Template.Domain.AggregatesModel.RoleAggregate; +using ABC.Template.Infrastructure.Repositories; +using ABC.Template.Domain; + +namespace ABC.Template.Web.Application.Commands.Identity.Admin.UserCommands; + +/// +/// 更新用户角色名称命令 +/// +public record UpdateUserRoleNameCommand(UserId UserId, RoleId RoleId, string RoleName) : ICommand; + +/// +/// 更新用户角色名称命令验证器 +/// +public class UpdateUserRoleNameCommandValidator : AbstractValidator +{ + public UpdateUserRoleNameCommandValidator() + { + RuleFor(x => x.UserId).NotEmpty().WithMessage("用户ID不能为空"); + RuleFor(x => x.RoleId).NotEmpty().WithMessage("角色ID不能为空"); + RuleFor(x => x.RoleName).NotEmpty().WithMessage("角色名称不能为空"); + } +} + +/// +/// 更新用户角色名称命令处理器 +/// +public class UpdateUserRoleNameCommandHandler(IUserRepository userRepository) : ICommandHandler +{ + public async Task Handle(UpdateUserRoleNameCommand request, CancellationToken cancellationToken) + { + var user = await userRepository.GetAsync(request.UserId, cancellationToken) ?? + throw new KnownException($"未找到用户,UserId = {request.UserId}", ErrorCodes.UserNotFound); + + user.UpdateRoleInfo(request.RoleId, request.RoleName); + + return user.Id; + } +} diff --git a/template/src/ABC.Template.Web/Application/Commands/Identity/Admin/UserCommands/UpdateUserRolesCommand.cs b/template/src/ABC.Template.Web/Application/Commands/Identity/Admin/UserCommands/UpdateUserRolesCommand.cs new file mode 100644 index 00000000..3b91b560 --- /dev/null +++ b/template/src/ABC.Template.Web/Application/Commands/Identity/Admin/UserCommands/UpdateUserRolesCommand.cs @@ -0,0 +1,45 @@ +using FluentValidation; +using ABC.Template.Domain.AggregatesModel.UserAggregate; +using ABC.Template.Infrastructure.Repositories; +using ABC.Template.Web.Application.Queries; +using ABC.Template.Domain; + +namespace ABC.Template.Web.Application.Commands.Identity.Admin.UserCommands; + +/// +/// 更新用户角色命令 +/// +public record UpdateUserRolesCommand(UserId UserId, List RolesToBeAssigned) : ICommand; + +/// +/// 更新用户角色命令验证器 +/// +public class UpdateUserRolesCommandValidator : AbstractValidator +{ + public UpdateUserRolesCommandValidator() + { + RuleFor(x => x.UserId).NotEmpty().WithMessage("用户ID不能为空"); + } +} + +/// +/// 更新用户角色命令处理器 +/// +public class UpdateUserRolesCommandHandler(IUserRepository userRepository) : ICommandHandler +{ + public async Task Handle(UpdateUserRolesCommand request, CancellationToken cancellationToken) + { + var user = await userRepository.GetAsync(request.UserId, cancellationToken) + ?? throw new KnownException($"未找到用户,UserId = {request.UserId}", ErrorCodes.UserNotFound); + + List roles = []; + + foreach (var assignAdminUserRoleDto in request.RolesToBeAssigned) + { + roles.Add(new UserRole(assignAdminUserRoleDto.RoleId, assignAdminUserRoleDto.RoleName)); + } + + user.UpdateRoles(roles); + } +} + diff --git a/template/src/ABC.Template.Web/Application/Commands/Orders/CreateOrderCommand.cs b/template/src/ABC.Template.Web/Application/Commands/Orders/CreateOrderCommand.cs deleted file mode 100644 index d198ae9b..00000000 --- a/template/src/ABC.Template.Web/Application/Commands/Orders/CreateOrderCommand.cs +++ /dev/null @@ -1,27 +0,0 @@ -using ABC.Template.Domain.AggregatesModel.OrderAggregate; -using ABC.Template.Infrastructure.Repositories; - -namespace ABC.Template.Web.Application.Commands.Orders; - -public record CreateOrderCommand(string Name, int Price, int Count) : ICommand; - -public class CreateOrderCommandValidator : AbstractValidator -{ - public CreateOrderCommandValidator() - { - RuleFor(x => x.Name).NotEmpty().MaximumLength(10).WithErrorCode("name error code"); - RuleFor(x => x.Price).InclusiveBetween(18, 60).WithErrorCode("price error code"); - } -} - -public class CreateOrderCommandHandler(IOrderRepository orderRepository, ILogger logger) : ICommandHandler -{ - - public async Task Handle(CreateOrderCommand request, CancellationToken cancellationToken) - { - var order = new Order(request.Name, request.Count); - order = await orderRepository.AddAsync(order, cancellationToken); - logger.LogInformation("order created, id:{OrderId}", order.Id); - return order.Id; - } -} \ No newline at end of file diff --git a/template/src/ABC.Template.Web/Application/Commands/Orders/PayOrderCommand.cs b/template/src/ABC.Template.Web/Application/Commands/Orders/PayOrderCommand.cs deleted file mode 100644 index 3a72d1ee..00000000 --- a/template/src/ABC.Template.Web/Application/Commands/Orders/PayOrderCommand.cs +++ /dev/null @@ -1,25 +0,0 @@ -using ABC.Template.Domain.AggregatesModel.OrderAggregate; -using ABC.Template.Infrastructure.Repositories; - -namespace ABC.Template.Web.Application.Commands.Orders; - -public record PayOrderCommand(OrderId OrderId) : ICommand; - -public class PayOrderCommandLock : ICommandLock -{ - public Task GetLockKeysAsync(PayOrderCommand command, - CancellationToken cancellationToken = new CancellationToken()) - { - return Task.FromResult(command.OrderId.ToCommandLockSettings()); - } -} - -public class PayOrderCommandHandler(IOrderRepository orderRepository) : ICommandHandler -{ - public async Task Handle(PayOrderCommand request, CancellationToken cancellationToken) - { - var order = await orderRepository.GetAsync(request.OrderId, cancellationToken) ?? - throw new KnownException($"未找到订单,OrderId = {request.OrderId}"); - order.OrderPaid(); - } -} \ No newline at end of file diff --git a/template/src/ABC.Template.Web/Application/DomainEventHandlers/DeptInfoChangedDomainEventHandlerForUpdateUserDeptName.cs b/template/src/ABC.Template.Web/Application/DomainEventHandlers/DeptInfoChangedDomainEventHandlerForUpdateUserDeptName.cs new file mode 100644 index 00000000..109271c9 --- /dev/null +++ b/template/src/ABC.Template.Web/Application/DomainEventHandlers/DeptInfoChangedDomainEventHandlerForUpdateUserDeptName.cs @@ -0,0 +1,28 @@ +using ABC.Template.Domain.DomainEvents.DeptEvents; +using ABC.Template.Web.Application.Commands.Identity.Admin.UserCommands; +using ABC.Template.Web.Application.Queries; + +namespace ABC.Template.Web.Application.DomainEventHandlers; + +/// +/// 部门信息变更领域事件处理器 - 用于更新用户部门名称 +/// +public class DeptInfoChangedDomainEventHandlerForUpdateUserDeptName(IMediator mediator, UserQuery userQuery) : IDomainEventHandler +{ + public async Task Handle(DeptInfoChangedDomainEvent domainEvent, CancellationToken cancellationToken) + { + var dept = domainEvent.Dept; + var deptId = dept.Id; + var newDeptName = dept.Name; + + // 查询所有属于该部门的用户ID + var userIds = await userQuery.GetUserIdsByDeptIdAsync(deptId, cancellationToken); + + // 遍历用户ID,通过Command更新每个用户的部门名称 + foreach (var userId in userIds) + { + var command = new UpdateUserDeptNameCommand(userId, newDeptName); + await mediator.Send(command, cancellationToken); + } + } +} diff --git a/template/src/ABC.Template.Web/Application/DomainEventHandlers/OrderCreatedDomainEventHandlerForDeliverGoods.cs b/template/src/ABC.Template.Web/Application/DomainEventHandlers/OrderCreatedDomainEventHandlerForDeliverGoods.cs deleted file mode 100644 index 660e0f4f..00000000 --- a/template/src/ABC.Template.Web/Application/DomainEventHandlers/OrderCreatedDomainEventHandlerForDeliverGoods.cs +++ /dev/null @@ -1,12 +0,0 @@ -using ABC.Template.Domain.DomainEvents; -using ABC.Template.Web.Application.Commands.Delivers; - -namespace ABC.Template.Web.Application.DomainEventHandlers; - -public class OrderCreatedDomainEventHandlerForDeliverGoods(IMediator mediator) : IDomainEventHandler -{ - public Task Handle(OrderCreatedDomainEvent notification, CancellationToken cancellationToken) - { - return mediator.Send(new DeliverGoodsCommand(notification.Order.Id), cancellationToken); - } -} \ No newline at end of file diff --git a/template/src/ABC.Template.Web/Application/DomainEventHandlers/RoleInfoChangedDomainEventHandlerForUpdateUserRoleName.cs b/template/src/ABC.Template.Web/Application/DomainEventHandlers/RoleInfoChangedDomainEventHandlerForUpdateUserRoleName.cs new file mode 100644 index 00000000..993f30e7 --- /dev/null +++ b/template/src/ABC.Template.Web/Application/DomainEventHandlers/RoleInfoChangedDomainEventHandlerForUpdateUserRoleName.cs @@ -0,0 +1,28 @@ +using ABC.Template.Domain.DomainEvents.RoleEvents; +using ABC.Template.Web.Application.Commands.Identity.Admin.UserCommands; +using ABC.Template.Web.Application.Queries; + +namespace ABC.Template.Web.Application.DomainEventHandlers; + +/// +/// 角色信息变更领域事件处理器 - 用于更新用户角色名称 +/// +public class RoleInfoChangedDomainEventHandlerForUpdateUserRoleName(IMediator mediator, UserQuery userQuery) : IDomainEventHandler +{ + public async Task Handle(RoleInfoChangedDomainEvent domainEvent, CancellationToken cancellationToken) + { + var role = domainEvent.Role; + var roleId = role.Id; + var newRoleName = role.Name; + + // 查询所有拥有该角色的用户ID + var userIds = await userQuery.GetUserIdsByRoleIdAsync(roleId, cancellationToken); + + // 遍历用户ID,通过Command更新每个用户的角色名称 + foreach (var userId in userIds) + { + var command = new UpdateUserRoleNameCommand(userId, roleId, newRoleName); + await mediator.Send(command, cancellationToken); + } + } +} diff --git a/template/src/ABC.Template.Web/Application/IntegrationEventConverters/OrderPaidIntegrationEventConverter.cs b/template/src/ABC.Template.Web/Application/IntegrationEventConverters/OrderPaidIntegrationEventConverter.cs deleted file mode 100644 index 8df21ef6..00000000 --- a/template/src/ABC.Template.Web/Application/IntegrationEventConverters/OrderPaidIntegrationEventConverter.cs +++ /dev/null @@ -1,13 +0,0 @@ -using ABC.Template.Domain.DomainEvents; -using ABC.Template.Web.Application.IntegrationEvents; - -namespace ABC.Template.Web.Application.IntegrationEventConverters; - -public class OrderPaidIntegrationEventConverter - : IIntegrationEventConverter -{ - public OrderPaidIntegrationEvent Convert(OrderPaidDomainEvent domainEvent) - { - return new OrderPaidIntegrationEvent(domainEvent.Order.Id); - } -} \ No newline at end of file diff --git a/template/src/ABC.Template.Web/Application/IntegrationEventHandlers/OrderPaidIntegrationEventHandlerForDeliverGoods.cs b/template/src/ABC.Template.Web/Application/IntegrationEventHandlers/OrderPaidIntegrationEventHandlerForDeliverGoods.cs deleted file mode 100644 index d6f3162c..00000000 --- a/template/src/ABC.Template.Web/Application/IntegrationEventHandlers/OrderPaidIntegrationEventHandlerForDeliverGoods.cs +++ /dev/null @@ -1,13 +0,0 @@ -using ABC.Template.Web.Application.Commands.Delivers; -using ABC.Template.Web.Application.IntegrationEvents; - -namespace ABC.Template.Web.Application.IntegrationEventHandlers; - -public class OrderPaidIntegrationEventHandlerForDeliverGoods(IMediator mediator) : IIntegrationEventHandler -{ - public async Task HandleAsync(OrderPaidIntegrationEvent eventData, CancellationToken cancellationToken = default) - { - var cmd = new DeliverGoodsCommand(eventData.OrderId); - _ = await mediator.Send(cmd, cancellationToken); - } -} \ No newline at end of file diff --git a/template/src/ABC.Template.Web/Application/IntegrationEvents/OrderPaidIntegrationEvent.cs b/template/src/ABC.Template.Web/Application/IntegrationEvents/OrderPaidIntegrationEvent.cs deleted file mode 100644 index 65735943..00000000 --- a/template/src/ABC.Template.Web/Application/IntegrationEvents/OrderPaidIntegrationEvent.cs +++ /dev/null @@ -1,5 +0,0 @@ -using ABC.Template.Domain.AggregatesModel.OrderAggregate; - -namespace ABC.Template.Web.Application.IntegrationEvents; - -public record OrderPaidIntegrationEvent(OrderId OrderId); diff --git a/template/src/ABC.Template.Web/Application/Queries/DeptQuery.cs b/template/src/ABC.Template.Web/Application/Queries/DeptQuery.cs new file mode 100644 index 00000000..14fe96d3 --- /dev/null +++ b/template/src/ABC.Template.Web/Application/Queries/DeptQuery.cs @@ -0,0 +1,198 @@ +using Microsoft.EntityFrameworkCore; +using ABC.Template.Domain.AggregatesModel.DeptAggregate; + +namespace ABC.Template.Web.Application.Queries; + +/// +/// 部门查询DTO +/// +public record DeptQueryDto(DeptId Id, string Name, string Remark, DeptId ParentId, int Status, DateTimeOffset CreatedAt, DeletedTime? DeletedAt); + +/// +/// 部门查询输入参数 +/// +public class DeptQueryInput +{ + public string? Name { get; set; } + public string? Remark { get; set; } + public int? Status { get; set; } + public DeptId? ParentId { get; set; } +} + +/// +/// 部门树形DTO - 应用层数据传输对象 +/// +public record DeptTreeDto( + DeptId Id, + string Name, + string Remark, + DeptId ParentId, + int Status, + DateTimeOffset CreatedAt, + IEnumerable Children); + +/// +/// 部门查询服务 +/// +public class DeptQuery(ApplicationDbContext applicationDbContext) : IQuery +{ + private DbSet DeptSet { get; } = applicationDbContext.Depts; + + /// + /// 检查部门名称是否存在 + /// + public async Task DoesDeptExist(string name, CancellationToken cancellationToken) + { + return await DeptSet.AsNoTracking() + .AnyAsync(d => d.Name == name, cancellationToken: cancellationToken); + } + + /// + /// 检查部门ID是否存在 + /// + public async Task DoesDeptExist(DeptId id, CancellationToken cancellationToken) + { + return await DeptSet.AsNoTracking() + .AnyAsync(d => d.Id == id, cancellationToken: cancellationToken); + } + + /// + /// 根据ID获取部门 + /// + public async Task GetDeptByIdAsync(DeptId id, CancellationToken cancellationToken = default) + { + return await DeptSet.AsNoTracking() + .Where(d => d.Id == id) + .Select(d => new DeptQueryDto(d.Id, d.Name, d.Remark, d.ParentId, d.Status, d.CreatedAt, d.DeletedAt)) + .FirstOrDefaultAsync(cancellationToken); + } + + /// + /// 获取所有部门 + /// + public async Task> GetAllDeptsAsync(DeptQueryInput query, CancellationToken cancellationToken) + { + return await DeptSet.AsNoTracking() + .WhereIf(!string.IsNullOrWhiteSpace(query.Name), d => d.Name.Contains(query.Name!)) + .WhereIf(!string.IsNullOrWhiteSpace(query.Remark), d => d.Remark.Contains(query.Remark!)) + .WhereIf(query.Status.HasValue, d => d.Status == query.Status) + .WhereIf(query.ParentId != null, d => d.ParentId == query.ParentId) + .OrderBy(d => d.CreatedAt) + .Select(d => new DeptQueryDto(d.Id, d.Name, d.Remark, d.ParentId, d.Status, d.CreatedAt, d.DeletedAt)) + .ToListAsync(cancellationToken); + } + + /// + /// 获取部门树 + /// 优化:使用投影只选择需要的字段,减少内存占用 + /// + public async Task> GetDeptTreeAsync(bool includeInactive = false, CancellationToken cancellationToken = default) + { + // 使用投影只选择构建树所需的字段,减少内存占用 + var allDepts = await DeptSet.AsNoTracking() + .WhereIf(!includeInactive, d => d.Status != 0) + .Select(d => new DeptTreeNode + { + Id = d.Id, + Name = d.Name, + Remark = d.Remark, + ParentId = d.ParentId, + Status = d.Status, + CreatedAt = d.CreatedAt + }) + .ToListAsync(cancellationToken); + + // 构建树形结构 + var treeStructure = BuildTreeStructureFromProjection(allDepts); + + // 转换为应用层DTO + return treeStructure.Select(d => ConvertToTreeDtoFromProjection(d)); + } + + /// + /// 构建部门树形结构(基于投影数据) + /// + private static List BuildTreeStructureFromProjection( + List allDepts) + { + var deptDict = allDepts.ToDictionary(d => d.Id); + var result = new List(); + + foreach (var dept in allDepts) + { + // 只处理根节点(ParentId为0) + if (dept.ParentId == new DeptId(0)) + { + result.Add(BuildTreeDtoFromProjection(dept, deptDict)); + } + } + + return result.OrderBy(d => d.CreatedAt).ToList(); + } + + /// + /// 构建单个部门的树形结构(基于投影数据) + /// + private static DeptTreeNode BuildTreeDtoFromProjection( + DeptTreeNode dept, + Dictionary allDepts) + { + var children = new List(); + + // 查找所有以当前部门为父级的子部门 + var childDepts = allDepts.Values + .Where(d => d.ParentId == dept.Id) + .OrderBy(d => d.CreatedAt); + + foreach (var child in childDepts) + { + children.Add(BuildTreeDtoFromProjection(child, allDepts)); + } + + return new DeptTreeNode + { + Id = dept.Id, + Name = dept.Name, + Remark = dept.Remark, + ParentId = dept.ParentId, + Status = dept.Status, + CreatedAt = dept.CreatedAt, + Children = children + }; + } + + /// + /// 将投影节点转换为树形DTO + /// + private static DeptTreeDto ConvertToTreeDtoFromProjection(DeptTreeNode node) + { + var children = node.Children + .OrderBy(d => d.CreatedAt) + .Select(d => ConvertToTreeDtoFromProjection(d)) + .ToList(); + + return new DeptTreeDto( + node.Id, + node.Name, + node.Remark, + node.ParentId, + node.Status, + node.CreatedAt, + children + ); + } + + /// + /// 部门树节点(用于内存中的树构建) + /// + private sealed class DeptTreeNode + { + public DeptId Id { get; set; }=default!; + public string Name { get; set; } = string.Empty; + public string Remark { get; set; } = string.Empty; + public DeptId ParentId { get; set; }=default!; + public int Status { get; set; } + public DateTimeOffset CreatedAt { get; set; } + public List Children { get; set; } = new(); + } +} diff --git a/template/src/ABC.Template.Web/Application/Queries/Orders/OrderQuery.cs b/template/src/ABC.Template.Web/Application/Queries/Orders/OrderQuery.cs deleted file mode 100644 index 50bf4e6e..00000000 --- a/template/src/ABC.Template.Web/Application/Queries/Orders/OrderQuery.cs +++ /dev/null @@ -1,21 +0,0 @@ -using ABC.Template.Domain.AggregatesModel.OrderAggregate; -using Microsoft.EntityFrameworkCore; - -namespace ABC.Template.Web.Application.Queries.Orders; - - -public record QueryOrder(OrderId Id) : IQuery; - -public record QueryOrderResult(OrderId Id, string Name, int Count); - -public class OrderQueryHandler(ApplicationDbContext applicationDbContext) - : IQueryHandler -{ - public async Task Handle(QueryOrder request, CancellationToken cancellationToken) - { - var result = await applicationDbContext.Orders.Where(p => p.Id == request.Id) - .Select(p => new QueryOrderResult(p.Id, p.Name, p.Count)) - .FirstOrDefaultAsync(cancellationToken); - return result ?? throw new KnownException("Order not found"); - } -} diff --git a/template/src/ABC.Template.Web/Application/Queries/RoleQuery.cs b/template/src/ABC.Template.Web/Application/Queries/RoleQuery.cs new file mode 100644 index 00000000..799c1f97 --- /dev/null +++ b/template/src/ABC.Template.Web/Application/Queries/RoleQuery.cs @@ -0,0 +1,247 @@ +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Caching.Memory; +using ABC.Template.Domain.AggregatesModel.RoleAggregate; + +namespace ABC.Template.Web.Application.Queries; + +public record RoleQueryDto(RoleId RoleId, string Name, string Description, bool IsActive, DateTimeOffset CreatedAt, IEnumerable PermissionCodes); + +public class RoleQueryInput : PageRequest +{ + public string? Name { get; set; } + public string? Description { get; set; } + public bool? IsActive { get; set; } + public DateTimeOffset? StartTime { get; set; } + public DateTimeOffset? EndTime { get; set; } +} + +public record AssignAdminUserRoleQueryDto(RoleId RoleId, string RoleName, IEnumerable PermissionCodes); + +public class RoleQuery(ApplicationDbContext applicationDbContext, IMemoryCache memoryCache) : IQuery +{ + private DbSet RoleSet { get; } = applicationDbContext.Roles; + private const string RoleCacheKeyPrefix = "role:"; + private static readonly TimeSpan RoleCacheExpiry = TimeSpan.FromMinutes(10); + + public async Task DoesRoleExist(string name, CancellationToken cancellationToken) + { + return await RoleSet.AsNoTracking() + .AnyAsync(r => r.Name == name, cancellationToken: cancellationToken); + } + +//#if (UseMongoDB) + /// + /// 获取用于分配的管理员角色信息 + /// MongoDB 不支持在 Select 中投影跨集合导航,拆为多次查询 + /// + public async Task> GetAdminRolesForAssignmentAsync(IEnumerable ids, CancellationToken cancellationToken) + { + var roleIdList = ids.ToList(); + if (!roleIdList.Any()) + { + return []; + } + + var roles = await RoleSet + .IgnoreAutoIncludes() + .AsNoTracking() + .Where(r => roleIdList.Contains(r.Id)) + .Select(r => new { r.Id, r.Name }) + .ToListAsync(cancellationToken); + + if (!roles.Any()) + { + return []; + } + + var allPermissions = await applicationDbContext.RolePermissions + .AsNoTracking() + .Where(rp => roleIdList.Contains(rp.RoleId)) + .ToListAsync(cancellationToken); + + var permissionsByRoleId = allPermissions + .GroupBy(rp => rp.RoleId) + .ToDictionary(g => g.Key, g => g.Select(rp => rp.PermissionCode).ToList()); + + return roles.Select(r => new AssignAdminUserRoleQueryDto( + r.Id, + r.Name, + permissionsByRoleId.GetValueOrDefault(r.Id, []))).ToList(); + } +//#else + public async Task> GetAdminRolesForAssignmentAsync(IEnumerable ids, CancellationToken cancellationToken) + { + return await RoleSet.AsNoTracking() + .Where(r => ids.Contains(r.Id)) + .Select(r => new AssignAdminUserRoleQueryDto( + r.Id, + r.Name, + r.Permissions.Select(rp => rp.PermissionCode))) + .ToListAsync(cancellationToken); + } +//#endif + +//#if (UseMongoDB) + /// + /// 获取指定角色的所有权限代码 + /// MongoDB 不支持 SelectMany 跨集合导航,改为直接查询 RolePermissions 集合 + /// + public async Task> GetAssignedPermissionCodesAsync(IEnumerable ids, CancellationToken cancellationToken) + { + if (!ids.Any()) + { + return Enumerable.Empty(); + } + + var roleIds = ids.ToList(); + return await applicationDbContext.RolePermissions + .AsNoTracking() + .Where(rp => roleIds.Contains(rp.RoleId)) + .Select(rp => rp.PermissionCode) + .Distinct() + .ToListAsync(cancellationToken); + } +//#else + public async Task> GetAssignedPermissionCodesAsync(IEnumerable ids, CancellationToken cancellationToken) + { + if (!ids.Any()) + { + return Enumerable.Empty(); + } + + var roleIds = ids.ToList(); + return await RoleSet.AsNoTracking() + .Where(r => roleIds.Contains(r.Id)) + .SelectMany(r => r.Permissions) + .Select(rp => rp.PermissionCode) + .Distinct() + .ToListAsync(cancellationToken); + } +//#endif + + public async Task GetRoleByIdAsync(RoleId id, CancellationToken cancellationToken = default) + { + var cacheKey = $"{RoleCacheKeyPrefix}{id}"; + + return await memoryCache.GetOrCreateAsync(cacheKey, async entry => + { + entry.AbsoluteExpirationRelativeToNow = RoleCacheExpiry; + +//#if (UseMongoDB) + var role = await RoleSet + .IgnoreAutoIncludes() + .AsNoTracking() + .Where(r => r.Id == id) + .Select(r => new { r.Id, r.Name, r.Description, r.IsActive, r.CreatedAt }) + .FirstOrDefaultAsync(cancellationToken); + + if (role == null) + return null; + + var permissions = await applicationDbContext.RolePermissions + .AsNoTracking() + .Where(rp => rp.RoleId == id) + .Select(rp => rp.PermissionCode) + .ToListAsync(cancellationToken); + + return new RoleQueryDto(role.Id, role.Name, role.Description, role.IsActive, role.CreatedAt, permissions); +//#else + return await RoleSet.AsNoTracking() + .Where(r => r.Id == id) + .Select(r => new RoleQueryDto(r.Id, r.Name, r.Description, r.IsActive, r.CreatedAt, r.Permissions.Select(rp => rp.PermissionCode))) + .FirstOrDefaultAsync(cancellationToken); +//#endif + }); + } + +//#if (UseMongoDB) + /// + /// 获取所有角色(分页) + /// MongoDB 不支持在 Select 中投影跨集合导航,拆为多次查询 + /// + public async Task> GetAllRolesAsync(RoleQueryInput query, CancellationToken cancellationToken) + { + var queryable = RoleSet + .IgnoreAutoIncludes() + .AsNoTracking(); + + if (!string.IsNullOrWhiteSpace(query.Name)) + { + queryable = queryable.Where(r => r.Name.Contains(query.Name!)); + } + + if (!string.IsNullOrWhiteSpace(query.Description)) + { + queryable = queryable.Where(r => r.Description.Contains(query.Description!)); + } + + if (query.IsActive.HasValue) + { + queryable = queryable.Where(r => r.IsActive == query.IsActive); + } + + if (query.StartTime.HasValue) + { + queryable = queryable.Where(r => r.CreatedAt >= query.StartTime!.Value); + } + + if (query.EndTime.HasValue) + { + queryable = queryable.Where(r => r.CreatedAt <= query.EndTime!.Value); + } + + var pagedRoles = await queryable + .OrderBy(r => r.Id) + .Select(r => new { r.Id, r.Name, r.Description, r.IsActive, r.CreatedAt }) + .ToPagedDataAsync(query, cancellationToken); + + if (pagedRoles.Items == null || !pagedRoles.Items.Any()) + { + return new PagedData( + Enumerable.Empty(), + pagedRoles.Total, + pagedRoles.PageIndex, + pagedRoles.PageSize); + } + + var roleIds = pagedRoles.Items.Select(r => r.Id).ToList(); + + var allPermissions = await applicationDbContext.RolePermissions + .AsNoTracking() + .Where(rp => roleIds.Contains(rp.RoleId)) + .ToListAsync(cancellationToken); + + var permissionsByRoleId = allPermissions + .GroupBy(rp => rp.RoleId) + .ToDictionary(g => g.Key, g => g.Select(rp => rp.PermissionCode).ToList()); + + var roleDtos = pagedRoles.Items.Select(r => new RoleQueryDto( + r.Id, + r.Name, + r.Description, + r.IsActive, + r.CreatedAt, + permissionsByRoleId.GetValueOrDefault(r.Id, []))).ToList(); + + return new PagedData( + roleDtos, + pagedRoles.Total, + pagedRoles.PageIndex, + pagedRoles.PageSize); + } +//#else + public async Task> GetAllRolesAsync(RoleQueryInput query, CancellationToken cancellationToken) + { + return await RoleSet.AsNoTracking() + .WhereIf(!string.IsNullOrWhiteSpace(query.Name), r => r.Name.Contains(query.Name!)) + .WhereIf(!string.IsNullOrWhiteSpace(query.Description), r => r.Description.Contains(query.Description!)) + .WhereIf(query.IsActive.HasValue, r => r.IsActive == query.IsActive) + .WhereIf(query.StartTime.HasValue, r => r.CreatedAt >= query.StartTime!.Value) + .WhereIf(query.EndTime.HasValue, r => r.CreatedAt <= query.EndTime!.Value) + .OrderBy(r => r.Id) + .Select(r => new RoleQueryDto(r.Id, r.Name, r.Description, r.IsActive, r.CreatedAt, r.Permissions.Select(rp => rp.PermissionCode))) + .ToPagedDataAsync(query, cancellationToken); + } +//#endif +} + diff --git a/template/src/ABC.Template.Web/Application/Queries/UserQuery.cs b/template/src/ABC.Template.Web/Application/Queries/UserQuery.cs new file mode 100644 index 00000000..63daf132 --- /dev/null +++ b/template/src/ABC.Template.Web/Application/Queries/UserQuery.cs @@ -0,0 +1,396 @@ +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Caching.Memory; +using ABC.Template.Domain.AggregatesModel.RoleAggregate; +using ABC.Template.Domain.AggregatesModel.UserAggregate; +using ABC.Template.Domain.AggregatesModel.DeptAggregate; +using ABC.Template.Domain; + +namespace ABC.Template.Web.Application.Queries; + +/// +/// 用户信息查询DTO +/// +public record UserInfoQueryDto(UserId UserId, string Name, string Phone, IEnumerable Roles, string RealName, int Status, string Email, DateTimeOffset CreatedAt, string Gender, int Age, DateTimeOffset BirthDate, DeptId? DeptId, string DeptName); + +public record UserLoginInfoQueryDto(UserId UserId, string Name, string Email, string PasswordHash, IEnumerable UserRoles); + +public class UserQueryInput : PageRequest +{ + public string? Keyword { get; set; } + public int? Status { get; set; } +} + +public class UserQuery(ApplicationDbContext applicationDbContext, IMemoryCache memoryCache) : IQuery +{ + private DbSet UserSet { get; } = applicationDbContext.Users; + private const string UserCacheKeyPrefix = "user:"; + private static readonly TimeSpan UserCacheExpiry = TimeSpan.FromMinutes(10); + +//#if (UseMongoDB) + /// + /// 根据刷新令牌获取用户ID + /// MongoDB 不支持 SelectMany 跨集合导航,改为直接查询 RefreshTokens 集合 + /// + public async Task GetUserIdByRefreshTokenAsync(string refreshToken, CancellationToken cancellationToken) + { + var userId = await applicationDbContext.Set() + .AsNoTracking() + .Where(t => t.Token == refreshToken) + .Select(t => t.UserId) + .SingleOrDefaultAsync(cancellationToken); + + return userId ?? throw new KnownException("无效的令牌", ErrorCodes.InvalidToken); + } +//#else + public async Task GetUserIdByRefreshTokenAsync(string refreshToken, CancellationToken cancellationToken) + { + return await UserSet.AsNoTracking() + .SelectMany(u => u.RefreshTokens) + .Where(t => t.Token == refreshToken) + .Select(t => t.UserId) + .SingleOrDefaultAsync(cancellationToken) + ?? throw new KnownException("无效的令牌", ErrorCodes.InvalidToken); + } +//#endif + + public async Task DoesUserExist(string username, CancellationToken cancellationToken) + { + return await UserSet.AsNoTracking() + .AnyAsync(u => u.Name == username, cancellationToken: cancellationToken); + } + + public async Task DoesUserExist(UserId userId, CancellationToken cancellationToken) + { + return await UserSet.AsNoTracking() + .AnyAsync(u => u.Id == userId, cancellationToken: cancellationToken); + } + + public async Task DoesEmailExist(string email, CancellationToken cancellationToken) + { + return await UserSet.AsNoTracking() + .AnyAsync(u => u.Email == email, cancellationToken: cancellationToken); + } + + /// + /// 根据ID获取用户信息(带缓存) + /// + public async Task GetUserByIdAsync(UserId userId, CancellationToken cancellationToken) + { + var cacheKey = $"{UserCacheKeyPrefix}{userId}"; + + return await memoryCache.GetOrCreateAsync(cacheKey, async entry => + { + entry.AbsoluteExpirationRelativeToNow = UserCacheExpiry; + +//#if (UseMongoDB) + // MongoDB 不支持在 Select 中投影跨集合导航,拆为多次查询 + var user = await UserSet + .IgnoreAutoIncludes() + .AsNoTracking() + .Where(u => u.Id == userId) + .Select(u => new + { + u.Id, + u.Name, + u.Phone, + u.RealName, + u.Status, + u.Email, + u.CreatedAt, + u.Gender, + u.Age, + u.BirthDate + }) + .FirstOrDefaultAsync(cancellationToken); + + if (user == null) + return null; + + var roles = await applicationDbContext.UserRoles + .AsNoTracking() + .Where(ur => ur.UserId == userId) + .Select(ur => ur.RoleName) + .ToListAsync(cancellationToken); + + var dept = await applicationDbContext.UserDepts + .AsNoTracking() + .Where(ud => ud.UserId == userId) + .Select(ud => new { ud.DeptId, ud.DeptName }) + .FirstOrDefaultAsync(cancellationToken); + + return new UserInfoQueryDto( + user.Id, + user.Name, + user.Phone, + roles, + user.RealName, + user.Status, + user.Email, + user.CreatedAt, + user.Gender, + user.Age, + user.BirthDate, + dept?.DeptId, + dept?.DeptName ?? string.Empty); +//#else + return await UserSet.AsNoTracking() + .Where(u => u.Id == userId) + .Select(au => new UserInfoQueryDto( + au.Id, + au.Name, + au.Phone, + au.Roles.Select(r => r.RoleName), + au.RealName, + au.Status, + au.Email, + au.CreatedAt, + au.Gender, + au.Age, + au.BirthDate, + au.Dept != null ? au.Dept.DeptId : null, + au.Dept != null ? au.Dept.DeptName : string.Empty)) + .FirstOrDefaultAsync(cancellationToken); +//#endif + }); + } + +//#if (UseMongoDB) + /// + /// 根据角色ID获取所有用户ID列表 + /// MongoDB 不支持在 Where 中使用跨集合导航,改为先查 UserRoles,再获取 UserIds + /// + public async Task> GetUserIdsByRoleIdAsync(RoleId roleId, CancellationToken cancellationToken = default) + { + return await applicationDbContext.UserRoles + .AsNoTracking() + .Where(ur => ur.RoleId == roleId) + .Select(ur => ur.UserId) + .Distinct() + .ToListAsync(cancellationToken); + } +//#else + public async Task> GetUserIdsByRoleIdAsync(RoleId roleId, CancellationToken cancellationToken = default) + { + return await UserSet.AsNoTracking() + .Where(u => u.Roles.Any(r => r.RoleId == roleId)) + .Select(u => u.Id) + .ToListAsync(cancellationToken); + } +//#endif + + /// + /// 根据部门ID获取所有用户ID列表 + /// + /// 部门ID + /// 取消令牌 + /// 属于指定部门的所有用户ID列表 +//#if (UseMongoDB) + /// MongoDB 不支持在 Where 中使用跨集合导航,改为直接查 UserDepts + public async Task> GetUserIdsByDeptIdAsync(DeptId deptId, CancellationToken cancellationToken = default) + { + return await applicationDbContext.UserDepts + .AsNoTracking() + .Where(ud => ud.DeptId == deptId) + .Select(ud => ud.UserId) + .ToListAsync(cancellationToken); + } +//#else + public async Task> GetUserIdsByDeptIdAsync(DeptId deptId, CancellationToken cancellationToken = default) + { + return await UserSet.AsNoTracking() + .Where(u => u.Dept != null && u.Dept.DeptId == deptId) + .Select(u => u.Id) + .ToListAsync(cancellationToken); + } +//#endif + +//#if (UseMongoDB) + /// + /// 获取登录用用户信息。MongoDB 不支持在 Select 中投影跨集合导航 u.Roles, + /// 故拆为两次查询:先查 User 基础字段,再按 UserId 查 UserRoles。 + /// + public async Task GetUserInfoForLoginAsync(string name, CancellationToken cancellationToken) + { + var user = await UserSet + .IgnoreAutoIncludes() + .AsNoTracking() + .Where(u => u.Name == name) + .Select(u => new { u.Id, u.Name, u.Email, u.PasswordHash }) + .FirstOrDefaultAsync(cancellationToken); + + if (user == null) + return null; + + var roles = await applicationDbContext.UserRoles + .AsNoTracking() + .Where(ur => ur.UserId == user.Id) + .ToListAsync(cancellationToken); + + return new UserLoginInfoQueryDto(user.Id, user.Name, user.Email, user.PasswordHash, roles); + } + + /// + /// 按 UserId 获取登录用用户信息。同上,避免投影 u.Roles,拆为两次查询。 + /// + public async Task GetUserInfoForLoginByIdAsync(UserId userId, CancellationToken cancellationToken) + { + var user = await UserSet + .IgnoreAutoIncludes() + .AsNoTracking() + .Where(u => u.Id == userId) + .Select(u => new { u.Id, u.Name, u.Email, u.PasswordHash }) + .FirstOrDefaultAsync(cancellationToken); + + if (user == null) + return null; + + var roles = await applicationDbContext.UserRoles + .AsNoTracking() + .Where(ur => ur.UserId == user.Id) + .ToListAsync(cancellationToken); + + return new UserLoginInfoQueryDto(user.Id, user.Name, user.Email, user.PasswordHash, roles); + } +//#else + public async Task GetUserInfoForLoginAsync(string name, CancellationToken cancellationToken) + { + return await UserSet + .Where(u => u.Name == name) + .Select(u => new UserLoginInfoQueryDto(u.Id, u.Name, u.Email, u.PasswordHash, u.Roles)) + .FirstOrDefaultAsync(cancellationToken); + } + + public async Task GetUserInfoForLoginByIdAsync(UserId userId, CancellationToken cancellationToken) + { + return await UserSet + .Where(u => u.Id == userId) + .Select(u => new UserLoginInfoQueryDto(u.Id, u.Name, u.Email, u.PasswordHash, u.Roles)) + .FirstOrDefaultAsync(cancellationToken); + } +//#endif + +//#if (UseMongoDB) + /// + /// 获取所有用户(分页) + /// MongoDB 不支持在 Select 中投影跨集合导航,拆为多次查询 + /// + public async Task> GetAllUsersAsync(UserQueryInput query, CancellationToken cancellationToken) + { + var queryable = UserSet + .IgnoreAutoIncludes() + .AsNoTracking(); + + if (!string.IsNullOrWhiteSpace(query.Keyword)) + { + queryable = queryable.Where(u => u.Name.Contains(query.Keyword!) || u.Email.Contains(query.Keyword!)); + } + + if (query.Status.HasValue) + { + queryable = queryable.Where(u => u.Status == query.Status); + } + + var pagedUsers = await queryable + .OrderByDescending(u => u.Id) + .Select(u => new + { + u.Id, + u.Name, + u.Phone, + u.RealName, + u.Status, + u.Email, + u.CreatedAt, + u.Gender, + u.Age, + u.BirthDate + }) + .ToPagedDataAsync(query, cancellationToken); + + if (pagedUsers.Items == null || !pagedUsers.Items.Any()) + { + return new PagedData( + Enumerable.Empty(), + pagedUsers.Total, + pagedUsers.PageIndex, + pagedUsers.PageSize); + } + + var userIds = pagedUsers.Items.Select(u => u.Id).ToList(); + + var allRoles = await applicationDbContext.UserRoles + .AsNoTracking() + .Where(ur => userIds.Contains(ur.UserId)) + .ToListAsync(cancellationToken); + var rolesByUserId = allRoles + .GroupBy(ur => ur.UserId) + .ToDictionary(g => g.Key, g => g.Select(ur => ur.RoleName).ToList()); + + var allDepts = await applicationDbContext.UserDepts + .AsNoTracking() + .Where(ud => userIds.Contains(ud.UserId)) + .ToListAsync(cancellationToken); + var deptByUserId = allDepts + .ToDictionary(ud => ud.UserId, ud => new { ud.DeptId, ud.DeptName }); + + var userInfoDtos = pagedUsers.Items.Select(u => + { + var dept = deptByUserId.GetValueOrDefault(u.Id); + return new UserInfoQueryDto( + u.Id, + u.Name, + u.Phone, + rolesByUserId.GetValueOrDefault(u.Id, []), + u.RealName, + u.Status, + u.Email, + u.CreatedAt, + u.Gender, + u.Age, + u.BirthDate, + dept?.DeptId, + dept?.DeptName ?? string.Empty); + }).ToList(); + + return new PagedData( + userInfoDtos, + pagedUsers.Total, + pagedUsers.PageIndex, + pagedUsers.PageSize); + } +//#else + public async Task> GetAllUsersAsync(UserQueryInput query, CancellationToken cancellationToken) + { + var queryable = UserSet.AsNoTracking(); + + if (!string.IsNullOrWhiteSpace(query.Keyword)) + { + queryable = queryable.Where(u => u.Name.Contains(query.Keyword!) || u.Email.Contains(query.Keyword!)); + } + + if (query.Status.HasValue) + { + queryable = queryable.Where(u => u.Status == query.Status); + } + + return await queryable + .OrderByDescending(u => u.Id) + .Select(u => new UserInfoQueryDto( + u.Id, + u.Name, + u.Phone, + u.Roles.Select(r => r.RoleName), + u.RealName, + u.Status, + u.Email, + u.CreatedAt, + u.Gender, + u.Age, + u.BirthDate, + u.Dept != null ? u.Dept.DeptId : null, + u.Dept != null ? u.Dept.DeptName : string.Empty)) + .ToPagedDataAsync(query, cancellationToken); + } +//#endif +} + diff --git a/template/src/ABC.Template.Web/Endpoints/DemoEndpoints/ContextEndpoint.cs b/template/src/ABC.Template.Web/Endpoints/DemoEndpoints/ContextEndpoint.cs deleted file mode 100644 index c190d413..00000000 --- a/template/src/ABC.Template.Web/Endpoints/DemoEndpoints/ContextEndpoint.cs +++ /dev/null @@ -1,19 +0,0 @@ -using FastEndpoints; -using Microsoft.AspNetCore.Authorization; -using NetCorePal.Context; -using NetCorePal.Extensions.Dto; - -namespace ABC.Template.Web.Endpoints.DemoEndpoints; - -[Tags("Demo")] -[HttpPost("/demo/context")] -[AllowAnonymous] -public class ContextEndpoint(IContextAccessor contextAccessor) : EndpointWithoutRequest> -{ - public override Task HandleAsync(CancellationToken ct) - { - var tenantContext = contextAccessor.GetContext(); - var result = (tenantContext == null ? "" : tenantContext.TenantId); - return Send.OkAsync(result.AsResponseData(), cancellation: ct); - } -} \ No newline at end of file diff --git a/template/src/ABC.Template.Web/Endpoints/DemoEndpoints/JsonEndpoint.cs b/template/src/ABC.Template.Web/Endpoints/DemoEndpoints/JsonEndpoint.cs deleted file mode 100644 index 87debfb6..00000000 --- a/template/src/ABC.Template.Web/Endpoints/DemoEndpoints/JsonEndpoint.cs +++ /dev/null @@ -1,24 +0,0 @@ -using FastEndpoints; -using Microsoft.AspNetCore.Authorization; -using NetCorePal.Extensions.Dto; -using NetCorePal.Extensions.Primitives; - -namespace ABC.Template.Web.Endpoints.DemoEndpoints; - -public partial record MyId : IGuidStronglyTypedId; - -public record JsonRequest(MyId Id, string Name, DateTime Time); - -public record JsonResponse(MyId Id, string Name, DateTime Time); - -[Tags("Demo")] -[HttpPost("/demo/json")] -[AllowAnonymous] -public class JsonEndpoint : Endpoint> -{ - public override Task HandleAsync(JsonRequest req, CancellationToken ct) - { - var response = new JsonResponse(req.Id, req.Name, req.Time); - return Send.OkAsync(response.AsResponseData(), cancellation: ct); - } -} \ No newline at end of file diff --git a/template/src/ABC.Template.Web/Endpoints/DemoEndpoints/LockEndpoint.cs b/template/src/ABC.Template.Web/Endpoints/DemoEndpoints/LockEndpoint.cs deleted file mode 100644 index 104ab2f3..00000000 --- a/template/src/ABC.Template.Web/Endpoints/DemoEndpoints/LockEndpoint.cs +++ /dev/null @@ -1,39 +0,0 @@ -using FastEndpoints; -using Microsoft.AspNetCore.Authorization; -using NetCorePal.Extensions.DistributedLocks; -using NetCorePal.Extensions.Dto; - -namespace ABC.Template.Web.Endpoints.DemoEndpoints; - -[Tags("Demo")] -[HttpGet("/demo/lock")] -[AllowAnonymous] -public class LockEndpoint(IDistributedLock distributedLock) : EndpointWithoutRequest> -{ - private static bool _isRunning = false; - - public override async Task HandleAsync(CancellationToken ct) - { - if (_isRunning) - { - await Send.OkAsync(true.AsResponseData(), cancellation: ct); - return; - } - - await using var handle = await distributedLock.AcquireAsync("lock"); - if (_isRunning) - { - await Send.OkAsync(true.AsResponseData(), cancellation: ct); - return; - } - -#pragma warning disable S2696 - _isRunning = true; -#pragma warning restore S2696 - await Task.Delay(1000, ct); -#pragma warning disable S2696 - _isRunning = false; -#pragma warning restore S2696 - await Send.OkAsync(false.AsResponseData(), cancellation: ct); - } -} diff --git a/template/src/ABC.Template.Web/Endpoints/DemoEndpoints/ValidatorEndpoint.cs b/template/src/ABC.Template.Web/Endpoints/DemoEndpoints/ValidatorEndpoint.cs deleted file mode 100644 index c8f7c604..00000000 --- a/template/src/ABC.Template.Web/Endpoints/DemoEndpoints/ValidatorEndpoint.cs +++ /dev/null @@ -1,22 +0,0 @@ -using ABC.Template.Web.Application.Commands.Demos; -using FastEndpoints; -using MediatR; -using Microsoft.AspNetCore.Authorization; -using NetCorePal.Extensions.Dto; - -namespace ABC.Template.Web.Endpoints.DemoEndpoints; - -public record ValidatorRequest(string Name, int Price); - -[Tags("Demo")] -[HttpPost("/demo/validator")] -[AllowAnonymous] -public class ValidatorEndpoint(IMediator mediator) : Endpoint -{ - public override async Task HandleAsync(ValidatorRequest req, CancellationToken ct) - { - var cmd = new ValidatorCommand(req.Name, req.Price); - await mediator.Send(cmd, ct); - await Send.OkAsync(true.AsResponseData(), cancellation: ct); - } -} \ No newline at end of file diff --git a/template/src/ABC.Template.Web/Endpoints/HelloEndpoint.cs b/template/src/ABC.Template.Web/Endpoints/HelloEndpoint.cs new file mode 100644 index 00000000..19688a08 --- /dev/null +++ b/template/src/ABC.Template.Web/Endpoints/HelloEndpoint.cs @@ -0,0 +1,25 @@ +using FastEndpoints; +using FastEndpoints.Swagger; +using Microsoft.AspNetCore.Authorization; +using NetCorePal.Extensions.Dto; + +namespace ABC.Template.Web.Endpoints; + +/// +/// Hello +/// +public class HelloEndpoint : EndpointWithoutRequest> +{ + public override void Configure() + { + Tags("Hello"); + Description(b => b.AutoTagOverride("Hello")); + Get("/api/hello"); + AllowAnonymous(); + } + + public override Task HandleAsync(CancellationToken ct) + { + return Send.OkAsync("hello".AsResponseData(), cancellation: ct); + } +} diff --git a/template/src/ABC.Template.Web/Endpoints/Identity/Admin/DeptEndpoints/CreateDeptEndpoint.cs b/template/src/ABC.Template.Web/Endpoints/Identity/Admin/DeptEndpoints/CreateDeptEndpoint.cs new file mode 100644 index 00000000..4222bae0 --- /dev/null +++ b/template/src/ABC.Template.Web/Endpoints/Identity/Admin/DeptEndpoints/CreateDeptEndpoint.cs @@ -0,0 +1,50 @@ +using FastEndpoints; +using FastEndpoints.Swagger; +using MediatR; +using Microsoft.AspNetCore.Authentication.JwtBearer; +using ABC.Template.Domain.AggregatesModel.DeptAggregate; +using ABC.Template.Web.Application.Commands.Identity.Admin.DeptCommands; +using ABC.Template.Web.AppPermissions; + +namespace ABC.Template.Web.Endpoints.Identity.Admin.DeptEndpoints; + +/// +/// 创建部门的请求模型 +/// +/// 部门名称 +/// 备注 +/// 父级部门ID,可为空表示顶级部门 +/// 状态(0=禁用,1=启用) +public record CreateDeptRequest(string Name, string Remark, DeptId? ParentId, int Status); + +/// +/// 创建部门的响应模型 +/// +/// 新创建的部门ID +/// 部门名称 +/// 备注 +public record CreateDeptResponse(DeptId Id, string Name, string Remark); + +/// +/// 创建部门 +/// +/// +public class CreateDeptEndpoint(IMediator mediator) : Endpoint> +{ + public override void Configure() + { + Tags("Depts"); + Description(b => b.AutoTagOverride("Depts")); + Post("/api/admin/dept"); + AuthSchemes(JwtBearerDefaults.AuthenticationScheme); + Permissions(PermissionCodes.AllApiAccess, PermissionCodes.DeptCreate); + } + + public override async Task HandleAsync(CreateDeptRequest req, CancellationToken ct) + { + var cmd = new CreateDeptCommand(req.Name, req.Remark, req.ParentId, req.Status); + var deptId = await mediator.Send(cmd, ct); + var response = new CreateDeptResponse(deptId, req.Name, req.Remark); + await Send.OkAsync(response.AsResponseData(), cancellation: ct); + } +} diff --git a/template/src/ABC.Template.Web/Endpoints/Identity/Admin/DeptEndpoints/DeleteDeptEndpoint.cs b/template/src/ABC.Template.Web/Endpoints/Identity/Admin/DeptEndpoints/DeleteDeptEndpoint.cs new file mode 100644 index 00000000..87898310 --- /dev/null +++ b/template/src/ABC.Template.Web/Endpoints/Identity/Admin/DeptEndpoints/DeleteDeptEndpoint.cs @@ -0,0 +1,45 @@ +using FastEndpoints; +using FastEndpoints.Swagger; +using MediatR; +using Microsoft.AspNetCore.Authentication.JwtBearer; +using ABC.Template.Domain.AggregatesModel.DeptAggregate; +using ABC.Template.Web.Application.Commands.Identity.Admin.DeptCommands; +using ABC.Template.Web.AppPermissions; + +namespace ABC.Template.Web.Endpoints.Identity.Admin.DeptEndpoints; + +/// +/// 删除部门的请求模型 +/// +/// 部门ID +public record DeleteDeptRequest(DeptId Id); + +/// +/// 删除部门 +/// +/// +public class DeleteDeptEndpoint(IMediator mediator) : Endpoint> +{ + public override void Configure() + { + Tags("Depts"); + Description(b => b.AutoTagOverride("Depts")); + Delete("/api/admin/dept/{id}"); + AuthSchemes(JwtBearerDefaults.AuthenticationScheme); + Permissions(PermissionCodes.AllApiAccess, PermissionCodes.DeptDelete); + } + + /// + /// 处理HTTP请求的核心方法 + /// 删除指定的部门 + /// + /// 取消令牌,用于支持异步操作的取消 + /// 异步任务 + public override async Task HandleAsync(DeleteDeptRequest request,CancellationToken ct) + { + + var command = new DeleteDeptCommand(request.Id); + await mediator.Send(command, ct); + await Send.OkAsync(true.AsResponseData(), cancellation: ct); + } +} diff --git a/template/src/ABC.Template.Web/Endpoints/Identity/Admin/DeptEndpoints/GetDeptEndpoint.cs b/template/src/ABC.Template.Web/Endpoints/Identity/Admin/DeptEndpoints/GetDeptEndpoint.cs new file mode 100644 index 00000000..119bc317 --- /dev/null +++ b/template/src/ABC.Template.Web/Endpoints/Identity/Admin/DeptEndpoints/GetDeptEndpoint.cs @@ -0,0 +1,70 @@ +using FastEndpoints; +using FastEndpoints.Swagger; +using Microsoft.AspNetCore.Authentication.JwtBearer; +using ABC.Template.Domain.AggregatesModel.DeptAggregate; +using ABC.Template.Web.Application.Queries; +using ABC.Template.Web.AppPermissions; + +namespace ABC.Template.Web.Endpoints.Identity.Admin.DeptEndpoints; + +/// +/// 获取单个部门的请求模型 +/// +/// 部门ID +public record GetDeptRequest(DeptId Id); + +/// +/// 获取单个部门的响应模型 +/// +/// 部门ID +/// 部门名称 +/// 备注 +/// 父级部门ID +/// 状态(0=禁用,1=启用) +/// 创建时间 +public record GetDeptResponse(DeptId Id, string Name, string Remark, DeptId ParentId, int Status, DateTimeOffset CreatedAt); + +/// +/// 获取部门 +/// +/// +public class GetDeptEndpoint(DeptQuery deptQuery) : Endpoint> +{ + + public override void Configure() + { + Tags("Depts"); + Description(b => b.AutoTagOverride("Depts")); + Get("/api/admin/dept/{id}"); + AuthSchemes(JwtBearerDefaults.AuthenticationScheme); + Permissions(PermissionCodes.AllApiAccess, PermissionCodes.DeptView); + } + + public override async Task HandleAsync(GetDeptRequest req, CancellationToken ct) + { + + + // 通过查询服务获取部门详细信息 + var dept = await deptQuery.GetDeptByIdAsync(req.Id, ct); + + // 验证部门是否存在 + if (dept == null) + { + await Send.NotFoundAsync(ct); + } + else + { + // 创建响应对象 + var response = new GetDeptResponse( + dept.Id, + dept.Name, + dept.Remark, + dept.ParentId, + dept.Status, + dept.CreatedAt + ); + // 返回成功响应,使用统一的响应数据格式包装 + await Send.OkAsync(response.AsResponseData(), cancellation: ct); + } + } +} diff --git a/template/src/ABC.Template.Web/Endpoints/Identity/Admin/DeptEndpoints/GetDeptTreeEndpoint.cs b/template/src/ABC.Template.Web/Endpoints/Identity/Admin/DeptEndpoints/GetDeptTreeEndpoint.cs new file mode 100644 index 00000000..1fb87ee6 --- /dev/null +++ b/template/src/ABC.Template.Web/Endpoints/Identity/Admin/DeptEndpoints/GetDeptTreeEndpoint.cs @@ -0,0 +1,37 @@ +using FastEndpoints; +using FastEndpoints.Swagger; +using Microsoft.AspNetCore.Authentication.JwtBearer; +using ABC.Template.Web.Application.Queries; +using ABC.Template.Web.AppPermissions; + +namespace ABC.Template.Web.Endpoints.Identity.Admin.DeptEndpoints; + +/// +/// 获取部门树的请求模型 +/// +/// 是否包含非激活的部门 +public record GetDeptTreeRequest(bool IncludeInactive = false); + +/// +/// 获取部门树 +/// +/// +public class GetDeptTreeEndpoint(DeptQuery deptQuery) : Endpoint>> +{ + + public override void Configure() + { + Tags("Depts"); + Description(b => b.AutoTagOverride("Depts")); + Get("/api/admin/dept/tree"); + AuthSchemes(JwtBearerDefaults.AuthenticationScheme); + Permissions(PermissionCodes.AllApiAccess, PermissionCodes.DeptView); + } + + + public override async Task HandleAsync(GetDeptTreeRequest req, CancellationToken ct) + { + var tree = await deptQuery.GetDeptTreeAsync(req.IncludeInactive, ct); + await Send.OkAsync(tree.AsResponseData(), cancellation: ct); + } +} diff --git a/template/src/ABC.Template.Web/Endpoints/Identity/Admin/DeptEndpoints/UpdateDeptEndpoint.cs b/template/src/ABC.Template.Web/Endpoints/Identity/Admin/DeptEndpoints/UpdateDeptEndpoint.cs new file mode 100644 index 00000000..d4c0107e --- /dev/null +++ b/template/src/ABC.Template.Web/Endpoints/Identity/Admin/DeptEndpoints/UpdateDeptEndpoint.cs @@ -0,0 +1,49 @@ +using FastEndpoints; +using FastEndpoints.Swagger; +using MediatR; +using Microsoft.AspNetCore.Authentication.JwtBearer; +using ABC.Template.Domain.AggregatesModel.DeptAggregate; +using ABC.Template.Web.Application.Commands.Identity.Admin.DeptCommands; +using ABC.Template.Web.AppPermissions; + +namespace ABC.Template.Web.Endpoints.Identity.Admin.DeptEndpoints; + +/// +/// 更新部门的请求模型 +/// +/// 部门ID +/// 部门名称 +/// 备注 +/// 父级部门ID,可为空表示顶级部门 +/// 状态(0=禁用,1=启用) +public record UpdateDeptRequest(DeptId Id, string Name, string Remark, DeptId? ParentId, int Status); + +/// +/// 更新部门 +/// +/// +public class UpdateDeptEndpoint(IMediator mediator) : Endpoint> +{ + public override void Configure() + { + Tags("Depts"); + Description(b => b.AutoTagOverride("Depts")); + Put("/api/admin/dept"); + AuthSchemes(JwtBearerDefaults.AuthenticationScheme); + Permissions(PermissionCodes.AllApiAccess, PermissionCodes.DeptEdit); + } + + public override async Task HandleAsync(UpdateDeptRequest req, CancellationToken ct) + { + // 如果父级ID为空,则设置为根部门(ID为0) + var command = new UpdateDeptCommand( + req.Id, + req.Name, + req.Remark, + req.ParentId ?? new DeptId(0), + req.Status + ); + await mediator.Send(command, ct); + await Send.OkAsync(true.AsResponseData(), cancellation: ct); + } +} diff --git a/template/src/ABC.Template.Web/Endpoints/Identity/Admin/RoleEndpoints/ActivateRoleEndpoint.cs b/template/src/ABC.Template.Web/Endpoints/Identity/Admin/RoleEndpoints/ActivateRoleEndpoint.cs new file mode 100644 index 00000000..638d9335 --- /dev/null +++ b/template/src/ABC.Template.Web/Endpoints/Identity/Admin/RoleEndpoints/ActivateRoleEndpoint.cs @@ -0,0 +1,38 @@ +using FastEndpoints; +using FastEndpoints.Swagger; +using MediatR; +using Microsoft.AspNetCore.Authentication.JwtBearer; +using ABC.Template.Domain.AggregatesModel.RoleAggregate; +using ABC.Template.Web.Application.Commands.Identity.Admin.RoleCommands; +using ABC.Template.Web.AppPermissions; + +namespace ABC.Template.Web.Endpoints.Identity.Admin.RoleEndpoints; + +/// +/// 激活角色的请求模型 +/// +/// 要激活的角色ID +public record ActivateRoleRequest(RoleId RoleId); + +/// +/// 激活角色 +/// +/// +public class ActivateRoleEndpoint(IMediator mediator) : Endpoint> +{ + public override void Configure() + { + Tags("Roles"); + Description(b => b.AutoTagOverride("Roles")); + Put("/api/admin/roles/activate"); + AuthSchemes(JwtBearerDefaults.AuthenticationScheme); + Permissions(PermissionCodes.AllApiAccess, PermissionCodes.RoleEdit); + } + + public override async Task HandleAsync(ActivateRoleRequest req, CancellationToken ct) + { + var cmd = new ActivateRoleCommand(req.RoleId); + await mediator.Send(cmd, ct); + await Send.OkAsync(true.AsResponseData(), cancellation: ct); + } +} diff --git a/template/src/ABC.Template.Web/Endpoints/Identity/Admin/RoleEndpoints/CreateRoleEndpoint.cs b/template/src/ABC.Template.Web/Endpoints/Identity/Admin/RoleEndpoints/CreateRoleEndpoint.cs new file mode 100644 index 00000000..339ea519 --- /dev/null +++ b/template/src/ABC.Template.Web/Endpoints/Identity/Admin/RoleEndpoints/CreateRoleEndpoint.cs @@ -0,0 +1,50 @@ +using FastEndpoints; +using FastEndpoints.Swagger; +using MediatR; +using Microsoft.AspNetCore.Authentication.JwtBearer; +using ABC.Template.Domain.AggregatesModel.RoleAggregate; +using ABC.Template.Web.Application.Commands.Identity.Admin.RoleCommands; +using ABC.Template.Web.AppPermissions; + +namespace ABC.Template.Web.Endpoints.Identity.Admin.RoleEndpoints; + +/// +/// 创建角色的请求模型 +/// +/// 角色名称 +/// 角色描述 +/// 权限代码列表 +public record CreateRoleRequest(string Name, string Description, IEnumerable PermissionCodes); + +/// +/// 创建角色的响应模型 +/// +/// 新创建的角色ID +/// 角色名称 +/// 角色描述 +public record CreateRoleResponse(RoleId RoleId, string Name, string Description); + +/// +/// 创建角色 +/// +/// +public class CreateRoleEndpoint(IMediator mediator) : Endpoint> +{ + public override void Configure() + { + Tags("Roles"); + Description(b => b.AutoTagOverride("Roles")); + Post("/api/admin/roles"); + AuthSchemes(JwtBearerDefaults.AuthenticationScheme); + Permissions(PermissionCodes.AllApiAccess, PermissionCodes.RoleCreate); + } + + public override async Task HandleAsync(CreateRoleRequest req, CancellationToken ct) + { + var cmd = new CreateRoleCommand(req.Name, req.Description, req.PermissionCodes); + var result = await mediator.Send(cmd, ct); + var response = new CreateRoleResponse(result, req.Name, req.Description); + await Send.OkAsync(response.AsResponseData(), cancellation: ct); + } +} + diff --git a/template/src/ABC.Template.Web/Endpoints/Identity/Admin/RoleEndpoints/DeactivateRoleEndpoint.cs b/template/src/ABC.Template.Web/Endpoints/Identity/Admin/RoleEndpoints/DeactivateRoleEndpoint.cs new file mode 100644 index 00000000..0486baa7 --- /dev/null +++ b/template/src/ABC.Template.Web/Endpoints/Identity/Admin/RoleEndpoints/DeactivateRoleEndpoint.cs @@ -0,0 +1,38 @@ +using FastEndpoints; +using FastEndpoints.Swagger; +using MediatR; +using Microsoft.AspNetCore.Authentication.JwtBearer; +using ABC.Template.Domain.AggregatesModel.RoleAggregate; +using ABC.Template.Web.Application.Commands.Identity.Admin.RoleCommands; +using ABC.Template.Web.AppPermissions; + +namespace ABC.Template.Web.Endpoints.Identity.Admin.RoleEndpoints; + +/// +/// 停用角色的请求模型 +/// +/// 要停用的角色ID +public record DeactivateRoleRequest(RoleId RoleId); + +/// +/// 停用角色 +/// +/// +public class DeactivateRoleEndpoint(IMediator mediator) : Endpoint> +{ + public override void Configure() + { + Tags("Roles"); + Description(b => b.AutoTagOverride("Roles")); + Put("/api/admin/roles/deactivate"); + AuthSchemes(JwtBearerDefaults.AuthenticationScheme); + Permissions(PermissionCodes.AllApiAccess, PermissionCodes.RoleEdit); + } + + public override async Task HandleAsync(DeactivateRoleRequest req, CancellationToken ct) + { + var cmd = new DeactivateRoleCommand(req.RoleId); + await mediator.Send(cmd, ct); + await Send.OkAsync(true.AsResponseData(), cancellation: ct); + } +} diff --git a/template/src/ABC.Template.Web/Endpoints/Identity/Admin/RoleEndpoints/DeleteRoleEndpoint.cs b/template/src/ABC.Template.Web/Endpoints/Identity/Admin/RoleEndpoints/DeleteRoleEndpoint.cs new file mode 100644 index 00000000..5aef3321 --- /dev/null +++ b/template/src/ABC.Template.Web/Endpoints/Identity/Admin/RoleEndpoints/DeleteRoleEndpoint.cs @@ -0,0 +1,40 @@ +using FastEndpoints; +using FastEndpoints.Swagger; +using MediatR; +using Microsoft.AspNetCore.Authentication.JwtBearer; +using ABC.Template.Domain.AggregatesModel.RoleAggregate; +using ABC.Template.Web.Application.Commands.Identity.Admin.RoleCommands; +using ABC.Template.Web.AppPermissions; + +namespace ABC.Template.Web.Endpoints.Identity.Admin.RoleEndpoints; + +/// +/// 删除角色的请求模型 +/// +/// 要删除的角色ID +public record DeleteRoleRequest(RoleId RoleId); + +/// +/// 删除角色 +/// +/// +public class DeleteRoleEndpoint(IMediator mediator) : Endpoint> +{ + public override void Configure() + { + Tags("Roles"); + Description(b => b.AutoTagOverride("Roles")); + Delete("/api/admin/roles/{roleId}"); + AuthSchemes(JwtBearerDefaults.AuthenticationScheme); + Permissions(PermissionCodes.AllApiAccess, PermissionCodes.RoleDelete); + } + + + public override async Task HandleAsync(DeleteRoleRequest request, CancellationToken ct) + { + var command = new DeleteRoleCommand(request.RoleId); + await mediator.Send(command, ct); + await Send.OkAsync(true.AsResponseData(), cancellation: ct); + } +} + diff --git a/template/src/ABC.Template.Web/Endpoints/Identity/Admin/RoleEndpoints/GetAllRolesEndpoint.cs b/template/src/ABC.Template.Web/Endpoints/Identity/Admin/RoleEndpoints/GetAllRolesEndpoint.cs new file mode 100644 index 00000000..40b2dc53 --- /dev/null +++ b/template/src/ABC.Template.Web/Endpoints/Identity/Admin/RoleEndpoints/GetAllRolesEndpoint.cs @@ -0,0 +1,31 @@ +using FastEndpoints; +using FastEndpoints.Swagger; +using Microsoft.AspNetCore.Authentication.JwtBearer; +using ABC.Template.Web.Application.Queries; +using ABC.Template.Web.AppPermissions; + +namespace ABC.Template.Web.Endpoints.Identity.Admin.RoleEndpoints; + +/// +/// 获取所有角色 +/// +/// +public class GetAllRolesEndpoint(RoleQuery roleQuery) : Endpoint>> +{ + + public override void Configure() + { + Tags("Roles"); + Description(b => b.AutoTagOverride("Roles")); + Get("/api/admin/roles"); + AuthSchemes(JwtBearerDefaults.AuthenticationScheme); + Permissions(PermissionCodes.AllApiAccess, PermissionCodes.RoleView); + } + + public override async Task HandleAsync(RoleQueryInput req, CancellationToken ct) + { + var roleInfo = await roleQuery.GetAllRolesAsync(req, ct); + await Send.OkAsync(roleInfo.AsResponseData(), cancellation: ct); + } +} + diff --git a/template/src/ABC.Template.Web/Endpoints/Identity/Admin/RoleEndpoints/GetRoleEndpoint.cs b/template/src/ABC.Template.Web/Endpoints/Identity/Admin/RoleEndpoints/GetRoleEndpoint.cs new file mode 100644 index 00000000..96bd97ca --- /dev/null +++ b/template/src/ABC.Template.Web/Endpoints/Identity/Admin/RoleEndpoints/GetRoleEndpoint.cs @@ -0,0 +1,49 @@ +using FastEndpoints; +using FastEndpoints.Swagger; +using Microsoft.AspNetCore.Authentication.JwtBearer; +using ABC.Template.Domain.AggregatesModel.RoleAggregate; +using ABC.Template.Web.Application.Queries; +using ABC.Template.Web.AppPermissions; + +namespace ABC.Template.Web.Endpoints.Identity.Admin.RoleEndpoints; + +/// +/// 获取角色信息的请求模型 +/// +/// 要查询的角色ID +public record GetRoleRequest(RoleId Id); + +/// +/// 获取角色 +/// +/// +public class GetRoleEndpoint(RoleQuery roleQuery) : Endpoint> +{ + + public override void Configure() + { + Tags("Roles"); + Description(b => b.AutoTagOverride("Roles")); + Get("/api/admin/roles/{id}"); + AuthSchemes(JwtBearerDefaults.AuthenticationScheme); + Permissions(PermissionCodes.AllApiAccess, PermissionCodes.RoleView); + } + + + public override async Task HandleAsync(GetRoleRequest req, CancellationToken ct) + { + // 通过查询服务获取角色详细信息 + var roleInfo = await roleQuery.GetRoleByIdAsync(req.Id, ct); + + // 验证角色是否存在 + if (roleInfo == null) + { + await Send.NotFoundAsync(ct); + } + else + { + await Send.OkAsync(roleInfo!.AsResponseData(), cancellation: ct); + } + } +} + diff --git a/template/src/ABC.Template.Web/Endpoints/Identity/Admin/RoleEndpoints/UpdateRoleEndpoint.cs b/template/src/ABC.Template.Web/Endpoints/Identity/Admin/RoleEndpoints/UpdateRoleEndpoint.cs new file mode 100644 index 00000000..5b753250 --- /dev/null +++ b/template/src/ABC.Template.Web/Endpoints/Identity/Admin/RoleEndpoints/UpdateRoleEndpoint.cs @@ -0,0 +1,49 @@ +using FastEndpoints; +using FastEndpoints.Swagger; +using MediatR; +using Microsoft.AspNetCore.Authentication.JwtBearer; +using ABC.Template.Domain.AggregatesModel.RoleAggregate; +using ABC.Template.Web.Application.Commands.Identity.Admin.RoleCommands; +using ABC.Template.Web.AppPermissions; + +namespace ABC.Template.Web.Endpoints.Identity.Admin.RoleEndpoints; + +/// +/// 更新角色信息的请求模型 +/// +/// 要更新的角色ID +/// 新的角色名称 +/// 新的角色描述 +/// 新的权限代码列表 +public record UpdateRoleInfoRequest(RoleId RoleId, string Name, string Description, IEnumerable PermissionCodes); + +/// +/// 更新角色 +/// +/// +public class UpdateRoleEndpoint(IMediator mediator) : Endpoint> +{ + + public override void Configure() + { + Tags("Roles"); + Description(b => b.AutoTagOverride("Roles")); + Put("/api/admin/roles/update"); + AuthSchemes(JwtBearerDefaults.AuthenticationScheme); + Permissions(PermissionCodes.AllApiAccess, PermissionCodes.RoleEdit); + } + + + public override async Task HandleAsync(UpdateRoleInfoRequest request, CancellationToken ct) + { + var cmd = new UpdateRoleInfoCommand( + request.RoleId, + request.Name, + request.Description, + request.PermissionCodes + ); + await mediator.Send(cmd, ct); + await Send.OkAsync(true.AsResponseData(), cancellation: ct); + } +} + diff --git a/template/src/ABC.Template.Web/Endpoints/Identity/Admin/UserEndpoints/AuthEndpoint.cs b/template/src/ABC.Template.Web/Endpoints/Identity/Admin/UserEndpoints/AuthEndpoint.cs new file mode 100644 index 00000000..3e9dfcbe --- /dev/null +++ b/template/src/ABC.Template.Web/Endpoints/Identity/Admin/UserEndpoints/AuthEndpoint.cs @@ -0,0 +1,25 @@ +using FastEndpoints; +using FastEndpoints.Swagger; +using Microsoft.AspNetCore.Authorization; +using NetCorePal.Extensions.Dto; + +namespace ABC.Template.Web.Endpoints.Identity.Admin.UserEndpoints; + +/// +/// 用户认证 +/// +public class AuthEndpoint : EndpointWithoutRequest> +{ + public override void Configure() + { + Tags("Users"); + Description(b => b.AutoTagOverride("Users")); + Get("/api/admin/user/auth"); + AuthSchemes("Bearer"); + } + + public override Task HandleAsync(CancellationToken ct) + { + return Send.OkAsync(true.AsResponseData(), cancellation: ct); + } +} \ No newline at end of file diff --git a/template/src/ABC.Template.Web/Endpoints/Identity/Admin/UserEndpoints/CreateUserEndpoint.cs b/template/src/ABC.Template.Web/Endpoints/Identity/Admin/UserEndpoints/CreateUserEndpoint.cs new file mode 100644 index 00000000..b3d93938 --- /dev/null +++ b/template/src/ABC.Template.Web/Endpoints/Identity/Admin/UserEndpoints/CreateUserEndpoint.cs @@ -0,0 +1,75 @@ +using FastEndpoints; +using FastEndpoints.Swagger; +using MediatR; +using Microsoft.AspNetCore.Authentication.JwtBearer; +using ABC.Template.Domain.AggregatesModel.RoleAggregate; +using ABC.Template.Domain.AggregatesModel.UserAggregate; +using ABC.Template.Domain.AggregatesModel.DeptAggregate; +using ABC.Template.Web.Application.Commands.Identity.Admin.UserCommands; +using ABC.Template.Web.Application.Queries; +using ABC.Template.Web.AppPermissions; +using ABC.Template.Web.Utils; + +namespace ABC.Template.Web.Endpoints.Identity.Admin.UserEndpoints; + +/// +/// 创建用户的请求模型 +/// +/// 用户名 +/// 邮箱地址 +/// 密码 +/// 电话号码 +/// 真实姓名 +/// 用户状态(0=禁用,1=启用) +/// 性别 +/// 出生日期 +/// 部门ID(可选) +/// 部门名称(可选) +/// 要分配的角色ID列表 +public record CreateUserRequest(string Name, string Email, string Password, string Phone, string RealName, int Status, string Gender, DateTimeOffset BirthDate, DeptId? DeptId, string? DeptName, IEnumerable RoleIds); + +/// +/// 创建用户的响应模型 +/// +/// 新创建的用户ID +/// 用户名 +/// 邮箱地址 +public record CreateUserResponse(UserId UserId, string Name, string Email); + +/// +/// 创建用户 +/// +/// +/// +public class CreateUserEndpoint(IMediator mediator, RoleQuery roleQuery) : Endpoint> +{ + public override void Configure() + { + Tags("Users"); + Description(b => b.AutoTagOverride("Users")); + Post("/api/admin/users"); + AuthSchemes(JwtBearerDefaults.AuthenticationScheme); + Permissions(PermissionCodes.AllApiAccess, PermissionCodes.UserCreate); + } + + public override async Task HandleAsync(CreateUserRequest request, CancellationToken ct) + { + var rolesToBeAssigned = await roleQuery.GetAdminRolesForAssignmentAsync(request.RoleIds, ct); + var cmd = new CreateUserCommand( + request.Name, + request.Email, + request.Password, + request.Phone, + request.RealName, + request.Status, + request.Gender, + request.BirthDate, + request.DeptId, + request.DeptName, + rolesToBeAssigned + ); + var userId = await mediator.Send(cmd, ct); + var response = new CreateUserResponse(userId, request.Name, request.Email); + await Send.OkAsync(response.AsResponseData(), cancellation: ct); + } +} diff --git a/template/src/ABC.Template.Web/Endpoints/Identity/Admin/UserEndpoints/DeleteUserEndpoint.cs b/template/src/ABC.Template.Web/Endpoints/Identity/Admin/UserEndpoints/DeleteUserEndpoint.cs new file mode 100644 index 00000000..5503a2bd --- /dev/null +++ b/template/src/ABC.Template.Web/Endpoints/Identity/Admin/UserEndpoints/DeleteUserEndpoint.cs @@ -0,0 +1,39 @@ +using FastEndpoints; +using FastEndpoints.Swagger; +using MediatR; +using Microsoft.AspNetCore.Authentication.JwtBearer; +using ABC.Template.Domain.AggregatesModel.UserAggregate; +using ABC.Template.Web.Application.Commands.Identity.Admin.UserCommands; +using ABC.Template.Web.AppPermissions; + +namespace ABC.Template.Web.Endpoints.Identity.Admin.UserEndpoints; + +/// +/// 删除用户的请求模型 +/// +/// 要删除的用户ID +public record DeleteUserRequest(UserId UserId); + +/// +/// 删除用户 +/// +/// +public class DeleteUserEndpoint(IMediator mediator) : Endpoint> +{ + public override void Configure() + { + Tags("Users"); + Description(b => b.AutoTagOverride("Users")); + Delete("/api/admin/users/{userId}"); + AuthSchemes(JwtBearerDefaults.AuthenticationScheme); + Permissions(PermissionCodes.AllApiAccess, PermissionCodes.UserDelete); + } + + public override async Task HandleAsync(DeleteUserRequest request, CancellationToken ct) + { + var command = new DeleteUserCommand(request.UserId); + await mediator.Send(command, ct); + await Send.OkAsync(true.AsResponseData(), cancellation: ct); + } +} + diff --git a/template/src/ABC.Template.Web/Endpoints/Identity/Admin/UserEndpoints/GetAllUsersEndpoint.cs b/template/src/ABC.Template.Web/Endpoints/Identity/Admin/UserEndpoints/GetAllUsersEndpoint.cs new file mode 100644 index 00000000..68f95389 --- /dev/null +++ b/template/src/ABC.Template.Web/Endpoints/Identity/Admin/UserEndpoints/GetAllUsersEndpoint.cs @@ -0,0 +1,32 @@ +using FastEndpoints; +using FastEndpoints.Swagger; +using Microsoft.AspNetCore.Authentication.JwtBearer; +using ABC.Template.Web.Application.Queries; +using ABC.Template.Web.AppPermissions; + +namespace ABC.Template.Web.Endpoints.Identity.Admin.UserEndpoints; + +/// +/// 获取所有用户 +/// +/// +public class GetAllUsersEndpoint(UserQuery userQuery) : Endpoint>> +{ + + public override void Configure() + { + Tags("Users"); + Description(b => b.AutoTagOverride("Users")); + Get("/api/admin/users"); + AuthSchemes(JwtBearerDefaults.AuthenticationScheme); + Permissions(PermissionCodes.AllApiAccess, PermissionCodes.UserView); + } + + + public override async Task HandleAsync(UserQueryInput req, CancellationToken ct) + { + var result = await userQuery.GetAllUsersAsync(req, ct); + await Send.OkAsync(result.AsResponseData(), cancellation: ct); + } +} + diff --git a/template/src/ABC.Template.Web/Endpoints/Identity/Admin/UserEndpoints/GetUserAccessCodesEndpoint.cs b/template/src/ABC.Template.Web/Endpoints/Identity/Admin/UserEndpoints/GetUserAccessCodesEndpoint.cs new file mode 100644 index 00000000..785a5928 --- /dev/null +++ b/template/src/ABC.Template.Web/Endpoints/Identity/Admin/UserEndpoints/GetUserAccessCodesEndpoint.cs @@ -0,0 +1,55 @@ +using System.Security.Claims; +using FastEndpoints; +using FastEndpoints.Swagger; +using Microsoft.AspNetCore.Authentication.JwtBearer; +using ABC.Template.Domain.AggregatesModel.UserAggregate; +using ABC.Template.Web.Application.Queries; +using ABC.Template.Domain; + +namespace ABC.Template.Web.Endpoints.Identity.Admin.UserEndpoints; + +/// +/// 获取用户权限码 +/// +/// +/// +public class GetUserAccessCodesEndpoint(RoleQuery roleQuery, UserQuery userQuery) : EndpointWithoutRequest>> +{ + public override void Configure() + { + Tags("Users"); + Description(b => b.AutoTagOverride("Users")); + Get("/api/admin/auth/codes"); + AuthSchemes(JwtBearerDefaults.AuthenticationScheme); + } + + public override async Task HandleAsync(CancellationToken ct) + { + // 从JWT token中获取用户ID + var userIdString = User.FindFirstValue(ClaimTypes.NameIdentifier); + if (string.IsNullOrEmpty(userIdString) || !long.TryParse(userIdString, out var userIdValue)) + { + throw new KnownException("无效的用户身份", ErrorCodes.InvalidUserIdentity); + } + + var userId = new UserId(userIdValue); + + // 获取用户信息(包含角色) + var userInfo = await userQuery.GetUserInfoForLoginByIdAsync(userId, ct); + if (userInfo == null) + { + throw new KnownException("用户不存在", ErrorCodes.UserNotFound); + } + + // 获取用户角色ID列表 + var roleIds = userInfo.UserRoles.Select(r => r.RoleId).ToList(); + + // 查询权限代码(如果用户没有角色,则返回空列表) + var permissionCodes = roleIds.Count > 0 + ? await roleQuery.GetAssignedPermissionCodesAsync(roleIds, ct) + : Enumerable.Empty(); + + // 返回成功响应,使用统一的响应数据格式包装 + await Send.OkAsync(permissionCodes.AsResponseData(), cancellation: ct); + } +} diff --git a/template/src/ABC.Template.Web/Endpoints/Identity/Admin/UserEndpoints/GetUserEndpoint.cs b/template/src/ABC.Template.Web/Endpoints/Identity/Admin/UserEndpoints/GetUserEndpoint.cs new file mode 100644 index 00000000..98f269f4 --- /dev/null +++ b/template/src/ABC.Template.Web/Endpoints/Identity/Admin/UserEndpoints/GetUserEndpoint.cs @@ -0,0 +1,44 @@ +using FastEndpoints; +using FastEndpoints.Swagger; +using Microsoft.AspNetCore.Authentication.JwtBearer; +using ABC.Template.Domain.AggregatesModel.UserAggregate; +using ABC.Template.Web.Application.Queries; +using ABC.Template.Web.AppPermissions; + +namespace ABC.Template.Web.Endpoints.Identity.Admin.UserEndpoints; + +/// +/// 获取用户信息的请求模型 +/// +/// 要查询的用户ID +public record GetUserRequest(UserId Id); + +/// +/// 获取用户 +/// +/// +public class GetUserEndpoint(UserQuery userQuery) : Endpoint> +{ + public override void Configure() + { + Tags("Users"); + Description(b => b.AutoTagOverride("Users")); + Get("/api/admin/users/{id}"); + AuthSchemes(JwtBearerDefaults.AuthenticationScheme); + Permissions(PermissionCodes.AllApiAccess, PermissionCodes.UserView); + } + + public override async Task HandleAsync(GetUserRequest req, CancellationToken ct) + { + var userInfo = await userQuery.GetUserByIdAsync(req.Id, ct); + if (userInfo == null) + { + await Send.NotFoundAsync(ct); + } + else + { + await Send.OkAsync(userInfo.AsResponseData(), cancellation: ct); + } + } +} + diff --git a/template/src/ABC.Template.Web/Endpoints/Identity/Admin/UserEndpoints/GetUserProfileEndpoint.cs b/template/src/ABC.Template.Web/Endpoints/Identity/Admin/UserEndpoints/GetUserProfileEndpoint.cs new file mode 100644 index 00000000..ea9c344d --- /dev/null +++ b/template/src/ABC.Template.Web/Endpoints/Identity/Admin/UserEndpoints/GetUserProfileEndpoint.cs @@ -0,0 +1,76 @@ +using FastEndpoints; +using FastEndpoints.Swagger; +using Microsoft.AspNetCore.Authentication.JwtBearer; +using ABC.Template.Domain.AggregatesModel.UserAggregate; +using ABC.Template.Domain.AggregatesModel.DeptAggregate; +using ABC.Template.Web.Application.Queries; +using ABC.Template.Domain; +using ABC.Template.Web.AppPermissions; + +namespace ABC.Template.Web.Endpoints.Identity.Admin.UserEndpoints; + +/// +/// 获取用户资料的请求模型 +/// +/// 要查询的用户ID +public record GetUserProfileRequest(UserId UserId); + +/// +/// 用户资料的响应模型 +/// +/// 用户ID +/// 用户名 +/// 电话号码 +/// 用户角色列表 +/// 真实姓名 +/// 用户状态 +/// 邮箱地址 +/// 创建时间 +/// 性别 +/// 年龄 +/// 出生日期 + /// 部门ID(可为空) + /// 部门名称 +public record UserProfileResponse(UserId UserId, string Name, string Phone, IEnumerable Roles, string RealName, int Status, string Email, DateTimeOffset CreatedAt, string Gender, int Age, DateTimeOffset BirthDate, DeptId? DeptId, string DeptName); + +/// +/// 获取用户资料 +/// +/// +public class GetUserProfileEndpoint(UserQuery userQuery) : Endpoint> +{ + public override void Configure() + { + Tags("Users"); + Description(b => b.AutoTagOverride("Users")); + Get("/api/admin/user/profile/{userId}"); + AuthSchemes(JwtBearerDefaults.AuthenticationScheme); + Permissions(PermissionCodes.AllApiAccess, PermissionCodes.UserView); + } + + public override async Task HandleAsync(GetUserProfileRequest req, CancellationToken ct) + { + var userInfo = await userQuery.GetUserByIdAsync(req.UserId, ct); + if (userInfo == null) + { + throw new KnownException("无效的用户", ErrorCodes.InvalidUser); + } + var response = new UserProfileResponse( + userInfo.UserId, + userInfo.Name, + userInfo.Phone, + userInfo.Roles, + userInfo.RealName, + userInfo.Status, + userInfo.Email, + userInfo.CreatedAt, + userInfo.Gender, + userInfo.Age, + userInfo.BirthDate, + userInfo.DeptId, + userInfo.DeptName + ); + await Send.OkAsync(response.AsResponseData(), cancellation: ct); + } +} + diff --git a/template/src/ABC.Template.Web/Endpoints/Identity/Admin/UserEndpoints/LoginEndpoint.cs b/template/src/ABC.Template.Web/Endpoints/Identity/Admin/UserEndpoints/LoginEndpoint.cs new file mode 100644 index 00000000..e9260f53 --- /dev/null +++ b/template/src/ABC.Template.Web/Endpoints/Identity/Admin/UserEndpoints/LoginEndpoint.cs @@ -0,0 +1,108 @@ +using System.Security.Claims; +using System.Text.Json; +using FastEndpoints; +using FastEndpoints.Swagger; +using Microsoft.AspNetCore.Authorization; +using Microsoft.Extensions.Options; +using NetCorePal.Extensions.Dto; +using NetCorePal.Extensions.Jwt; +using ABC.Template.Domain.AggregatesModel.UserAggregate; +using ABC.Template.Web.Application.Commands.Identity.Admin.UserCommands; +using ABC.Template.Web.Application.Queries; +using ABC.Template.Domain; +using ABC.Template.Web.Utils; +using Serilog; + +namespace ABC.Template.Web.Endpoints.Identity.Admin.UserEndpoints; + +public record LoginRequest(string Username, string Password); + +public record LoginResponse(string Token, string RefreshToken, UserId UserId, string Name, string Email, string Roles, IEnumerable PermissionCodes, DateTimeOffset TokenExpiryTime); + +/// +/// 用户登录 +/// +/// +/// +/// +/// +/// +public class LoginEndpoint(IMediator mediator, UserQuery userQuery, IJwtProvider jwtProvider, IOptions appConfiguration, RoleQuery roleQuery) : Endpoint> +{ + private const string PermissionClaimType = "permissions"; + + public override void Configure() + { + Tags("Users"); + Description(b => b.AutoTagOverride("Users")); + Post("/api/admin/user/login"); + AllowAnonymous(); + } + + public override async Task HandleAsync(LoginRequest req, CancellationToken ct) + { + Log.Information("用户登录尝试: Username={Username}", req.Username); + + var loginInfo = await userQuery.GetUserInfoForLoginAsync(req.Username, ct); + + if (loginInfo == null || !PasswordHasher.VerifyHashedPassword(req.Password, loginInfo.PasswordHash)) + { + throw new KnownException("用户名或密码错误", ErrorCodes.UserNameOrPasswordError); + } + + var nowTime = DateTimeOffset.UtcNow; + var tokenExpiryTime = nowTime.AddMinutes(appConfiguration.Value.TokenExpiryInMinutes); + var refreshToken = TokenGenerator.GenerateRefreshToken(); + var roles = loginInfo.UserRoles.Select(r => r.RoleId).ToList(); + var assignedPermissionCodes = roles.Count > 0 + ? await roleQuery.GetAssignedPermissionCodesAsync(roles, ct) + : Enumerable.Empty(); + var claims = BuildClaims(loginInfo, assignedPermissionCodes); + var config = appConfiguration.Value; + var token = await jwtProvider.GenerateJwtToken( + new JwtData( + config.JwtIssuer, + config.JwtAudience, + claims, + nowTime.UtcDateTime, + tokenExpiryTime.UtcDateTime), + ct); + var response = new LoginResponse( + token, + refreshToken, + loginInfo.UserId, + loginInfo.Name, + loginInfo.Email, + JsonSerializer.Serialize(roles) ?? "[]", + assignedPermissionCodes, + tokenExpiryTime + ); + + // 更新用户登录时间和刷新令牌 + var updateCmd = new UpdateUserLoginTimeCommand(loginInfo.UserId, nowTime, refreshToken); + await mediator.Send(updateCmd, ct); + + Log.Information("用户登录成功: UserId={UserId}, Username={Username}, Email={Email}, RoleCount={RoleCount}, PermissionCount={PermissionCount}", + loginInfo.UserId, loginInfo.Name, loginInfo.Email, roles.Count, assignedPermissionCodes.Count()); + + await Send.OkAsync(response.AsResponseData(), cancellation: ct); + } + + /// + /// 构建JWT Claims + /// + private static List BuildClaims(UserLoginInfoQueryDto loginInfo, IEnumerable permissionCodes) + { + var userIdString = loginInfo.UserId.ToString(); + var claims = new List + { + new(ClaimTypes.Name, loginInfo.Name), + new(ClaimTypes.Email, loginInfo.Email), + new(ClaimTypes.NameIdentifier, userIdString) + }; + + claims.AddRange(permissionCodes.Select(code => new Claim(PermissionClaimType, code))); + + return claims; + } +} \ No newline at end of file diff --git a/template/src/ABC.Template.Web/Endpoints/Identity/Admin/UserEndpoints/LogoutEndpoint.cs b/template/src/ABC.Template.Web/Endpoints/Identity/Admin/UserEndpoints/LogoutEndpoint.cs new file mode 100644 index 00000000..b1b44d36 --- /dev/null +++ b/template/src/ABC.Template.Web/Endpoints/Identity/Admin/UserEndpoints/LogoutEndpoint.cs @@ -0,0 +1,57 @@ +using System.Security.Claims; +using FastEndpoints; +using FastEndpoints.Swagger; +using Microsoft.AspNetCore.Authentication.JwtBearer; +using NetCorePal.Extensions.Dto; +using ABC.Template.Domain.AggregatesModel.UserAggregate; +using ABC.Template.Web.Application.Commands.Identity.Admin.UserCommands; +using Serilog; + +namespace ABC.Template.Web.Endpoints.Identity.Admin.UserEndpoints; + +/// +/// 用户退出登录 +/// +/// +public class LogoutEndpoint(IMediator mediator) : EndpointWithoutRequest> +{ + public override void Configure() + { + Tags("Users"); + Description(b => b.AutoTagOverride("Users")); + Post("/api/admin/auth/logout"); + AuthSchemes(JwtBearerDefaults.AuthenticationScheme); + AllowAnonymous(); // 允许匿名访问,因为token可能已过期 + } + + public override async Task HandleAsync(CancellationToken ct) + { + // 尝试从JWT token中获取用户ID(如果token有效) + var userIdString = User.FindFirstValue(ClaimTypes.NameIdentifier); + if (!string.IsNullOrEmpty(userIdString) && long.TryParse(userIdString, out var userIdValue)) + { + var userId = new UserId(userIdValue); + + try + { + // 撤销用户的所有刷新令牌,防止token被继续使用 + var revokeCmd = new RevokeUserRefreshTokensCommand(userId); + await mediator.Send(revokeCmd, ct); + + Log.Information("用户退出登录成功: UserId={UserId}", userId); + } + catch (Exception ex) + { + // 即使撤销token失败,也记录日志但不影响退出流程 + Log.Warning(ex, "用户退出登录时撤销刷新令牌失败: UserId={UserId}", userId); + } + } + else + { + Log.Information("用户退出登录: Token已失效或未提供"); + } + + // 返回成功响应 + await Send.OkAsync(true.AsResponseData(), cancellation: ct); + } +} diff --git a/template/src/ABC.Template.Web/Endpoints/Identity/Admin/UserEndpoints/PasswordResetEndpoint.cs b/template/src/ABC.Template.Web/Endpoints/Identity/Admin/UserEndpoints/PasswordResetEndpoint.cs new file mode 100644 index 00000000..4a6db5b1 --- /dev/null +++ b/template/src/ABC.Template.Web/Endpoints/Identity/Admin/UserEndpoints/PasswordResetEndpoint.cs @@ -0,0 +1,48 @@ +using FastEndpoints; +using FastEndpoints.Swagger; +using MediatR; +using Microsoft.AspNetCore.Authentication.JwtBearer; +using ABC.Template.Domain.AggregatesModel.UserAggregate; +using ABC.Template.Web.Application.Commands.Identity.Admin.UserCommands; +using ABC.Template.Web.AppPermissions; +using ABC.Template.Web.Utils; + +namespace ABC.Template.Web.Endpoints.Identity.Admin.UserEndpoints; + +/// +/// 密码重置的请求模型 +/// +/// 需要重置密码的用户ID +public record PasswordResetRequest(UserId UserId); + +/// +/// 密码重置的响应模型 +/// +/// 已重置密码的用户ID +public record PasswordResetResponse(UserId UserId); + +/// +/// 密码重置 +/// +/// +public class PasswordResetEndpoint(IMediator mediator) : Endpoint> +{ + public override void Configure() + { + Tags("Users"); + Description(b => b.AutoTagOverride("Users")); + Put("/api/admin/user/password-reset"); + AuthSchemes(JwtBearerDefaults.AuthenticationScheme); + Permissions(PermissionCodes.AllApiAccess, PermissionCodes.UserEdit); + } + + public override async Task HandleAsync(PasswordResetRequest request, CancellationToken ct) + { + var passwordHash = PasswordHasher.HashPassword("123456"); + var cmd = new PasswordResetCommand(request.UserId, passwordHash); + var userId = await mediator.Send(cmd, ct); + var response = new PasswordResetResponse(userId); + await Send.OkAsync(response.AsResponseData(), cancellation: ct); + } +} + diff --git a/template/src/ABC.Template.Web/Endpoints/Identity/Admin/UserEndpoints/RegisterEndpoint.cs b/template/src/ABC.Template.Web/Endpoints/Identity/Admin/UserEndpoints/RegisterEndpoint.cs new file mode 100644 index 00000000..6cbaceb9 --- /dev/null +++ b/template/src/ABC.Template.Web/Endpoints/Identity/Admin/UserEndpoints/RegisterEndpoint.cs @@ -0,0 +1,75 @@ +using FastEndpoints; +using FastEndpoints.Swagger; +using MediatR; +using ABC.Template.Domain.AggregatesModel.RoleAggregate; +using ABC.Template.Domain.AggregatesModel.UserAggregate; +using ABC.Template.Domain.AggregatesModel.DeptAggregate; +using ABC.Template.Web.Application.Commands.Identity.Admin.UserCommands; +using ABC.Template.Web.Application.Queries; +using ABC.Template.Web.Utils; + +namespace ABC.Template.Web.Endpoints.Identity.Admin.UserEndpoints; + +/// +/// 用户注册的请求模型 +/// +/// 用户名 +/// 邮箱地址 +/// 密码 +/// 电话号码 +/// 真实姓名 +/// 用户状态 +/// 性别 +/// 年龄 +/// 出生日期 + /// 部门ID(可选) + /// 部门名称(可选) + /// 要分配的角色ID列表 +public record RegisterRequest(string Name, string Email, string Password, string Phone, string RealName, int Status, string Gender, int Age, DateTimeOffset BirthDate, DeptId? DeptId, string? DeptName, IEnumerable RoleIds); + +/// +/// 用户注册的响应模型 +/// +/// 新创建的用户ID +/// 用户名 +/// 邮箱地址 +public record RegisterResponse(UserId UserId, string Name, string Email); + +/// +/// 用户注册 +/// +/// +/// +public class RegisterEndpoint(IMediator mediator, RoleQuery roleQuery) : Endpoint> +{ + public override void Configure() + { + Tags("Users"); + Description(b => b.AutoTagOverride("Users")); + Post("/api/admin/user/register"); + AllowAnonymous(); + } + + public override async Task HandleAsync(RegisterRequest request, CancellationToken ct) + { + var rolesToBeAssigned = await roleQuery.GetAdminRolesForAssignmentAsync(request.RoleIds, ct); + var passwordHash = PasswordHasher.HashPassword(request.Password); + var cmd = new CreateUserCommand( + request.Name, + request.Email, + passwordHash, + request.Phone, + request.RealName, + request.Status, + request.Gender, + request.BirthDate, + request.DeptId, + request.DeptName, + rolesToBeAssigned + ); + var userId = await mediator.Send(cmd, ct); + var response = new RegisterResponse(userId, request.Name, request.Email); + await Send.OkAsync(response.AsResponseData(), cancellation: ct); + } +} + diff --git a/template/src/ABC.Template.Web/Endpoints/Identity/Admin/UserEndpoints/UpdateUserEndpoint.cs b/template/src/ABC.Template.Web/Endpoints/Identity/Admin/UserEndpoints/UpdateUserEndpoint.cs new file mode 100644 index 00000000..63f552f7 --- /dev/null +++ b/template/src/ABC.Template.Web/Endpoints/Identity/Admin/UserEndpoints/UpdateUserEndpoint.cs @@ -0,0 +1,79 @@ +using FastEndpoints; +using FastEndpoints.Swagger; +using MediatR; +using Microsoft.AspNetCore.Authentication.JwtBearer; +using ABC.Template.Domain.AggregatesModel.UserAggregate; +using ABC.Template.Domain.AggregatesModel.DeptAggregate; +using ABC.Template.Web.Application.Commands.Identity.Admin.UserCommands; +using ABC.Template.Web.AppPermissions; +using ABC.Template.Web.Utils; + +namespace ABC.Template.Web.Endpoints.Identity.Admin.UserEndpoints; + +/// +/// 更新用户信息的请求模型 +/// +/// 要更新的用户ID +/// 用户名 +/// 邮箱地址 +/// 电话号码 +/// 真实姓名 +/// 用户状态 +/// 性别 +/// 年龄 +/// 出生日期 + /// 部门ID + /// 部门名称 + /// 密码(可选,为空则不更新) +public record UpdateUserRequest(UserId UserId, string Name, string Email, string Phone, string RealName, int Status, string Gender, int Age, DateTimeOffset BirthDate, DeptId DeptId, string DeptName, string Password); + +/// +/// 更新用户信息的响应模型 +/// +/// 已更新的用户ID +/// 用户名 +/// 邮箱地址 +public record UpdateUserResponse(UserId UserId, string Name, string Email); + +/// +/// 更新用户 +/// +/// +public class UpdateUserEndpoint(IMediator mediator) : Endpoint> +{ + public override void Configure() + { + Tags("Users"); + Description(b => b.AutoTagOverride("Users")); + Put("/api/admin/user/update"); + AuthSchemes(JwtBearerDefaults.AuthenticationScheme); + Permissions(PermissionCodes.AllApiAccess, PermissionCodes.UserEdit); + } + + public override async Task HandleAsync(UpdateUserRequest request, CancellationToken ct) + { + var passwordHash = string.Empty; + if (!string.IsNullOrWhiteSpace(request.Password)) + { + passwordHash = PasswordHasher.HashPassword(request.Password); + } + var cmd = new UpdateUserCommand( + request.UserId, + request.Name, + request.Email, + request.Phone, + request.RealName, + request.Status, + request.Gender, + request.Age, + request.BirthDate, + request.DeptId, + request.DeptName, + passwordHash + ); + var userId = await mediator.Send(cmd, ct); + var response = new UpdateUserResponse(userId, request.Name, request.Email); + await Send.OkAsync(response.AsResponseData(), cancellation: ct); + } +} + diff --git a/template/src/ABC.Template.Web/Endpoints/Identity/Admin/UserEndpoints/UpdateUserRolesEndpoint.cs b/template/src/ABC.Template.Web/Endpoints/Identity/Admin/UserEndpoints/UpdateUserRolesEndpoint.cs new file mode 100644 index 00000000..6102487f --- /dev/null +++ b/template/src/ABC.Template.Web/Endpoints/Identity/Admin/UserEndpoints/UpdateUserRolesEndpoint.cs @@ -0,0 +1,51 @@ +using FastEndpoints; +using FastEndpoints.Swagger; +using MediatR; +using Microsoft.AspNetCore.Authentication.JwtBearer; +using ABC.Template.Domain.AggregatesModel.UserAggregate; +using ABC.Template.Domain.AggregatesModel.RoleAggregate; +using ABC.Template.Web.Application.Commands.Identity.Admin.UserCommands; +using ABC.Template.Web.Application.Queries; +using ABC.Template.Web.AppPermissions; + +namespace ABC.Template.Web.Endpoints.Identity.Admin.UserEndpoints; + +/// +/// 更新用户角色的请求模型 +/// +/// 要更新角色的用户ID +/// 要分配给用户的角色ID列表 +public record UpdateUserRolesRequest(UserId UserId, IEnumerable RoleIds); + +/// +/// 更新用户角色的响应模型 +/// +/// 已更新角色的用户ID +public record UpdateUserRolesResponse(UserId UserId); + +/// +/// 更新用户角色 +/// +/// +/// +public class UpdateUserRolesEndpoint(IMediator mediator, RoleQuery roleQuery) : Endpoint> +{ + public override void Configure() + { + Tags("Users"); + Description(b => b.AutoTagOverride("Users")); + Put("/api/admin/users/update-roles"); + AuthSchemes(JwtBearerDefaults.AuthenticationScheme); + Permissions(PermissionCodes.AllApiAccess, PermissionCodes.UserRoleAssign); + } + + public override async Task HandleAsync(UpdateUserRolesRequest request, CancellationToken ct) + { + var rolesToBeAssigned = await roleQuery.GetAdminRolesForAssignmentAsync(request.RoleIds, ct); + var cmd = new UpdateUserRolesCommand(request.UserId, rolesToBeAssigned); + await mediator.Send(cmd, ct); + var response = new UpdateUserRolesResponse(request.UserId); + await Send.OkAsync(response.AsResponseData(), cancellation: ct); + } +} + diff --git a/template/src/ABC.Template.Web/Endpoints/OrderEndpoints/CreateOrderEndpoint.cs b/template/src/ABC.Template.Web/Endpoints/OrderEndpoints/CreateOrderEndpoint.cs deleted file mode 100644 index 9611656b..00000000 --- a/template/src/ABC.Template.Web/Endpoints/OrderEndpoints/CreateOrderEndpoint.cs +++ /dev/null @@ -1,23 +0,0 @@ -using ABC.Template.Domain.AggregatesModel.OrderAggregate; -using ABC.Template.Web.Application.Commands.Orders; -using FastEndpoints; -using MediatR; -using Microsoft.AspNetCore.Authorization; -using NetCorePal.Extensions.Dto; - -namespace ABC.Template.Web.Endpoints.OrderEndpoints; - -public record CreateOrderRequest(string Name, int Price, int Count); - -[Tags("Orders")] -[HttpPost("/api/order")] -[AllowAnonymous] -public class CreateOrderEndpoint(IMediator mediator) : Endpoint> -{ - public override async Task HandleAsync(CreateOrderRequest req, CancellationToken ct) - { - var cmd = new CreateOrderCommand(req.Name, req.Price, req.Count); - var id = await mediator.Send(cmd, ct); - await Send.OkAsync(id.AsResponseData(), cancellation: ct); - } -} \ No newline at end of file diff --git a/template/src/ABC.Template.Web/Endpoints/OrderEndpoints/GetOrderByIdEndpoint.cs b/template/src/ABC.Template.Web/Endpoints/OrderEndpoints/GetOrderByIdEndpoint.cs deleted file mode 100644 index 57579de3..00000000 --- a/template/src/ABC.Template.Web/Endpoints/OrderEndpoints/GetOrderByIdEndpoint.cs +++ /dev/null @@ -1,21 +0,0 @@ -using ABC.Template.Domain.AggregatesModel.OrderAggregate; -using ABC.Template.Web.Application.Queries.Orders; -using FastEndpoints; -using Microsoft.AspNetCore.Authorization; -using NetCorePal.Extensions.Dto; - -namespace ABC.Template.Web.Endpoints.OrderEndpoints; - -public record GetOrderByIdRequest(OrderId Id); - -[Tags("Orders")] -[HttpGet("/api/order/{Id}")] -[AllowAnonymous] -public class GetOrderByIdEndpoint(IMediator mediator) : Endpoint> -{ - public override async Task HandleAsync(GetOrderByIdRequest req, CancellationToken ct) - { - var order = await mediator.Send(new QueryOrder(req.Id), ct); - await Send.OkAsync(order.AsResponseData(), cancellation: ct); - } -} diff --git a/template/src/ABC.Template.Web/Endpoints/OrderEndpoints/PayOrderEndpoint.cs b/template/src/ABC.Template.Web/Endpoints/OrderEndpoints/PayOrderEndpoint.cs deleted file mode 100644 index b7f7a2ac..00000000 --- a/template/src/ABC.Template.Web/Endpoints/OrderEndpoints/PayOrderEndpoint.cs +++ /dev/null @@ -1,22 +0,0 @@ -using ABC.Template.Domain.AggregatesModel.OrderAggregate; -using ABC.Template.Web.Application.Commands.Orders; -using FastEndpoints; -using MediatR; -using Microsoft.AspNetCore.Authorization; -using NetCorePal.Extensions.Dto; - -namespace ABC.Template.Web.Endpoints.OrderEndpoints; - -public record PayOrderRequest(OrderId Id); - -[Tags("Orders")] -[HttpPost("/api/order/pay")] -[AllowAnonymous] -public class PayOrderEndpoint(IMediator mediator) : Endpoint> -{ - public override async Task HandleAsync(PayOrderRequest req, CancellationToken ct) - { - await mediator.Send(new PayOrderCommand(req.Id), ct); - await Send.OkAsync(true.AsResponseData(), cancellation: ct); - } -} \ No newline at end of file diff --git a/template/src/ABC.Template.Web/Endpoints/UserEndpoints/AuthEndpoint.cs b/template/src/ABC.Template.Web/Endpoints/UserEndpoints/AuthEndpoint.cs deleted file mode 100644 index c26e94e0..00000000 --- a/template/src/ABC.Template.Web/Endpoints/UserEndpoints/AuthEndpoint.cs +++ /dev/null @@ -1,16 +0,0 @@ -using FastEndpoints; -using Microsoft.AspNetCore.Authorization; -using NetCorePal.Extensions.Dto; - -namespace ABC.Template.Web.Endpoints.UserEndpoints; - -[Tags("Users")] -[Authorize(AuthenticationSchemes = "Bearer")] -[HttpGet("/api/user/auth")] -public class AuthEndpoint : EndpointWithoutRequest> -{ - public override Task HandleAsync(CancellationToken ct) - { - return Send.OkAsync(true.AsResponseData(), cancellation: ct); - } -} \ No newline at end of file diff --git a/template/src/ABC.Template.Web/Endpoints/UserEndpoints/LoginEndpoint.cs b/template/src/ABC.Template.Web/Endpoints/UserEndpoints/LoginEndpoint.cs deleted file mode 100644 index d47c18de..00000000 --- a/template/src/ABC.Template.Web/Endpoints/UserEndpoints/LoginEndpoint.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System.Security.Claims; -using FastEndpoints; -using Microsoft.AspNetCore.Authorization; -using NetCorePal.Extensions.Dto; -using NetCorePal.Extensions.Jwt; - -namespace ABC.Template.Web.Endpoints.UserEndpoints; - -public record LoginRequest(string Username, string Password); - -[Tags("Users")] -[HttpPost("/api/user/login")] -[AllowAnonymous] -public class LoginEndpoint(IJwtProvider jwtProvider) : Endpoint> -{ - public override async Task HandleAsync(LoginRequest req, CancellationToken ct) - { - var jwt = await jwtProvider.GenerateJwtToken( - new JwtData("netcorepal", "netcorepal", - [new Claim("name", req.Username)], - DateTime.Now, DateTime.Now.AddDays(1))); - await Send.OkAsync(jwt.AsResponseData(), cancellation: ct); - } -} \ No newline at end of file diff --git a/template/src/ABC.Template.Web/Extensions/ServiceCollectionExtensions.cs b/template/src/ABC.Template.Web/Extensions/ServiceCollectionExtensions.cs new file mode 100644 index 00000000..e6a801c9 --- /dev/null +++ b/template/src/ABC.Template.Web/Extensions/ServiceCollectionExtensions.cs @@ -0,0 +1,33 @@ +using System.Reflection; +using Microsoft.Extensions.DependencyInjection; +//#if (UseAdmin) +using ABC.Template.Web.Application.Queries; +//#endif + +namespace ABC.Template.Web.Extensions; + +/// +/// 服务集合扩展方法 +/// +public static class ServiceCollectionExtensions +{ + /// + /// 自动注册所有实现 IQuery 接口的查询类 + /// 参考框架的 AddRepositories 模式 + /// + /// 服务集合 + /// 要扫描的程序集 + /// 服务集合 + public static IServiceCollection AddQueries(this IServiceCollection services, Assembly assembly) + { + var queryTypes = assembly.GetTypes() + .Where(t => t.IsClass && !t.IsAbstract && typeof(IQuery).IsAssignableFrom(t)); + + foreach (var queryType in queryTypes) + { + services.AddScoped(queryType); + } + + return services; + } +} diff --git a/template/src/ABC.Template.Web/GlobalUsings.cs b/template/src/ABC.Template.Web/GlobalUsings.cs index 39d1fdd0..3383caba 100644 --- a/template/src/ABC.Template.Web/GlobalUsings.cs +++ b/template/src/ABC.Template.Web/GlobalUsings.cs @@ -1,7 +1,9 @@ -global using NetCorePal.Extensions.AspNetCore; +global using NetCorePal.Extensions.AspNetCore; global using NetCorePal.Extensions.DependencyInjection; global using Microsoft.Extensions.DependencyInjection; +//#if (UseAdmin) global using ABC.Template.Domain; +//#endif global using ABC.Template.Infrastructure; global using FluentValidation; global using NetCorePal.Extensions.Primitives; diff --git a/template/src/ABC.Template.Web/Program.cs b/template/src/ABC.Template.Web/Program.cs index b99d5d03..c0fe1b8e 100644 --- a/template/src/ABC.Template.Web/Program.cs +++ b/template/src/ABC.Template.Web/Program.cs @@ -6,9 +6,9 @@ using Microsoft.AspNetCore.DataProtection; using StackExchange.Redis; using FluentValidation.AspNetCore; -using ABC.Template.Web.Application.IntegrationEventHandlers; using ABC.Template.Web.Clients; using ABC.Template.Web.Extensions; +using ABC.Template.Web.Utils; using FastEndpoints; using Serilog; using Serilog.Formatting.Json; @@ -79,17 +79,41 @@ builder.Services.AddDataProtection() .PersistKeysToStackExchangeRedis("DataProtection-Keys"); - builder.Services.AddAuthentication().AddJwtBearer(options => + // 配置JWT认证 + builder.Services.Configure(builder.Configuration.GetSection("AppConfiguration")); + var appConfig = builder.Configuration.GetSection("AppConfiguration").Get() ?? new AppConfiguration { JwtIssuer = "netcorepal", JwtAudience = "netcorepal" }; + + builder.Services.AddAuthentication().AddJwtBearer(options => + { + options.RequireHttpsMetadata = false; + options.TokenValidationParameters.ValidAudience = appConfig.JwtAudience; + options.TokenValidationParameters.ValidateAudience = true; + options.TokenValidationParameters.ValidIssuer = appConfig.JwtIssuer; + options.TokenValidationParameters.ValidateIssuer = true; + }); + builder.Services.AddNetCorePalJwt().AddRedisStore(); + + #endregion + +//#if (UseAdmin) + #region CORS + + var allowedOrigins = builder.Configuration.GetSection("Cors:AllowedOrigins").Get() + ?? new[] { "http://localhost:5666", "http://localhost:5173", "http://localhost:3000" }; + + builder.Services.AddCors(options => { - options.RequireHttpsMetadata = false; - options.TokenValidationParameters.ValidAudience = "netcorepal"; - options.TokenValidationParameters.ValidateAudience = true; - options.TokenValidationParameters.ValidIssuer = "netcorepal"; - options.TokenValidationParameters.ValidateIssuer = true; + options.AddDefaultPolicy(policy => + { + policy.WithOrigins(allowedOrigins) + .AllowAnyMethod() + .AllowAnyHeader() + .AllowCredentials(); + }); }); - builder.Services.AddNetCorePalJwt().AddRedisStore(); #endregion +//#endif #region Controller @@ -116,6 +140,13 @@ #endregion +//#if (UseAdmin) + #region Query + // 自动注册所有实现 IQuery 接口的查询类 + builder.Services.AddQueries(Assembly.GetExecutingAssembly()); + #endregion +//#endif + #region 基础设施 builder.Services.AddRepositories(typeof(ApplicationDbContext).Assembly); @@ -377,7 +408,8 @@ var app = builder.Build(); - if (app.Environment.IsDevelopment()) + // 在非生产环境中执行数据库迁移(包括开发、测试、Staging等环境) + if (!app.Environment.IsProduction()) { using var scope = app.Services.CreateScope(); var dbContext = scope.ServiceProvider.GetRequiredService(); @@ -388,6 +420,22 @@ } +//#if (UseAdmin) + // SeedDatabase 必须在数据库迁移之后执行,确保表已创建 + // 在非生产环境中,如果 SeedDatabase 失败,应该抛出异常以便发现问题 + if (!app.Environment.IsProduction()) + { + try + { + app.SeedDatabase(); + } + catch (Exception ex) + { + Log.Error(ex, "Failed to seed database in {Environment} environment", app.Environment.EnvironmentName); + throw; // 重新抛出异常,确保测试能够发现数据库种子数据问题 + } + } +//#endif app.UseKnownExceptionHandler(); // Configure the HTTP request pipeline. @@ -399,7 +447,11 @@ app.UseStaticFiles(); //app.UseHttpsRedirection(); +//#if (UseAdmin) + app.UseCors(); // CORS 必须在 UseRouting 之前 +//#endif app.UseRouting(); + app.UseAuthentication(); // Authentication 必须在 Authorization 之前 app.UseAuthorization(); app.MapControllers(); @@ -423,10 +475,12 @@ // Code analysis endpoint app.MapGet("/code-analysis", () => { + var assemblies = new List { typeof(Program).Assembly, typeof(ApplicationDbContext).Assembly }; +//#if (UseAdmin) + assemblies.Add(typeof(ABC.Template.Domain.AggregatesModel.UserAggregate.User).Assembly); +//#endif var html = VisualizationHtmlBuilder.GenerateVisualizationHtml( - CodeFlowAnalysisHelper.GetResultFromAssemblies(typeof(Program).Assembly, - typeof(ApplicationDbContext).Assembly, - typeof(ABC.Template.Domain.AggregatesModel.OrderAggregate.Order).Assembly) + CodeFlowAnalysisHelper.GetResultFromAssemblies(assemblies.ToArray()) ); return Results.Content(html, "text/html; charset=utf-8"); }); diff --git a/template/src/ABC.Template.Web/Utils/AppConfiguration.cs b/template/src/ABC.Template.Web/Utils/AppConfiguration.cs new file mode 100644 index 00000000..d1017e3f --- /dev/null +++ b/template/src/ABC.Template.Web/Utils/AppConfiguration.cs @@ -0,0 +1,18 @@ +namespace ABC.Template.Web.Utils; + +public class AppConfiguration +{ + public string Secret { get; set; } = string.Empty; + public int TokenExpiryInMinutes { get; set; } + + /// + /// JWT Issuer(签发者) + /// + public string JwtIssuer { get; set; } = "netcorepal"; + + /// + /// JWT Audience(受众) + /// + public string JwtAudience { get; set; } = "netcorepal"; +} + diff --git a/template/src/ABC.Template.Web/Utils/PasswordHasher.cs b/template/src/ABC.Template.Web/Utils/PasswordHasher.cs new file mode 100644 index 00000000..d40f3007 --- /dev/null +++ b/template/src/ABC.Template.Web/Utils/PasswordHasher.cs @@ -0,0 +1,56 @@ +using Microsoft.AspNetCore.Cryptography.KeyDerivation; +using System.Security.Cryptography; +using System.Text; + +namespace ABC.Template.Web.Utils; + +public static class PasswordHasher +{ + private static string HashPassword(string value, string salt) + { + var valueBytes = KeyDerivation.Pbkdf2( + password: value, + salt: Encoding.UTF8.GetBytes(salt), + prf: KeyDerivationPrf.HMACSHA512, + iterationCount: 100000, + numBytesRequested: 256 / 8); + + return Convert.ToBase64String(valueBytes); + } + + private static string GenerateSalt() + { + var randomBytes = new byte[128 / 8]; + using var generator = RandomNumberGenerator.Create(); + generator.GetBytes(randomBytes); + return Convert.ToBase64String(randomBytes); + } + + public static string HashPassword(string password) + { + var salt = GenerateSalt(); + var hash = HashPassword(password, salt); + var result = $"{salt}.{hash}"; + return result; + } + + public static bool VerifyHashedPassword(string password, string storePassword) + { + if (string.IsNullOrEmpty(password)) + { + throw new ArgumentNullException(nameof(password)); + } + + if (string.IsNullOrEmpty(storePassword)) + { + throw new ArgumentNullException(nameof(storePassword)); + } + + var parts = storePassword.Split('.'); + var salt = parts[0]; + var hash = parts[1]; + + return HashPassword(password, salt) == hash; + } +} + diff --git a/template/src/ABC.Template.Web/Utils/SeedDatabaseExtension.cs b/template/src/ABC.Template.Web/Utils/SeedDatabaseExtension.cs new file mode 100644 index 00000000..61cc7a10 --- /dev/null +++ b/template/src/ABC.Template.Web/Utils/SeedDatabaseExtension.cs @@ -0,0 +1,221 @@ +using ABC.Template.Domain.AggregatesModel.DeptAggregate; +using ABC.Template.Domain.AggregatesModel.RoleAggregate; +using ABC.Template.Domain.AggregatesModel.UserAggregate; +using ABC.Template.Infrastructure; +using ABC.Template.Web.AppPermissions; +using Microsoft.EntityFrameworkCore; +using Serilog; + +namespace ABC.Template.Web.Utils; + +/// +/// 数据库种子数据扩展方法 +/// 用于在开发环境中初始化基础数据(角色、权限、组织架构、用户等) +/// +public static class SeedDatabaseExtension +{ + /// + /// 初始化数据库种子数据 + /// 包括:角色和权限、组织架构、管理员用户、测试用户 + /// + /// 应用程序构建器 + /// 应用程序构建器 + internal static IApplicationBuilder SeedDatabase(this IApplicationBuilder app) + { + try + { + Log.Information("开始初始化数据库种子数据..."); + using var serviceScope = app.ApplicationServices.CreateScope(); + var dbContext = serviceScope.ServiceProvider.GetRequiredService(); + + // 初始化角色和权限 +//#if (UseMongoDB) + if (!dbContext.Roles.IgnoreAutoIncludes().Any()) +//#else + if (!dbContext.Roles.Any()) +//#endif + { + var adminPermissionCodes = new[] + { + // 父权限码(用于菜单和路由权限控制) + PermissionCodes.UserManagement, + PermissionCodes.RoleManagement, + PermissionCodes.DeptManagement, + + // 用户管理权限 + PermissionCodes.UserCreate, + PermissionCodes.UserView, + PermissionCodes.UserEdit, + PermissionCodes.UserDelete, + PermissionCodes.UserRoleAssign, + PermissionCodes.UserResetPassword, + + // 角色管理权限 + PermissionCodes.RoleCreate, + PermissionCodes.RoleView, + PermissionCodes.RoleEdit, + PermissionCodes.RoleDelete, + PermissionCodes.RoleUpdatePermissions, + + // 部门管理权限 + PermissionCodes.DeptCreate, + PermissionCodes.DeptView, + PermissionCodes.DeptEdit, + PermissionCodes.DeptDelete, + + // 所有接口访问权限 + PermissionCodes.AllApiAccess, + }; + + var adminPermissions = adminPermissionCodes.Select(code => + { + var (name, description) = PermissionMapper.GetPermissionInfo(code); + return new RolePermission(code, name, description); + }).ToList(); + + var userPermissionCodes = new[] + { + PermissionCodes.UserView, + PermissionCodes.UserEdit, + PermissionCodes.AllApiAccess, + }; + + var userPermissions = userPermissionCodes.Select(code => + { + var (name, description) = PermissionMapper.GetPermissionInfo(code); + // 对于 UserEdit,使用特殊描述 + if (code == PermissionCodes.UserEdit) + { + description = "更新自己的用户信息"; + } + return new RolePermission(code, name, description); + }).ToList(); + + var adminRole = new Role("管理员", "系统管理员", adminPermissions); + var userRole = new Role("普通用户", "普通用户", userPermissions); + + dbContext.Roles.Add(adminRole); + dbContext.Roles.Add(userRole); + dbContext.SaveChanges(); + } + + // 初始化部门 + if (!dbContext.Depts.Any()) + { + var dept = new Dept("研发", "根节点", new DeptId(0), 1); + + dbContext.Depts.Add(dept); + dbContext.SaveChanges(); + + var deptId = dbContext.Depts.FirstOrDefault(r => r.Name == "研发")?.Id; + if (deptId == null) + { + throw new InvalidOperationException("无法找到部门'研发',请确保部门已正确创建"); + } + var childGroup = new Dept("Net", "第一个子节点", deptId, 1); + dbContext.Depts.Add(childGroup); + dbContext.SaveChanges(); + + var childGroupId = dbContext.Depts.FirstOrDefault(r => r.Name == "Net")?.Id; + if (childGroupId == null) + { + throw new InvalidOperationException("无法找到部门'Net',请确保部门已正确创建"); + } + var childIndividual = new Dept("C#", "第一个子节点的子节点", childGroupId, 1); + dbContext.Depts.Add(childIndividual); + dbContext.SaveChanges(); + } + + // 初始化管理员用户 +//#if (UseMongoDB) + // MongoDB 不支持对跨集合导航使用 Include,User 配置了 Roles/Dept 的 AutoInclude,此处用 IgnoreAutoIncludes 避免种子查询报错 + if (!dbContext.Users.IgnoreAutoIncludes().Any(u => u.Name == "admin")) + { + var dept = dbContext.Depts.FirstOrDefault(r => r.Name == "研发"); + var adminRole = dbContext.Roles.IgnoreAutoIncludes().FirstOrDefault(r => r.Name == "管理员"); +//#else + if (!dbContext.Users.Any(u => u.Name == "admin")) + { + var dept = dbContext.Depts.FirstOrDefault(r => r.Name == "研发"); + var adminRole = dbContext.Roles.FirstOrDefault(r => r.Name == "管理员"); +//#endif + + if (dept == null) + { + throw new InvalidOperationException("无法找到部门'研发',请确保部门已正确初始化"); + } + + if (adminRole == null) + { + throw new InvalidOperationException("无法找到角色'管理员',请确保角色已正确初始化"); + } + + var adminUser = new User( + "admin", + "13800138000", + PasswordHasher.HashPassword("123456"), + new List { new UserRole(adminRole.Id, adminRole.Name) }, + "系统管理员", + 1, + "admin@example.com", + "男", + DateTimeOffset.UtcNow.AddYears(-30) // 假设管理员年龄为30岁 + ); + + // 设置部门关系 + adminUser.AssignDept(new UserDept(adminUser.Id, dept.Id, dept.Name)); + dbContext.Users.Add(adminUser); + dbContext.SaveChanges(); + } + + // 初始化测试用户 +//#if (UseMongoDB) + if (!dbContext.Users.IgnoreAutoIncludes().Any(u => u.Name == "test")) + { + var dept = dbContext.Depts.FirstOrDefault(r => r.Name == "研发"); + var userRole = dbContext.Roles.IgnoreAutoIncludes().FirstOrDefault(r => r.Name == "普通用户"); +//#else + if (!dbContext.Users.Any(u => u.Name == "test")) + { + var dept = dbContext.Depts.FirstOrDefault(r => r.Name == "研发"); + var userRole = dbContext.Roles.FirstOrDefault(r => r.Name == "普通用户"); +//#endif + + if (dept == null) + { + throw new InvalidOperationException("无法找到部门'研发',请确保部门已正确初始化"); + } + + if (userRole == null) + { + throw new InvalidOperationException("无法找到角色'普通用户',请确保角色已正确初始化"); + } + + var testUser = new User( + "test", + "13800138001", + PasswordHasher.HashPassword("123456"), + new List { new UserRole(userRole.Id, userRole.Name) }, + "测试用户", + 1, + "test@example.com", + "女", + DateTimeOffset.UtcNow.AddYears(-25) // 假设测试用户年龄为25岁 + ); + + testUser.AssignDept(new UserDept(testUser.Id, dept.Id, dept.Name)); + dbContext.Users.Add(testUser); + dbContext.SaveChanges(); + } + + Log.Information("数据库种子数据初始化完成"); + return app; + } + catch (Exception ex) + { + Log.Error(ex, "数据库种子数据初始化失败"); + throw; + } + } +} + diff --git a/template/src/ABC.Template.Web/Utils/TokenGenerator.cs b/template/src/ABC.Template.Web/Utils/TokenGenerator.cs new file mode 100644 index 00000000..a014a20a --- /dev/null +++ b/template/src/ABC.Template.Web/Utils/TokenGenerator.cs @@ -0,0 +1,24 @@ +using System.Security.Cryptography; + +namespace ABC.Template.Web.Utils; + +public static class TokenGenerator +{ + public static string GenerateCryptographicallySecureGuid() + { + using var rng = RandomNumberGenerator.Create(); + var bytes = new byte[16]; + rng.GetBytes(bytes); + return new Guid(bytes).ToString("N"); + } + + public static string GenerateRefreshToken() + { + var randomNumber = new byte[32]; + using var rnd = RandomNumberGenerator.Create(); + rnd.GetBytes(randomNumber); + + return Convert.ToBase64String(randomNumber); + } +} + diff --git a/template/src/ABC.Template.Web/appsettings.Development.json b/template/src/ABC.Template.Web/appsettings.Development.json index f1a56b66..aa761fb8 100644 --- a/template/src/ABC.Template.Web/appsettings.Development.json +++ b/template/src/ABC.Template.Web/appsettings.Development.json @@ -47,6 +47,21 @@ "Pulsar": { "ServiceUrl": "pulsar://localhost:6650" }, +//#endif +//#if (UseAdmin) + "Cors": { + "AllowedOrigins": [ + "http://localhost:5666", + "http://localhost:5173", + "http://localhost:3000" + ] + }, + "AppConfiguration": { + "Secret": "your-secret-key-here", + "TokenExpiryInMinutes": 1440, + "JwtIssuer": "netcorepal", + "JwtAudience": "netcorepal" + }, //#endif "Services": { "user": { diff --git a/template/src/ABC.Template.Web/appsettings.json b/template/src/ABC.Template.Web/appsettings.json index ec04bc12..9345c0c6 100644 --- a/template/src/ABC.Template.Web/appsettings.json +++ b/template/src/ABC.Template.Web/appsettings.json @@ -5,5 +5,85 @@ "Microsoft.AspNetCore": "Warning" } }, - "AllowedHosts": "*" + "AllowedHosts": "*", +//#if (UseAdmin) + "Cors": { + "AllowedOrigins": [ + "http://localhost:5666", + "http://localhost:5173", + "http://localhost:3000" + ] + }, + "AppConfiguration": { + "Secret": "your-secret-key-here", + "TokenExpiryInMinutes": 1440, + "JwtIssuer": "netcorepal", + "JwtAudience": "netcorepal" + }, +//#endif + "ConnectionStrings": { +//#if (UseMySql) + "MySql": "Server=localhost;User ID=root;Password=123456;Database=dev;SslMode=none", +//#elif (UseSqlServer) + "SqlServer": "Server=localhost;Database=dev;User ID=sa;Password=Test123456!;TrustServerCertificate=true", +//#elif (UsePostgreSQL) + "PostgreSQL": "Host=localhost;Database=dev;Username=postgres;Password=123456", +//#elif (UseSqlite) + "Sqlite": "Data Source=demo.db", +//#elif (UseGaussDB) + "GaussDB": "Host=localhost;Database=dev;Username=postgres;Password=123456", +//#elif (UseDMDB) + "DMDB": "Server=localhost;User ID=SYSDBA;Password=SYSDBA;Database=dev", +//#elif (UseMongoDB) + "MongoDB": "mongodb://localhost:27017/dev", +//#endif + "Redis": "localhost:6379" + }, +//#if (UseRabbitMQ) + "RabbitMQ": { + "HostName": "localhost", + "UserName": "guest", + "Password": "guest", + "VirtualHost": "/", + "Port": 5672 + }, +//#elif (UseKafka) + "Kafka": { + "Servers": "localhost:9092" + }, +//#elif (UseAzureServiceBus) + "AzureServiceBus": { + "ConnectionString": "Endpoint=sb://your-servicebus.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=your-key" + }, +//#elif (UseAmazonSQS) + "AmazonSQS": { + "Region": "us-east-1", + "AccessKey": "your-access-key", + "SecretKey": "your-secret-key" + }, +//#elif (UseNATS) + "NATS": { + "Servers": "nats://localhost:4222" + }, +//#elif (UseRedisStreams) + "RedisStreams": { + "ConnectionString": "localhost:6379" + }, +//#elif (UsePulsar) + "Pulsar": { + "ServiceUrl": "pulsar://localhost:6650" + }, +//#endif + "Services": { + "user": { + "https": [ + "https://user:8443" + ] + }, + "user-v2": { + "https": [ + "https://user-v2:8443" + ] + } + } } \ No newline at end of file diff --git a/template/src/frontend/.browserslistrc b/template/src/frontend/.browserslistrc new file mode 100644 index 00000000..dc3bc09a --- /dev/null +++ b/template/src/frontend/.browserslistrc @@ -0,0 +1,4 @@ +> 1% +last 2 versions +not dead +not ie 11 diff --git a/template/src/frontend/.changeset/README.md b/template/src/frontend/.changeset/README.md new file mode 100644 index 00000000..5654e898 --- /dev/null +++ b/template/src/frontend/.changeset/README.md @@ -0,0 +1,5 @@ +# Changesets + +Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works with multi-package repos, or single-package repos to help you version and publish your code. You can find the full documentation for it [in our repository](https://github.com/changesets/changesets) + +We have a quick list of common questions to get you started engaging with this project in [our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md) diff --git a/template/src/frontend/.changeset/config.json b/template/src/frontend/.changeset/config.json new file mode 100644 index 00000000..f954fb4b --- /dev/null +++ b/template/src/frontend/.changeset/config.json @@ -0,0 +1,18 @@ +{ + "$schema": "https://unpkg.com/@changesets/config@3.0.0/schema.json", + "changelog": [ + "@changesets/changelog-github", + { "repo": "vbenjs/vue-vben-admin" } + ], + "commit": false, + "fixed": [["@vben-core/*", "@vben/*"]], + "snapshot": { + "prereleaseTemplate": "{tag}-{datetime}" + }, + "privatePackages": { "version": true, "tag": true }, + "linked": [], + "access": "public", + "baseBranch": "main", + "updateInternalDependencies": "patch", + "ignore": [] +} diff --git a/template/src/frontend/.commitlintrc.js b/template/src/frontend/.commitlintrc.js new file mode 100644 index 00000000..02e33fa6 --- /dev/null +++ b/template/src/frontend/.commitlintrc.js @@ -0,0 +1 @@ +export { default } from '@vben/commitlint-config'; diff --git a/template/src/frontend/.dockerignore b/template/src/frontend/.dockerignore new file mode 100644 index 00000000..52b833a9 --- /dev/null +++ b/template/src/frontend/.dockerignore @@ -0,0 +1,7 @@ +node_modules +.git +.gitignore +*.md +dist +.turbo +dist.zip diff --git a/template/src/frontend/.editorconfig b/template/src/frontend/.editorconfig new file mode 100644 index 00000000..179aec6f --- /dev/null +++ b/template/src/frontend/.editorconfig @@ -0,0 +1,18 @@ +root = true + +[*] +charset=utf-8 +end_of_line=lf +insert_final_newline=true +indent_style=space +indent_size=2 +max_line_length = 100 +trim_trailing_whitespace = true +quote_type = single + +[*.{yml,yaml,json}] +indent_style = space +indent_size = 2 + +[*.md] +trim_trailing_whitespace = false diff --git a/template/src/frontend/.gitattributes b/template/src/frontend/.gitattributes new file mode 100644 index 00000000..d4e5bd3e --- /dev/null +++ b/template/src/frontend/.gitattributes @@ -0,0 +1,11 @@ +# https://docs.github.com/cn/get-started/getting-started-with-git/configuring-git-to-handle-line-endings + +# Automatically normalize line endings (to LF) for all text-based files. +* text=auto eol=lf + +# Declare files that will always have CRLF line endings on checkout. +*.{cmd,[cC][mM][dD]} text eol=crlf +*.{bat,[bB][aA][tT]} text eol=crlf + +# Denote all files that are truly binary and should not be modified. +*.{ico,png,jpg,jpeg,gif,webp,svg,woff,woff2} binary \ No newline at end of file diff --git a/template/src/frontend/.gitconfig b/template/src/frontend/.gitconfig new file mode 100644 index 00000000..4b28a69c --- /dev/null +++ b/template/src/frontend/.gitconfig @@ -0,0 +1,2 @@ +[core] + ignorecase = false diff --git a/template/src/frontend/.github/CODEOWNERS b/template/src/frontend/.github/CODEOWNERS new file mode 100644 index 00000000..b95ff946 --- /dev/null +++ b/template/src/frontend/.github/CODEOWNERS @@ -0,0 +1,14 @@ +# default onwer +* anncwb@126.com vince292007@gmail.com netfan@foxmail.com jinmao88@qq.com + +# vben core onwer +/.github/ anncwb@126.com vince292007@gmail.com netfan@foxmail.com jinmao88@qq.com +/.vscode/ anncwb@126.com vince292007@gmail.com netfan@foxmail.com jinmao88@qq.com +/packages/ anncwb@126.com vince292007@gmail.com netfan@foxmail.com jinmao88@qq.com +/packages/@core/ anncwb@126.com vince292007@gmail.com netfan@foxmail.com jinmao88@qq.com +/internal/ anncwb@126.com vince292007@gmail.com netfan@foxmail.com jinmao88@qq.com +/scripts/ anncwb@126.com vince292007@gmail.com netfan@foxmail.com jinmao88@qq.com + +# vben team onwer +apps/ anncwb@126.com vince292007@gmail.com netfan@foxmail.com @vbenjs/team-v5 jinmao88@qq.com +docs/ anncwb@126.com vince292007@gmail.com netfan@foxmail.com @vbenjs/team-v5 jinmao88@qq.com diff --git a/template/src/frontend/.github/ISSUE_TEMPLATE/bug-report.yml b/template/src/frontend/.github/ISSUE_TEMPLATE/bug-report.yml new file mode 100644 index 00000000..ae927803 --- /dev/null +++ b/template/src/frontend/.github/ISSUE_TEMPLATE/bug-report.yml @@ -0,0 +1,74 @@ +name: 🐞 Bug Report +description: Report an issue with Vben Admin to help us make it better. +title: 'Bug: ' +labels: ['bug: pending triage'] + +body: + - type: markdown + attributes: + value: | + Thanks for taking the time to fill out this bug report! + - type: dropdown + id: version + attributes: + label: Version + description: What version of our software are you running? + options: + - Vben Admin V5 + - Vben Admin V2 + default: 0 + validations: + required: true + + - type: textarea + id: bug-desc + attributes: + label: Describe the bug? + description: A clear and concise description of what the bug is. If you intend to submit a PR for this issue, tell us in the description. Thanks! + placeholder: Bug Description + validations: + required: true + + - type: textarea + id: reproduction + attributes: + label: Reproduction + description: Please provide a link to [StackBlitz](https://stackblitz.com/fork/github/vitest-dev/vitest/tree/main/examples/basic?initialPath=__vitest__/) (you can also use [examples](https://github.com/vitest-dev/vitest/tree/main/examples)) or a github repo that can reproduce the problem you ran into. A [minimal reproduction](https://stackoverflow.com/help/minimal-reproducible-example) is required unless you are absolutely sure that the issue is obvious and the provided information is enough to understand the problem. If a report is vague (e.g. just a generic error message) and has no reproduction, it will receive a "needs reproduction" label. If no reproduction is provided after 3 days, it will be auto-closed. + placeholder: Reproduction + validations: + required: true + + - type: textarea + id: system-info + attributes: + label: System Info + description: Output of `npx envinfo --system --npmPackages '{vue}' --binaries --browsers` + render: shell + placeholder: System, Binaries, Browsers + validations: + required: true + + - type: textarea + id: logs + attributes: + label: Relevant log output + description: Please copy and paste any relevant log output. This will be automatically formatted into code, so no need for backticks. + render: shell + + - type: checkboxes + id: terms + attributes: + label: Validations + description: Before submitting the issue, please make sure you do the following + # description: By submitting this issue, you agree to follow our [Code of Conduct](https://example.com). + options: + - label: Read the [docs](https://doc.vben.pro/) + required: true + - label: Ensure the code is up to date. (Some issues have been fixed in the latest version) + required: true + - label: I have searched the [existing issues](https://github.com/vbenjs/vue-vben-admin/issues) and checked that my issue does not duplicate any existing issues. + required: true + - label: Check that this is a concrete bug. For Q&A open a [GitHub Discussion](https://github.com/vbenjs/vue-vben-admin/discussions) or join our [Discord Chat Server](https://discord.gg/8GuAdwDhj6). + required: true + - label: The provided reproduction is a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example) of the bug. + required: true diff --git a/template/src/frontend/.github/ISSUE_TEMPLATE/docs.yml b/template/src/frontend/.github/ISSUE_TEMPLATE/docs.yml new file mode 100644 index 00000000..d2bf16ef --- /dev/null +++ b/template/src/frontend/.github/ISSUE_TEMPLATE/docs.yml @@ -0,0 +1,38 @@ +name: 📚 Documentation +description: Report an issue with Vben Admin Website to help us make it better. +title: 'Docs: ' +labels: [documentation] +body: + - type: markdown + attributes: + value: | + Thanks for taking the time to fill out this issue! + - type: checkboxes + id: documentation_is + attributes: + label: Documentation is + options: + - label: Missing + - label: Outdated + - label: Confusing + - label: Not sure? + - type: textarea + id: description + attributes: + label: Explain in Detail + description: A clear and concise description of your suggestion. If you intend to submit a PR for this issue, tell us in the description. Thanks! + placeholder: The description of ... page is not clear. I thought it meant ... but it wasn't. + validations: + required: true + - type: textarea + id: suggestion + attributes: + label: Your Suggestion for Changes + validations: + required: true + - type: textarea + id: reproduction-steps + attributes: + label: Steps to reproduce + description: Please provide any reproduction steps that may need to be described. E.g. if it happens only when running the dev or build script make sure it's clear which one to use. + placeholder: Run `pnpm install` followed by `pnpm run docs:dev` diff --git a/template/src/frontend/.github/ISSUE_TEMPLATE/feature-request.yml b/template/src/frontend/.github/ISSUE_TEMPLATE/feature-request.yml new file mode 100644 index 00000000..393334e8 --- /dev/null +++ b/template/src/frontend/.github/ISSUE_TEMPLATE/feature-request.yml @@ -0,0 +1,70 @@ +name: ✨ New Feature Proposal +description: Propose a new feature to be added to Vben Admin +title: 'FEATURE: ' +labels: ['enhancement: pending triage'] +body: + - type: markdown + attributes: + value: | + Thank you for suggesting a feature for our project! Please fill out the information below to help us understand and implement your request! + - type: dropdown + id: version + attributes: + label: Version + description: What version of our software are you running? + options: + - Vben Admin V5 + - Vben Admin V2 + default: 0 + validations: + required: true + + - type: textarea + id: description + attributes: + label: Description + description: A detailed description of the feature request. + placeholder: Please describe the feature you would like to see, and why it would be useful. + validations: + required: true + + - type: textarea + id: proposed-solution + attributes: + label: Proposed Solution + description: A clear and concise description of what you want to happen. + placeholder: Describe the solution you'd like to see + validations: + required: true + + - type: textarea + id: alternatives + attributes: + label: Alternatives Considered + description: | + A clear and concise description of any alternative solutions or features you've considered. + placeholder: Describe any alternative solutions or features you've considered + validations: + required: false + + - type: input + id: additional-context + attributes: + label: Additional Context + description: Add any other context or screenshots about the feature request here. + placeholder: Any additional information + validations: + required: false + + - type: checkboxes + id: checkboxes + attributes: + label: Validations + description: Before submitting the issue, please make sure you do the following + options: + - label: Read the [docs](https://doc.vben.pro/) + required: true + - label: Ensure the code is up to date. (Some issues have been fixed in the latest version) + required: true + - label: I have searched the [existing issues](https://github.com/vbenjs/vue-vben-admin/issues) and checked that my issue does not duplicate any existing issues. + required: true diff --git a/template/src/frontend/.github/actions/setup-node/action.yml b/template/src/frontend/.github/actions/setup-node/action.yml new file mode 100644 index 00000000..35fa41c8 --- /dev/null +++ b/template/src/frontend/.github/actions/setup-node/action.yml @@ -0,0 +1,40 @@ +name: 'Setup Node' + +description: 'Setup node and pnpm' + +runs: + using: 'composite' + steps: + - name: Install pnpm + uses: pnpm/action-setup@v4 + + - name: Install Node.js + uses: actions/setup-node@v4 + with: + node-version-file: .node-version + cache: 'pnpm' + + - name: Get pnpm store directory + shell: bash + run: | + echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV + + - uses: actions/cache@v4 + name: Setup pnpm cache + if: ${{ github.ref_name == 'main' }} + with: + path: ${{ env.STORE_PATH }} + key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} + restore-keys: | + ${{ runner.os }}-pnpm-store- + + - uses: actions/cache/restore@v4 + if: ${{ github.ref_name != 'main' }} + with: + path: ${{ env.STORE_PATH }} + key: | + ${{ runner.os }}-pnpm-store- + + - name: Install dependencies + shell: bash + run: pnpm install --frozen-lockfile diff --git a/template/src/frontend/.github/commit-convention.md b/template/src/frontend/.github/commit-convention.md new file mode 100644 index 00000000..a1a969e9 --- /dev/null +++ b/template/src/frontend/.github/commit-convention.md @@ -0,0 +1,89 @@ +## Git Commit Message Convention + +> This is adapted from [Angular's commit convention](https://github.com/conventional-changelog/conventional-changelog/tree/master/packages/conventional-changelog-angular). + +#### TL;DR: + +Messages must be matched by the following regex: + +```js +/^(revert: )?(feat|fix|docs|style|refactor|perf|test|workflow|build|ci|chore|types|wip): .{1,50}/; +``` + +#### Examples + +Appears under "Features" header, `dev` subheader: + +``` +feat(dev): add 'comments' option +``` + +Appears under "Bug Fixes" header, `dev` subheader, with a link to issue #28: + +``` +fix(dev): fix dev error + +close #28 +``` + +Appears under "Performance Improvements" header, and under "Breaking Changes" with the breaking change explanation: + +``` +perf(build): remove 'foo' option + +BREAKING CHANGE: The 'foo' option has been removed. +``` + +The following commit and commit `667ecc1` do not appear in the changelog if they are under the same release. If not, the revert commit appears under the "Reverts" header. + +``` +revert: feat(compiler): add 'comments' option + +This reverts commit 667ecc1654a317a13331b17617d973392f415f02. +``` + +### Full Message Format + +A commit message consists of a **header**, **body** and **footer**. The header has a **type**, **scope** and **subject**: + +``` +(): + + + +