mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-24 05:48:59 +08:00
e516e0db23
- [x] separates modules into `fundamental`, `core`, `plugins`
- [x] optional modules with `@OptionalModule` decorator to install modules with requirements met(`requires`, `if`)
- [x] `module.contributesTo` defines optional features that will be enabled if module registered
- [x] `AFFiNE.plugins.use('payment', {})` to enable a optional/plugin module
- [x] `PaymentModule` is the first plugin module
- [x] GraphQLSchema will not be generated for non-included modules
- [x] Frontend can use `ServerConfigType` query to detect which features are enabled
- [x] override existing provider globally
37 lines
1.0 KiB
TypeScript
37 lines
1.0 KiB
TypeScript
import { PrismaClient } from '@prisma/client';
|
|
|
|
import { QuotaType } from '../../core/quota/types';
|
|
export class OldUserFeature1702620653283 {
|
|
// do the migration
|
|
static async up(db: PrismaClient) {
|
|
await db.$transaction(async tx => {
|
|
const latestFreePlan = await tx.features.findFirstOrThrow({
|
|
where: { feature: QuotaType.FreePlanV1 },
|
|
orderBy: { version: 'desc' },
|
|
select: { id: true },
|
|
});
|
|
|
|
// find all users that don't have any features
|
|
const userIds = await db.user.findMany({
|
|
where: { NOT: { features: { some: { NOT: { id: { gt: 0 } } } } } },
|
|
select: { id: true },
|
|
});
|
|
|
|
await tx.userFeatures.createMany({
|
|
data: userIds.map(({ id: userId }) => ({
|
|
userId,
|
|
featureId: latestFreePlan.id,
|
|
reason: 'old user feature migration',
|
|
activated: true,
|
|
})),
|
|
});
|
|
});
|
|
}
|
|
|
|
// revert the migration
|
|
// WARN: this will drop all user features
|
|
static async down(db: PrismaClient) {
|
|
await db.userFeatures.deleteMany({});
|
|
}
|
|
}
|