-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
de40844
commit 908cd18
Showing
4 changed files
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
packages/backend/server/src/data/migrations/1713258139569-refresh-new-plan.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { ModuleRef } from '@nestjs/core'; | ||
import { PrismaClient } from '@prisma/client'; | ||
|
||
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, 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.UnlimitedPlanV1, ''); | ||
await quota.switchUserQuota(id, QuotaType.UnlimitedPlanV1); | ||
} | ||
} | ||
} | ||
|
||
// revert the migration | ||
static async down(_db: PrismaClient) {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters