feat: 添加租户隔离保护触发器的管理方法,并更新迁移文档

This commit is contained in:
2026-07-28 14:45:33 +08:00
parent 99e4e43122
commit 5e993298e7
5 changed files with 61 additions and 4 deletions

View File

@@ -9200,14 +9200,13 @@ namespace Tiku.Infrastructure.Persistence.Migrations
principalColumns: new[] { "tenant_id", "id" },
onDelete: ReferentialAction.SetNull);
migrationBuilder.Sql(PostgreSqlTenantConstraintSql.CreateTenantQuestionReferenceGuard);
migrationBuilder.Sql(PostgreSqlTenantConstraintSql.CreateTaxonomyParentGuard);
migrationBuilder.EnsureTenantIsolationGuards();
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.Sql(PostgreSqlTenantConstraintSql.DropTenantGuards);
migrationBuilder.DropTenantIsolationGuards();
migrationBuilder.DropForeignKey(
name: "fk_content_entries_regions_tenant_id_region_id",

View File

@@ -0,0 +1,18 @@
using Microsoft.EntityFrameworkCore.Migrations;
namespace Tiku.Infrastructure.Persistence.Migrations;
internal static class MigrationBuilderTenantGuardExtensions
{
public static void EnsureTenantIsolationGuards(this MigrationBuilder migrationBuilder)
{
migrationBuilder.Sql(PostgreSqlTenantConstraintSql.DropTenantGuards);
migrationBuilder.Sql(PostgreSqlTenantConstraintSql.CreateTenantQuestionReferenceGuard);
migrationBuilder.Sql(PostgreSqlTenantConstraintSql.CreateTaxonomyParentGuard);
}
public static void DropTenantIsolationGuards(this MigrationBuilder migrationBuilder)
{
migrationBuilder.Sql(PostgreSqlTenantConstraintSql.DropTenantGuards);
}
}