feat: 使用 PostgreSQL xmin 系统列作为并发控制
All checks were successful
Build and Deploy AdminApi / build-and-deploy (push) Successful in 38s
All checks were successful
Build and Deploy AdminApi / build-and-deploy (push) Successful in 38s
This commit is contained in:
@@ -79,7 +79,7 @@ public sealed class IdentityUser : AuditableEntityBase
|
|||||||
public string? Avatar { get; set; }
|
public string? Avatar { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 并发控制字段(映射到 PostgreSQL xmin)。
|
/// 并发控制字段(映射到 PostgreSQL xmin 系统列)。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public uint RowVersion { get; set; }
|
public uint RowVersion { get; set; }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,52 +0,0 @@
|
|||||||
using Microsoft.EntityFrameworkCore.Migrations;
|
|
||||||
|
|
||||||
#nullable disable
|
|
||||||
|
|
||||||
namespace TakeoutSaaS.Infrastructure.Migrations.IdentityDb
|
|
||||||
{
|
|
||||||
/// <inheritdoc />
|
|
||||||
public partial class SyncIdentityModel : Migration
|
|
||||||
{
|
|
||||||
/// <inheritdoc />
|
|
||||||
protected override void Up(MigrationBuilder migrationBuilder)
|
|
||||||
{
|
|
||||||
migrationBuilder.RenameColumn(
|
|
||||||
name: "RowVersion",
|
|
||||||
table: "identity_users",
|
|
||||||
newName: "xmin");
|
|
||||||
|
|
||||||
migrationBuilder.AlterColumn<uint>(
|
|
||||||
name: "xmin",
|
|
||||||
table: "identity_users",
|
|
||||||
type: "xid",
|
|
||||||
rowVersion: true,
|
|
||||||
nullable: false,
|
|
||||||
comment: "并发控制字段(映射到 PostgreSQL xmin)。",
|
|
||||||
oldClrType: typeof(byte[]),
|
|
||||||
oldType: "bytea",
|
|
||||||
oldRowVersion: true,
|
|
||||||
oldComment: "并发控制字段。");
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
protected override void Down(MigrationBuilder migrationBuilder)
|
|
||||||
{
|
|
||||||
migrationBuilder.RenameColumn(
|
|
||||||
name: "xmin",
|
|
||||||
table: "identity_users",
|
|
||||||
newName: "RowVersion");
|
|
||||||
|
|
||||||
migrationBuilder.AlterColumn<byte[]>(
|
|
||||||
name: "RowVersion",
|
|
||||||
table: "identity_users",
|
|
||||||
type: "bytea",
|
|
||||||
rowVersion: true,
|
|
||||||
nullable: false,
|
|
||||||
comment: "并发控制字段。",
|
|
||||||
oldClrType: typeof(uint),
|
|
||||||
oldType: "xid",
|
|
||||||
oldRowVersion: true,
|
|
||||||
oldComment: "并发控制字段(映射到 PostgreSQL xmin)。");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -12,8 +12,8 @@ using TakeoutSaaS.Infrastructure.Identity.Persistence;
|
|||||||
namespace TakeoutSaaS.Infrastructure.Migrations.IdentityDb
|
namespace TakeoutSaaS.Infrastructure.Migrations.IdentityDb
|
||||||
{
|
{
|
||||||
[DbContext(typeof(IdentityDbContext))]
|
[DbContext(typeof(IdentityDbContext))]
|
||||||
[Migration("20260205131209_SyncIdentityModel")]
|
[Migration("20260205131953_UseXminConcurrency")]
|
||||||
partial class SyncIdentityModel
|
partial class UseXminConcurrency
|
||||||
{
|
{
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||||
@@ -275,7 +275,7 @@ namespace TakeoutSaaS.Infrastructure.Migrations.IdentityDb
|
|||||||
.ValueGeneratedOnAddOrUpdate()
|
.ValueGeneratedOnAddOrUpdate()
|
||||||
.HasColumnType("xid")
|
.HasColumnType("xid")
|
||||||
.HasColumnName("xmin")
|
.HasColumnName("xmin")
|
||||||
.HasComment("并发控制字段(映射到 PostgreSQL xmin)。");
|
.HasComment("并发控制字段(映射到 PostgreSQL xmin 系统列)。");
|
||||||
|
|
||||||
b.Property<int>("Status")
|
b.Property<int>("Status")
|
||||||
.HasColumnType("integer")
|
.HasColumnType("integer")
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace TakeoutSaaS.Infrastructure.Migrations.IdentityDb
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public partial class UseXminConcurrency : Migration
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
// 删除旧的 RowVersion 列,改用 PostgreSQL 原生 xmin 系统列
|
||||||
|
migrationBuilder.DropColumn(
|
||||||
|
name: "RowVersion",
|
||||||
|
table: "identity_users");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
// 恢复 RowVersion 列
|
||||||
|
migrationBuilder.AddColumn<byte[]>(
|
||||||
|
name: "RowVersion",
|
||||||
|
table: "identity_users",
|
||||||
|
type: "bytea",
|
||||||
|
rowVersion: true,
|
||||||
|
nullable: false,
|
||||||
|
defaultValue: new byte[0]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -272,7 +272,7 @@ namespace TakeoutSaaS.Infrastructure.Migrations.IdentityDb
|
|||||||
.ValueGeneratedOnAddOrUpdate()
|
.ValueGeneratedOnAddOrUpdate()
|
||||||
.HasColumnType("xid")
|
.HasColumnType("xid")
|
||||||
.HasColumnName("xmin")
|
.HasColumnName("xmin")
|
||||||
.HasComment("并发控制字段(映射到 PostgreSQL xmin)。");
|
.HasComment("并发控制字段(映射到 PostgreSQL xmin 系统列)。");
|
||||||
|
|
||||||
b.Property<int>("Status")
|
b.Property<int>("Status")
|
||||||
.HasColumnType("integer")
|
.HasColumnType("integer")
|
||||||
|
|||||||
Reference in New Issue
Block a user