mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-13 12:55:00 +00:00
fix: upgrade plan correctly (#6543)
This commit is contained in:
@@ -1,14 +1,17 @@
|
||||
import { PrismaClient } from '@prisma/client';
|
||||
|
||||
import { Quotas } from '../../core/quota';
|
||||
import { upgradeQuotaVersion } from './utils/user-quotas';
|
||||
import { QuotaType } from '../../core/quota/types';
|
||||
import { upgradeLatestQuotaVersion } from './utils/user-quotas';
|
||||
|
||||
export class RefreshFreePlan1712224382221 {
|
||||
// do the migration
|
||||
static async up(db: PrismaClient) {
|
||||
// free plan 1.0
|
||||
const quota = Quotas[4];
|
||||
await upgradeQuotaVersion(db, quota, 'free plan 1.1 migration');
|
||||
// free plan 1.1
|
||||
await upgradeLatestQuotaVersion(
|
||||
db,
|
||||
QuotaType.FreePlanV1,
|
||||
'free plan 1.1 migration'
|
||||
);
|
||||
}
|
||||
|
||||
// revert the migration
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { PrismaClient } from '@prisma/client';
|
||||
|
||||
import { FeatureKind } from '../../../core/features';
|
||||
import { Quota } from '../../../core/quota/types';
|
||||
import { Quotas } from '../../../core/quota/schema';
|
||||
import { Quota, QuotaType } from '../../../core/quota/types';
|
||||
import { upsertFeature } from './user-features';
|
||||
|
||||
export async function upgradeQuotaVersion(
|
||||
@@ -63,3 +64,14 @@ export async function upgradeQuotaVersion(
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
export async function upgradeLatestQuotaVersion(
|
||||
db: PrismaClient,
|
||||
type: QuotaType,
|
||||
reason: string
|
||||
) {
|
||||
const quota = Quotas.filter(f => f.feature === type);
|
||||
quota.sort((a, b) => b.version - a.version);
|
||||
const latestQuota = quota[0];
|
||||
await upgradeQuotaVersion(db, latestQuota, reason);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user