feat(backend): add DB persistence layer

Replace raw pg Pool with Drizzle ORM backed by Bun.sql.
Add per-user source configuration table (user_sources).
Migrate Better Auth to drizzle-adapter.
Add AES-256-GCM credential encryption.

Co-authored-by: Ona <no-reply@ona.com>
This commit is contained in:
2026-03-16 01:19:26 +00:00
parent 9ac88d921c
commit b813f27f0a
27 changed files with 1543 additions and 115 deletions

View File

@@ -1,10 +1,19 @@
import { betterAuth } from "better-auth"
import { drizzleAdapter } from "better-auth/adapters/drizzle"
import { pool } from "../db.ts"
import type { Database } from "../db/index.ts"
import * as schema from "../db/schema.ts"
export const auth = betterAuth({
database: pool,
emailAndPassword: {
enabled: true,
},
})
export function createAuth(db: Database) {
return betterAuth({
database: drizzleAdapter(db, {
provider: "pg",
schema,
}),
emailAndPassword: {
enabled: true,
},
})
}
export type Auth = ReturnType<typeof createAuth>