chore: server-and-serverless template

This commit is contained in:
e2e
2026-06-28 16:06:43 +02:00
commit b58a1238dc
202 changed files with 9063 additions and 0 deletions

67
db/sqlite/0001-init.sql Normal file
View File

@@ -0,0 +1,67 @@
PRAGMA foreign_keys = ON;
-- Better Auth core schema. These four tables (user, session, account,
-- verification) are owned and written entirely by Better Auth — the app never
-- inserts into them directly; sign-up / sign-in / sessions all flow through the
-- generated `/api/auth/**` routes (see src/auth.ts).
--
-- The schema is generated by Better Auth's own migration generator
-- (`getMigrations(...).compileMigrations()`); the columns are spelled in
-- snake_case to match the rest of the app's DB convention. Better Auth is handed
-- the app's kysely (with CamelCasePlugin) in src/auth.ts, so its camelCase field
-- names (emailVerified, userId, createdAt, ...) compile to exactly these
-- snake_case columns at runtime. To change this schema (add a provider field, a
-- plugin table, ...), re-run the generator rather than hand-editing.
--
-- Email + password is the default sign-in method. The credential hash is stored
-- by Better Auth in account.password (provider_id = 'credential'), never on the
-- user row.
CREATE TABLE IF NOT EXISTS "user" (
"id" text not null primary key,
"name" text not null,
"email" text not null unique,
"email_verified" integer not null,
"image" text,
"created_at" date not null,
"updated_at" date not null
);
CREATE TABLE IF NOT EXISTS "session" (
"id" text not null primary key,
"expires_at" date not null,
"token" text not null unique,
"created_at" date not null,
"updated_at" date not null,
"ip_address" text,
"user_agent" text,
"user_id" text not null references "user" ("id") on delete cascade
);
CREATE TABLE IF NOT EXISTS "account" (
"id" text not null primary key,
"account_id" text not null,
"provider_id" text not null,
"user_id" text not null references "user" ("id") on delete cascade,
"access_token" text,
"refresh_token" text,
"id_token" text,
"access_token_expires_at" date,
"refresh_token_expires_at" date,
"scope" text,
"password" text,
"created_at" date not null,
"updated_at" date not null
);
CREATE TABLE IF NOT EXISTS "verification" (
"id" text not null primary key,
"identifier" text not null,
"value" text not null,
"expires_at" date not null,
"created_at" date not null,
"updated_at" date not null
);
CREATE INDEX IF NOT EXISTS "session_user_id_idx" ON "session" ("user_id");
CREATE INDEX IF NOT EXISTS "account_user_id_idx" ON "account" ("user_id");
CREATE INDEX IF NOT EXISTS "verification_identifier_idx" ON "verification" ("identifier");

View File

@@ -0,0 +1,12 @@
PRAGMA foreign_keys = ON;
-- Demo "hello world" persistence: a single editable message that shows the full
-- loop (sign in -> read from the DB -> write back -> see who last changed it).
-- Singleton row, always id = 1. Safe to delete this table and its functions
-- (get-message / update-message) once you start building your own thing.
CREATE TABLE IF NOT EXISTS message_state (
id INTEGER PRIMARY KEY,
message TEXT NOT NULL,
updated_at TEXT NOT NULL DEFAULT (datetime('now')),
updated_by_user_id TEXT REFERENCES "user" ("id")
);

26
db/sqlite/0003-audit.sql Normal file
View File

@@ -0,0 +1,26 @@
-- Audit log. Fabric's audit service flushes events here via a per-stage
-- CF Queue. Add this table if you want audit capture; remove it (and skip
-- this migration) if your project has no audit requirements.
CREATE TABLE IF NOT EXISTS audit (
audit_id TEXT NOT NULL PRIMARY KEY DEFAULT (lower(hex(randomblob(16)))),
occurred_at TEXT NOT NULL DEFAULT (datetime('now')),
type TEXT NOT NULL,
source TEXT NOT NULL DEFAULT 'auto',
outcome TEXT,
function_id TEXT,
wire_type TEXT,
trace_id TEXT,
transaction_id TEXT,
query_id TEXT,
actor_user_id TEXT,
actor_org_id TEXT,
tables TEXT, -- JSON array of table names touched
changed_cols TEXT, -- JSON array of changed column names
event TEXT, -- custom event label
old TEXT, -- JSON: previous values
data TEXT -- JSON: new values / event payload
);
CREATE INDEX IF NOT EXISTS idx_audit_occurred_at ON audit (occurred_at);
CREATE INDEX IF NOT EXISTS idx_audit_actor ON audit (actor_user_id) WHERE actor_user_id IS NOT NULL;
CREATE INDEX IF NOT EXISTS idx_audit_function ON audit (function_id) WHERE function_id IS NOT NULL;