Files
dahoam/src/db/schema.ts
T
niklas 4b9690e064
images / check (push) Successful in 28s
images / image (push) Successful in 24s
feat: a slider darkens the wallpaper, the dots and the fade are gone
2026-11-18 17:06:40 +01:00

150 lines
4.4 KiB
TypeScript

import {
boolean,
customType,
index,
integer,
pgTable,
text,
timestamp,
uuid,
} from "drizzle-orm/pg-core"
// ---- Better Auth core tables ----
export const user = pgTable("user", {
id: text("id").primaryKey(),
name: text("name").notNull(),
email: text("email").notNull().unique(),
emailVerified: boolean("email_verified").notNull().default(false),
image: text("image"),
createdAt: timestamp("created_at").notNull().defaultNow(),
updatedAt: timestamp("updated_at").notNull().defaultNow(),
})
export const session = pgTable(
"session",
{
id: text("id").primaryKey(),
expiresAt: timestamp("expires_at").notNull(),
token: text("token").notNull().unique(),
createdAt: timestamp("created_at").notNull().defaultNow(),
updatedAt: timestamp("updated_at").notNull().defaultNow(),
ipAddress: text("ip_address"),
userAgent: text("user_agent"),
userId: text("user_id")
.notNull()
.references(() => user.id, { onDelete: "cascade" }),
},
(t) => [index("session_user_id_idx").on(t.userId)]
)
export const account = pgTable(
"account",
{
id: text("id").primaryKey(),
accountId: text("account_id").notNull(),
providerId: text("provider_id").notNull(),
userId: text("user_id")
.notNull()
.references(() => user.id, { onDelete: "cascade" }),
accessToken: text("access_token"),
refreshToken: text("refresh_token"),
idToken: text("id_token"),
accessTokenExpiresAt: timestamp("access_token_expires_at"),
refreshTokenExpiresAt: timestamp("refresh_token_expires_at"),
scope: text("scope"),
password: text("password"),
createdAt: timestamp("created_at").notNull().defaultNow(),
updatedAt: timestamp("updated_at").notNull().defaultNow(),
},
(t) => [index("account_user_id_idx").on(t.userId)]
)
export const verification = pgTable(
"verification",
{
id: text("id").primaryKey(),
identifier: text("identifier").notNull(),
value: text("value").notNull(),
expiresAt: timestamp("expires_at").notNull(),
createdAt: timestamp("created_at").notNull().defaultNow(),
updatedAt: timestamp("updated_at").notNull().defaultNow(),
},
(t) => [index("verification_identifier_idx").on(t.identifier)]
)
// ---- Dashboard tables ----
const bytea = customType<{ data: Uint8Array }>({ dataType: () => "bytea" })
/** A named group of links on the dashboard. */
export const card = pgTable(
"card",
{
id: uuid("id").primaryKey().defaultRandom(),
userId: text("user_id")
.notNull()
.references(() => user.id, { onDelete: "cascade" }),
name: text("name").notNull(),
createdAt: timestamp("created_at").notNull().defaultNow(),
},
(t) => [index("card_user_id_idx").on(t.userId)]
)
export const link = pgTable(
"link",
{
id: uuid("id").primaryKey().defaultRandom(),
userId: text("user_id")
.notNull()
.references(() => user.id, { onDelete: "cascade" }),
cardId: uuid("card_id")
.notNull()
.references(() => card.id, { onDelete: "cascade" }),
// order inside the card
position: integer("position").notNull().default(0),
name: text("name").notNull(),
url: text("url").notNull(),
// image URL or a dashboard-icons name ("plex"); null = guess from name
icon: text("icon"),
createdAt: timestamp("created_at").notNull().defaultNow(),
},
(t) => [
index("link_user_id_idx").on(t.userId),
index("link_card_id_idx").on(t.cardId),
]
)
export const settings = pgTable("settings", {
userId: text("user_id")
.primaryKey()
.references(() => user.id, { onDelete: "cascade" }),
title: text("title").notNull().default("Dahoam"),
searchEngine: text("search_engine", {
enum: ["duckduckgo", "searxng", "google"],
})
.notNull()
.default("duckduckgo"),
// null = bundled default wallpaper
wallpaperUrl: text("wallpaper_url"),
// percent of black over the wallpaper, see DEFAULT_WALLPAPER_DIM
wallpaperDim: integer("wallpaper_dim").notNull().default(40),
// the big clock, see src/lib/clock.ts
clockFont: text("clock_font", {
enum: ["serif", "sans", "light", "rounded", "slab"],
})
.notNull()
.default("serif"),
clockStyle: text("clock_style", { enum: ["solid", "glass", "tinted"] })
.notNull()
.default("solid"),
})
export const wallpaper = pgTable("wallpaper", {
userId: text("user_id")
.primaryKey()
.references(() => user.id, { onDelete: "cascade" }),
mime: text("mime").notNull(),
data: bytea("data").notNull(),
})