Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/openstatusHQ/openstatus. ๐ซ Status page with uptime monitoring & API monitoring as code ๐ซ openstatus.dev
bun drizzle-orm monitoring monitoring-as-code nextjs observability on-call open-source shadcn-ui status-page statuspage synthetic-monitoring tinybird turso uptime uptime-checker uptime-monitor
Something went wrong. Try again.
TypeScript
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127import { relations, sql } from "drizzle-orm";import { index, integer, primaryKey, sqliteTable, text,} from "drizzle-orm/sqlite-core";import type { AdapterAccount } from "next-auth/adapters";
import { workspace, workspaceRole } from "../workspaces";
export const user = sqliteTable( "user", { id: integer("id").primaryKey(),
// clerk fields tenantId: text("tenant_id", { length: 256 }).unique(), // the clerk User Id firstName: text("first_name").default(""), lastName: text("last_name").default(""), photoUrl: text("photo_url").default(""),
// next-auth fields name: text("name"), email: text("email").default(""), emailVerified: integer("emailVerified", { mode: "timestamp_ms" }),
createdAt: integer("created_at", { mode: "timestamp" }).default( sql`(strftime('%s', 'now'))`, ), updatedAt: integer("updated_at", { mode: "timestamp" }).default( sql`(strftime('%s', 'now'))`, ), deletedAt: integer("deleted_at", { mode: "timestamp" }), }, // Plain, not LOWER(email): @auth/drizzle-adapter's getUserByEmail does an // exact eq() match, which an expression index would not serve. (table) => [index("user_email_idx").on(table.email)],);
export const userRelations = relations(user, ({ many }) => ({ usersToWorkspaces: many(usersToWorkspaces),}));
export const usersToWorkspaces = sqliteTable( "users_to_workspaces", { userId: integer("user_id") .notNull() .references(() => user.id), workspaceId: integer("workspace_id") .notNull() .references(() => workspace.id), role: text("role", { enum: workspaceRole }).notNull().default("member"), createdAt: integer("created_at", { mode: "timestamp" }).default( sql`(strftime('%s', 'now'))`, ), }, (t) => [ primaryKey({ columns: [t.userId, t.workspaceId] }), index("users_to_workspaces_workspace_id_idx").on(t.workspaceId), ],);
export const usersToWorkspaceRelations = relations( usersToWorkspaces, ({ one }) => ({ workspace: one(workspace, { fields: [usersToWorkspaces.workspaceId], references: [workspace.id], }), user: one(user, { fields: [usersToWorkspaces.userId], references: [user.id], }), }),);
// NEXT AUTH TABLES
export const account = sqliteTable( "account", { userId: integer("user_id") .notNull() .references(() => user.id, { onDelete: "cascade" }), type: text("type").$type<AdapterAccount["type"]>().notNull(), provider: text("provider").notNull(), providerAccountId: text("provider_account_id").notNull(), refresh_token: text("refresh_token"), access_token: text("access_token"), expires_at: integer("expires_at"), token_type: text("token_type"), scope: text("scope"), id_token: text("id_token"), session_state: text("session_state"), }, (account) => [ primaryKey({ columns: [account.provider, account.providerAccountId], }), ],);
export const session = sqliteTable( "session", { sessionToken: text("session_token").primaryKey(), userId: integer("user_id") .notNull() .references(() => user.id, { onDelete: "cascade" }), expires: integer("expires", { mode: "timestamp_ms" }).notNull(), }, (table) => [index("session_user_id_idx").on(table.userId)],);
export const verificationToken = sqliteTable( "verification_token", { identifier: text("identifier").notNull(), token: text("token").notNull(), expires: integer("expires", { mode: "timestamp_ms" }).notNull(), }, (vt) => [primaryKey({ columns: [vt.identifier, vt.token] })],);