Openstatus
www.openstatus.dev
1import { relations, sql } from "drizzle-orm";
2import { integer, sqliteTable, text, unique } from "drizzle-orm/sqlite-core";
3
4import { monitor } from "../monitors";
5import { notification } from "../notifications";
6import { page } from "../pages";
7import { usersToWorkspaces } from "../users";
8import { workspacePlans } from "./constants";
9
10export const workspace = sqliteTable(
11 "workspace",
12 {
13 id: integer("id").primaryKey(),
14 slug: text("slug").notNull().unique(), // we love random words
15 name: text("name"),
16
17 stripeId: text("stripe_id", { length: 256 }).unique(),
18 subscriptionId: text("subscription_id"),
19 plan: text("plan", { enum: workspacePlans }),
20 endsAt: integer("ends_at", { mode: "timestamp" }),
21 paidUntil: integer("paid_until", { mode: "timestamp" }),
22 limits: text("limits").default("{}").notNull(),
23 createdAt: integer("created_at", { mode: "timestamp" }).default(
24 sql`(strftime('%s', 'now'))`,
25 ),
26 updatedAt: integer("updated_at", { mode: "timestamp" }).default(
27 sql`(strftime('%s', 'now'))`,
28 ),
29
30 dsn: text("dsn"), // should be removed soon
31 },
32 (t) => ({
33 unique: unique().on(t.id, t.dsn),
34 }),
35);
36
37export const workspaceRelations = relations(workspace, ({ many }) => ({
38 usersToWorkspaces: many(usersToWorkspaces),
39 pages: many(page),
40 monitors: many(monitor),
41 notifications: many(notification),
42 // TODO: add checks or monitorRuns
43}));