feat(server): cleanup legacy compatibility (#15239)

This commit is contained in:
DarkSky
2026-07-15 03:01:51 +08:00
committed by GitHub
parent 00d4ab10a1
commit e145d87d56
104 changed files with 3184 additions and 8883 deletions
@@ -30,13 +30,13 @@ test.after.always(async t => {
test('permission backfill repairs ownerless workspaces before runtime state projection', async t => {
const emptyWorkspace = await t.context.db.workspace.create({
data: { public: false },
data: { accessPolicy: { create: {} } },
});
const member = await t.context.models.user.create({
email: 'member@affine.pro',
});
const memberWorkspace = await t.context.db.workspace.create({
data: { public: false },
data: { accessPolicy: { create: {} } },
});
await t.context.db.workspaceMember.create({
data: {
@@ -80,13 +80,4 @@ test('permission backfill repairs ownerless workspaces before runtime state proj
}),
{ role: 'owner' }
);
t.like(
await t.context.db.workspaceUserRole.findFirstOrThrow({
where: {
workspaceId: memberWorkspace.id,
userId: member.id,
},
}),
{ type: 99 }
);
});
@@ -1,12 +1,8 @@
import { ModuleRef } from '@nestjs/core';
import { PrismaClient } from '@prisma/client';
import { Models } from '../../models';
export class BackfillPermissionProjection1765500000000 {
static async up(db: PrismaClient, ref: ModuleRef) {
const models = ref.get(Models, { strict: false });
await models.permissionProjection.backfillLegacyProjection();
static async up(db: PrismaClient, _ref: ModuleRef) {
await ensureWorkspaceAdminStatsDirtyTriggerGuard(db);
await repairOwnerlessWorkspaces(db);
await backfillUnknownQuotaRuntimeStates(db);
@@ -134,29 +130,6 @@ async function backfillUnknownQuotaRuntimeStates(db: PrismaClient) {
stale = true,
updated_at = now()
`;
await db.$executeRaw`
INSERT INTO workspace_runtime_states (
workspace_id,
known,
readonly,
readonly_reasons,
last_reconciled_at,
stale_after,
updated_at
)
SELECT
workspace_id,
false,
false,
ARRAY[]::text[],
NULL,
NULL,
now()
FROM effective_workspace_quota_states
ON CONFLICT (workspace_id)
DO NOTHING
`;
}
async function repairOwnerlessWorkspaces(db: PrismaClient) {
@@ -1,15 +1,8 @@
import { ModuleRef } from '@nestjs/core';
import { PrismaClient } from '@prisma/client';
import { LegacyEntitlementProjectionService } from '../../core/entitlement';
export class BackfillEntitlementProjection1765600000000 {
static async up(_db: PrismaClient, ref: ModuleRef) {
const projection = ref.get(LegacyEntitlementProjectionService, {
strict: false,
});
await projection.shadowBackfillEntitlementsAndQuotaStates();
}
static async up(_db: PrismaClient, _ref: ModuleRef) {}
static async down(_db: PrismaClient) {}
}