feat: Dahoam start page with accounts, cards and search
Replica of the reference start page: wallpaper, serif clock, search bar and link cards, as a TanStack Start app. - Better Auth: email/password and OIDC single sign-on - Postgres with Drizzle for the auth tables, cards, links, settings and uploaded wallpapers; the server applies the migrations on start - cards group links; links are dragged inside and between cards - search with DuckDuckGo, SearXNG or Google, suggestions and / commands - settings page: name, search engine, wallpaper, account - UI from collabry-components, copied into src/vendor/collabry - Dockerfile and a Gitea workflow that checks the code, builds the image for amd64 and arm64 and pushes it to the registry on main
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
import { drizzle } from "drizzle-orm/postgres-js"
|
||||
import { migrate } from "drizzle-orm/postgres-js/migrator"
|
||||
import * as schema from "./schema"
|
||||
|
||||
if (!process.env.DATABASE_URL) throw new Error("DATABASE_URL is not set")
|
||||
|
||||
export const db = drizzle({
|
||||
schema,
|
||||
connection: {
|
||||
url: process.env.DATABASE_URL,
|
||||
// the migrator's "already exists, skipping" on every start looks like an error in the log
|
||||
onnotice: () => {},
|
||||
},
|
||||
})
|
||||
|
||||
// The server brings the database up to date before it answers its first request
|
||||
// (the image has no drizzle-kit). A server on an old schema must not run: stop,
|
||||
// so that the restart policy tries again.
|
||||
await migrate(db, { migrationsFolder: "drizzle" }).catch((error) => {
|
||||
console.error("Database migration failed:", error)
|
||||
process.exit(1)
|
||||
})
|
||||
@@ -0,0 +1,138 @@
|
||||
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"),
|
||||
})
|
||||
|
||||
export const wallpaper = pgTable("wallpaper", {
|
||||
userId: text("user_id")
|
||||
.primaryKey()
|
||||
.references(() => user.id, { onDelete: "cascade" }),
|
||||
mime: text("mime").notNull(),
|
||||
data: bytea("data").notNull(),
|
||||
})
|
||||
Reference in New Issue
Block a user