Initial import
This commit is contained in:
50
packages/db/src/bootstrap.ts
Normal file
50
packages/db/src/bootstrap.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
import { Prisma, type PrismaClient } from "@prisma/client";
|
||||
import { prisma as defaultPrisma } from "./prisma-client.js";
|
||||
|
||||
export interface SubscriptionPlanSeedInput {
|
||||
code: string;
|
||||
displayName: string;
|
||||
monthlyRequestLimit: number;
|
||||
monthlyPriceUsd: number;
|
||||
billingCurrency: string;
|
||||
}
|
||||
|
||||
export const defaultSubscriptionPlanSeed: SubscriptionPlanSeedInput = {
|
||||
code: "mvp_monthly",
|
||||
displayName: "MVP Monthly",
|
||||
monthlyRequestLimit: 100,
|
||||
monthlyPriceUsd: 9.99,
|
||||
billingCurrency: "USDT",
|
||||
};
|
||||
|
||||
export async function ensureSubscriptionPlan(
|
||||
input: SubscriptionPlanSeedInput,
|
||||
database: PrismaClient = defaultPrisma,
|
||||
): Promise<void> {
|
||||
await database.subscriptionPlan.upsert({
|
||||
where: {
|
||||
code: input.code,
|
||||
},
|
||||
update: {
|
||||
displayName: input.displayName,
|
||||
monthlyRequestLimit: input.monthlyRequestLimit,
|
||||
monthlyPriceUsd: new Prisma.Decimal(input.monthlyPriceUsd),
|
||||
billingCurrency: input.billingCurrency,
|
||||
isActive: true,
|
||||
},
|
||||
create: {
|
||||
code: input.code,
|
||||
displayName: input.displayName,
|
||||
monthlyRequestLimit: input.monthlyRequestLimit,
|
||||
monthlyPriceUsd: new Prisma.Decimal(input.monthlyPriceUsd),
|
||||
billingCurrency: input.billingCurrency,
|
||||
isActive: true,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export async function ensureDefaultSubscriptionPlan(
|
||||
database: PrismaClient = defaultPrisma,
|
||||
): Promise<void> {
|
||||
await ensureSubscriptionPlan(defaultSubscriptionPlanSeed, database);
|
||||
}
|
||||
Reference in New Issue
Block a user