mirror of
https://github.com/fosrl/pangolin.git
synced 2026-08-11 15:08:36 +02:00
Remove budget periods
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { aiBudgetPeriods } from "@server/db/sqlite";
|
||||
import { randomUUID } from "crypto";
|
||||
import { InferSelectModel, sql } from "drizzle-orm";
|
||||
import {
|
||||
@@ -1721,10 +1722,20 @@ export const aiBudgets = pgTable(
|
||||
() => siteResources.siteResourceId,
|
||||
{ onDelete: "cascade" }
|
||||
),
|
||||
roleId: integer("roleId").references(() => roles.roleId, {
|
||||
onDelete: "cascade"
|
||||
}),
|
||||
amount: real("amount").notNull(),
|
||||
unit: varchar("unit").$type<"usd" | "tokens">().notNull(),
|
||||
period: varchar("period")
|
||||
.$type<"monthly">()
|
||||
.$type<
|
||||
| "monthly"
|
||||
| "yearly"
|
||||
| "lifetime"
|
||||
| "daily"
|
||||
| "hourly"
|
||||
| "weekly"
|
||||
>()
|
||||
.notNull()
|
||||
.default("monthly"),
|
||||
enforcement: varchar("enforcement")
|
||||
@@ -1752,20 +1763,6 @@ export const aiBudgets = pgTable(
|
||||
]
|
||||
);
|
||||
|
||||
export const aiBudgetPeriods = pgTable(
|
||||
"aiBudgetPeriods",
|
||||
{
|
||||
periodId: serial("periodId").primaryKey(),
|
||||
budgetId: integer("budgetId")
|
||||
.notNull()
|
||||
.references(() => aiBudgets.budgetId, { onDelete: "cascade" }),
|
||||
periodStart: bigint("periodStart", { mode: "number" }).notNull(),
|
||||
periodEnd: bigint("periodEnd", { mode: "number" }).notNull(),
|
||||
usedAmount: real("usedAmount").notNull().default(0)
|
||||
},
|
||||
(t) => [unique("ai_budget_period_start_uniq").on(t.budgetId, t.periodStart)]
|
||||
);
|
||||
|
||||
export type Org = InferSelectModel<typeof orgs>;
|
||||
export type User = InferSelectModel<typeof users>;
|
||||
export type Site = InferSelectModel<typeof sites>;
|
||||
@@ -1853,7 +1850,6 @@ export type ResourcePolicyRule = InferSelectModel<typeof resourcePolicyRules>;
|
||||
export type AiProvider = InferSelectModel<typeof aiProviders>;
|
||||
export type AiModel = InferSelectModel<typeof aiModels>;
|
||||
export type AiBudget = InferSelectModel<typeof aiBudgets>;
|
||||
export type AiBudgetPeriod = InferSelectModel<typeof aiBudgetPeriods>;
|
||||
export type ResourceAiProvider = InferSelectModel<typeof resourceAiProviders>;
|
||||
export type SiteResourceAiProvider = InferSelectModel<
|
||||
typeof siteResourceAiProviders
|
||||
|
||||
@@ -1705,9 +1705,22 @@ export const aiBudgets = sqliteTable(
|
||||
() => siteResources.siteResourceId,
|
||||
{ onDelete: "cascade" }
|
||||
),
|
||||
roleId: integer("roleId").references(() => roles.roleId, {
|
||||
onDelete: "cascade"
|
||||
}),
|
||||
amount: real("amount").notNull(),
|
||||
unit: text("unit").$type<"usd" | "tokens">().notNull(),
|
||||
period: text("period").$type<"monthly">().notNull().default("monthly"),
|
||||
period: text("period")
|
||||
.$type<
|
||||
| "monthly"
|
||||
| "yearly"
|
||||
| "lifetime"
|
||||
| "daily"
|
||||
| "hourly"
|
||||
| "weekly"
|
||||
>()
|
||||
.notNull()
|
||||
.default("monthly"),
|
||||
enforcement: text("enforcement")
|
||||
.$type<"hard" | "soft">()
|
||||
.notNull()
|
||||
@@ -1726,20 +1739,6 @@ export const aiBudgets = sqliteTable(
|
||||
]
|
||||
);
|
||||
|
||||
export const aiBudgetPeriods = sqliteTable(
|
||||
"aiBudgetPeriods",
|
||||
{
|
||||
periodId: integer("periodId").primaryKey({ autoIncrement: true }),
|
||||
budgetId: integer("budgetId")
|
||||
.notNull()
|
||||
.references(() => aiBudgets.budgetId, { onDelete: "cascade" }),
|
||||
periodStart: integer("periodStart").notNull(),
|
||||
periodEnd: integer("periodEnd").notNull(),
|
||||
usedAmount: real("usedAmount").notNull().default(0)
|
||||
},
|
||||
(t) => [unique("ai_budget_period_start_uniq").on(t.budgetId, t.periodStart)]
|
||||
);
|
||||
|
||||
export type Org = InferSelectModel<typeof orgs>;
|
||||
export type User = InferSelectModel<typeof users>;
|
||||
export type Site = InferSelectModel<typeof sites>;
|
||||
@@ -1825,7 +1824,6 @@ export type UserPolicy = InferSelectModel<typeof userPolicies>;
|
||||
export type AiProvider = InferSelectModel<typeof aiProviders>;
|
||||
export type AiModel = InferSelectModel<typeof aiModels>;
|
||||
export type AiBudget = InferSelectModel<typeof aiBudgets>;
|
||||
export type AiBudgetPeriod = InferSelectModel<typeof aiBudgetPeriods>;
|
||||
export type ResourceAiProvider = InferSelectModel<typeof resourceAiProviders>;
|
||||
export type SiteResourceAiProvider = InferSelectModel<
|
||||
typeof siteResourceAiProviders
|
||||
|
||||
Reference in New Issue
Block a user