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

@@ -1,4 +1,6 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.Extensions.DependencyInjection;
using Tiku.IntegrationTests.Api;
using Tiku.Infrastructure.Persistence;
@@ -22,4 +24,22 @@ public sealed class MigrationExecutionTests
Assert.NotEmpty(appliedMigrations);
Assert.True(await dbContext.Database.CanConnectAsync());
}
[Fact]
public async Task Migration_script_contains_tenant_isolation_guard_triggers()
{
await using var factory = new ApiTestFactory();
using var scope = factory.Services.CreateScope();
var dbContext = scope.ServiceProvider.GetRequiredService<TikuDbContext>();
var migrator = dbContext.GetService<IMigrator>();
var script = migrator.GenerateScript();
Assert.Contains("drop trigger if exists trg_tenant_question_references_platform_or_self_owner", script);
Assert.Contains("create or replace function tiku_guard_tenant_question_reference()", script);
Assert.Contains("create trigger trg_tenant_question_references_platform_or_self_owner", script);
Assert.Contains("drop trigger if exists trg_taxonomy_nodes_parent_platform_or_self_owner", script);
Assert.Contains("create or replace function tiku_guard_taxonomy_parent_owner()", script);
Assert.Contains("create trigger trg_taxonomy_nodes_parent_platform_or_self_owner", script);
}
}