refactor: migrate legacy wire namespace to wrn
Quality / quality (ubuntu-latest) (push) Failing after 9m49s
Quality / quality (windows-latest) (push) Canceled after 0s

This commit is contained in:
2026-08-12 18:51:15 +05:30
parent ec23dd4c93
commit 2c960fc1dc
488 changed files with 27306 additions and 19063 deletions
+2 -2
View File
@@ -128,7 +128,7 @@ const events = await getDb("analytics").all("SELECT * FROM hits");
Migrations are `.sql` files (in e.g. `app/db/migrations`), each split into
`-- +up` and `-- +down` sections. A file with no markers is treated entirely as
`up`. Applied names are recorded in a `_wire_migrations` table so each runs once.
`up`. Applied names are recorded in a `_wrn_migrations` table so each runs once.
- `parseMigration(name, content)``Migration` (`{ name, up, down }`).
- `loadMigrations(dir)` — parse all `.sql` files, sorted by filename.
@@ -249,7 +249,7 @@ SQL driver — use `@wrnexus/db/mongo` directly.
- **Bun-only.** Uses `bun:sqlite` (SQLite adapter + session store) and `Bun.SQL`
(Postgres/MySQL). Migrations/scaffolding use `node:fs`/`node:path`.
- Works with `@wrnexus/core``sqliteSessionStore` implements its
`SessionBackend`; `getDb`/`setDb` are wired by the WrNexus runtime from
`SessionBackend`; `getDb`/`setDb` are connected by the WrNexus runtime from
`wrnexus.config.ts`.
- The `mongodb` npm package is an optional, lazily-imported peer — install it
only if you use `@wrnexus/db/mongo`. The core package stays dependency-free.
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@wrnexus/db",
"version": "0.8.8",
"version": "0.8.9",
"private": true,
"type": "module",
"main": "./src/index.ts",
+3 -3
View File
@@ -1,7 +1,7 @@
/**
* Migration runner. Migrations are `.sql` files in `app/db/migrations`, each
* split into `-- +up` and `-- +down` sections. Applied migrations are recorded
* in a `_wire_migrations` table so they run exactly once, newest-last.
* in a `_wrn_migrations` table so they run exactly once, newest-last.
*
* `scaffoldMigration(..., models)` writes an initial migration straight from the
* TS models — the source of truth — so you don't hand-write the first schema.
@@ -19,8 +19,8 @@ export interface Migration {
down: string;
}
const MIGRATIONS_TABLE = "_wire_migrations";
const MIGRATION_LOCKS_TABLE = "_wire_migration_locks";
const MIGRATIONS_TABLE = "_wrn_migrations";
const MIGRATION_LOCKS_TABLE = "_wrn_migration_locks";
export interface MigrationRunOptions {
/** Return pending migration names without executing their SQL. */
+1 -1
View File
@@ -55,7 +55,7 @@ export async function paginate<T = Row>(
const perPage = Math.min(maxPerPage, Math.max(1, Math.floor(opts.perPage ?? 20)));
const offset = (page - 1) * perPage;
const countSql = query.countSql ?? `SELECT COUNT(*) AS n FROM (${query.sql}) AS __wire_sub`;
const countSql = query.countSql ?? `SELECT COUNT(*) AS n FROM (${query.sql}) AS __wrn_sub`;
const countRow = await db.one<{ n: number | string }>(countSql, params);
const total = Number(countRow?.n ?? 0);
+4 -4
View File
@@ -105,7 +105,7 @@ for (const [label, driver] of [
}
test("migration runner: parse, migrate, status, rollback", async () => {
const dir = mkdtempSync(join(tmpdir(), "wire-mig-"));
const dir = mkdtempSync(join(tmpdir(), "wrn-mig-"));
writeFileSync(
join(dir, "0001_init.sql"),
"-- +up\nCREATE TABLE t (id INTEGER PRIMARY KEY, n TEXT);\n-- +down\nDROP TABLE t;",
@@ -166,15 +166,15 @@ test("migration lock rejects a concurrent runner and recovers expired locks", as
const db = createDb(sqlite());
const migrations = [{ name: "0001_lock", up: "CREATE TABLE locked_test (id INTEGER)", down: "" }];
await db.exec(
"CREATE TABLE _wire_migration_locks (name TEXT PRIMARY KEY, owner TEXT NOT NULL, expires_at TEXT NOT NULL)",
"CREATE TABLE _wrn_migration_locks (name TEXT PRIMARY KEY, owner TEXT NOT NULL, expires_at TEXT NOT NULL)",
);
await db.exec("INSERT INTO _wire_migration_locks (name, owner, expires_at) VALUES (?, ?, ?)", [
await db.exec("INSERT INTO _wrn_migration_locks (name, owner, expires_at) VALUES (?, ?, ?)", [
"global",
"other",
new Date(Date.now() + 60_000).toISOString(),
]);
await expect(applyMigrations(db, migrations)).rejects.toThrow("WRN-DB-MIGRATION-LOCKED");
await db.exec("UPDATE _wire_migration_locks SET expires_at = ?", [new Date(0).toISOString()]);
await db.exec("UPDATE _wrn_migration_locks SET expires_at = ?", [new Date(0).toISOString()]);
expect(await applyMigrations(db, migrations)).toEqual(["0001_lock"]);
await db.close();
});