mirror of
https://github.com/alkimake/paperclip.git
synced 2026-06-19 12:10:37 +09:00
feat(costs): add billing, quota, and budget control plane
This commit is contained in:
parent
656b4659fc
commit
76e6cc08a6
91 changed files with 22406 additions and 769 deletions
43
packages/db/src/schema/budget_policies.ts
Normal file
43
packages/db/src/schema/budget_policies.ts
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
import { boolean, index, integer, pgTable, text, timestamp, uuid, uniqueIndex } from "drizzle-orm/pg-core";
|
||||
import { companies } from "./companies.js";
|
||||
|
||||
export const budgetPolicies = pgTable(
|
||||
"budget_policies",
|
||||
{
|
||||
id: uuid("id").primaryKey().defaultRandom(),
|
||||
companyId: uuid("company_id").notNull().references(() => companies.id),
|
||||
scopeType: text("scope_type").notNull(),
|
||||
scopeId: uuid("scope_id").notNull(),
|
||||
metric: text("metric").notNull().default("billed_cents"),
|
||||
windowKind: text("window_kind").notNull(),
|
||||
amount: integer("amount").notNull().default(0),
|
||||
warnPercent: integer("warn_percent").notNull().default(80),
|
||||
hardStopEnabled: boolean("hard_stop_enabled").notNull().default(true),
|
||||
notifyEnabled: boolean("notify_enabled").notNull().default(true),
|
||||
isActive: boolean("is_active").notNull().default(true),
|
||||
createdByUserId: text("created_by_user_id"),
|
||||
updatedByUserId: text("updated_by_user_id"),
|
||||
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
||||
updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
|
||||
},
|
||||
(table) => ({
|
||||
companyScopeActiveIdx: index("budget_policies_company_scope_active_idx").on(
|
||||
table.companyId,
|
||||
table.scopeType,
|
||||
table.scopeId,
|
||||
table.isActive,
|
||||
),
|
||||
companyWindowIdx: index("budget_policies_company_window_idx").on(
|
||||
table.companyId,
|
||||
table.windowKind,
|
||||
table.metric,
|
||||
),
|
||||
companyScopeMetricUniqueIdx: uniqueIndex("budget_policies_company_scope_metric_unique_idx").on(
|
||||
table.companyId,
|
||||
table.scopeType,
|
||||
table.scopeId,
|
||||
table.metric,
|
||||
table.windowKind,
|
||||
),
|
||||
}),
|
||||
);
|
||||
Loading…
Add table
Add a link
Reference in a new issue