Use ordered SQLite migrations (Refs #75)
CI / checks (push) Successful in 5m6s

This commit is contained in:
2026-10-10 00:01:18 -04:00
parent a0663e43b8
commit 8d1bb69591
56 changed files with 1085 additions and 736 deletions
+1 -4
View File
@@ -1,6 +1,5 @@
import { createHash, randomBytes, randomUUID, timingSafeEqual } from 'node:crypto';
import { db } from '../db/index.js';
import { ensureAuthSchema } from './schema.js';
import { hashPassword, verifyPassword } from './passwords.js';
import { systemUsername, type AuthUser, type UserRole } from '../../auth.js';
@@ -9,9 +8,7 @@ export const SESSION_LIFETIME_MS = 12 * 60 * 60_000;
export const SESSION_IDLE_MS = 30 * 60_000;
const digest = (value: string) => createHash('sha256').update(value).digest('hex');
function database() {
const handle = db();
ensureAuthSchema(handle);
return handle;
return db();
}
type UserRow = {
id: string;
+1 -4
View File
@@ -1,7 +1,5 @@
import type Database from 'better-sqlite3';
const initialized = new WeakSet<Database.Database>();
export function ensureAuthSchema(handle: Database.Database): void {
if (initialized.has(handle)) return;
export function migrateAuthSchema(handle: Database.Database): void {
handle.exec(`
CREATE TABLE IF NOT EXISTS auth_users (
id TEXT PRIMARY KEY, username TEXT NOT NULL COLLATE NOCASE UNIQUE,
@@ -24,5 +22,4 @@ export function ensureAuthSchema(handle: Database.Database): void {
);
CREATE INDEX IF NOT EXISTS auth_audit_created_at ON auth_audit(created_at);
`);
initialized.add(handle);
}