Add override for limits

This commit is contained in:
Owen
2026-02-10 21:28:56 -08:00
committed by Owen Schwartz
parent 7ce5134415
commit f95e2f1f0e
3 changed files with 33 additions and 0 deletions

View File

@@ -140,6 +140,7 @@ export const limits = pgTable("limits", {
})
.notNull(),
value: real("value"),
override: boolean("override").default(false),
description: text("description")
});

View File

@@ -129,6 +129,7 @@ export const limits = sqliteTable("limits", {
})
.notNull(),
value: real("value"),
override: integer("override", { mode: "boolean" }).default(false),
description: text("description")
});

View File

@@ -2,6 +2,7 @@ import { db, limits } from "@server/db";
import { and, eq } from "drizzle-orm";
import { LimitSet } from "./limitSet";
import { FeatureId } from "./features";
import logger from "@server/logger";
class LimitService {
async applyLimitSetToOrg(orgId: string, limitSet: LimitSet): Promise<void> {
@@ -13,6 +14,36 @@ class LimitService {
for (const [featureId, entry] of limitEntries) {
const limitId = `${orgId}-${featureId}`;
const { value, description } = entry;
// get the limit first
const [limit] = await trx
.select()
.from(limits)
.where(eq(limits.limitId, limitId))
.limit(1);
if (!limit) {
logger.warn(
`Limit with ID ${limitId} not found for org ${orgId}...`
);
continue;
}
// check if its overriden
if (limit.override) {
logger.debug(
`Skipping limit ${limitId} for org ${orgId} since it is overridden...`
);
continue;
}
// dont write if the value is the same
if (limit.value === value) {
logger.debug(
`Skipping limit ${limitId} for org ${orgId} since the value is the same (${value})...`
);
continue;
}
await trx
.insert(limits)
.values({ limitId, orgId, featureId, value, description });