Skip to content

Commit

Permalink
chore: refresh existed user
Browse files Browse the repository at this point in the history
  • Loading branch information
darkskygit committed Apr 16, 2024
1 parent 9d43095 commit a9c3914
Showing 1 changed file with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
import { ModuleRef } from '@nestjs/core';
import { PrismaClient } from '@prisma/client';

import { QuotaType } from '../../core/quota/types';
import { QuotaService, QuotaType } from '../../core/quota';
import { UserService } from '../../core/user';
import { Config } from '../../fundamentals';
import { upgradeLatestQuotaVersion } from './utils/user-quotas';

export class RefreshNewPlan1713258139569 {
// do the migration
static async up(db: PrismaClient) {
await upgradeLatestQuotaVersion(db, QuotaType.SelfHostedPlanV1, '');
static async up(db: PrismaClient, ref: ModuleRef) {
const config = ref.get(Config, { strict: false });
const { AFFINE_ADMIN_EMAIL } = process.env;
if (config.isSelfhosted && AFFINE_ADMIN_EMAIL) {
const user = ref.get(UserService, { strict: false });
const quota = ref.get(QuotaService, { strict: false });
const { id } = (await user.findUserByEmail(AFFINE_ADMIN_EMAIL)) || {};
if (id) {
await upgradeLatestQuotaVersion(db, QuotaType.SelfHostedPlanV1, '');
await quota.switchUserQuota(id, QuotaType.SelfHostedPlanV1);
}
}
}

// revert the migration
Expand Down

0 comments on commit a9c3914

Please sign in to comment.