Let a super admin read the database from the app

A new super admin settings page, /admin/settings/database, lists every
table with its record count and size, and one page of the open table's
records newest key first. Values are cut inside SQL (400 characters, with
a flag saying so) and a record opens whole in a modal, so a table of long
texts reads without shipping it all. A search matches every column's
text, word by word or as a phrase, which is the one thing that also works
on a virtual table. Nothing in it writes: the catalog, the records and
the single record are all reads, GET only.
This commit is contained in:
2026-10-23 06:03:42 +01:00
parent 9b26c169d6
commit 41bb4aaac2
48 changed files with 2573 additions and 0 deletions
@@ -0,0 +1,20 @@
import BunSQLite from "@moduletrace/bun-sqlite";
import buildTableSizesSql, { type TableSizeRow } from "./build-table-sizes-sql";
/**
* How many bytes each table takes on disk, by table name. Empty when
* SQLite was built without the `dbstat` vtab, which only costs the browser
* its size column: the records still read.
*/
export default async function grabTableSizes(): Promise<Map<string, number>> {
const sizes = new Map<string, number>();
const res = await BunSQLite.sql<TableSizeRow>({ sql: buildTableSizesSql() });
if (!res.success || !res.payload) return sizes;
for (const row of res.payload) {
sizes.set(row.table_name, Number(row.bytes) || 0);
}
return sizes;
}