mirror of
https://github.com/profullstack/logicsrc.git
synced 2026-10-02 04:43:58 +00:00
feat(pwa): move app.logicsrc.com from Turso/libSQL to Postgres via @profullstack/libsql-pg (#218)
Production reads DATABASE_URL (postgres://) through @profullstack/libsql-pg, which keeps the @libsql/client surface; no query changed. A missing, non-Postgres or leftover libsql:// URL fails at boot in production. Dev and tests keep libSQL (file:/:memory:) as a devDependency. Postgres migrations in src/migrations-pg/ (converted with libsql-pg convert-schema, same file names so the copied _migrations ledger matches); migrate.mjs picks the dialect. Tests run against Postgres with PWA_TEST_DATABASE_URL. Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
parent
c535aaa32c
commit
4ac750e65b
12 changed files with 507 additions and 29 deletions
|
|
@ -1,6 +1,6 @@
|
|||
// Integration coverage for team-member CRUD, invite-key rotation, and the
|
||||
// dashboard controls that expose those operations.
|
||||
process.env.DATABASE_URL = ":memory:";
|
||||
process.env.DATABASE_URL = process.env.PWA_TEST_DATABASE_URL || ":memory:";
|
||||
|
||||
import test from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
|
|
@ -10,13 +10,19 @@ import { dirname, join } from "node:path";
|
|||
import express from "express";
|
||||
|
||||
const here = dirname(fileURLToPath(import.meta.url));
|
||||
const { db, run, get } = await import("../src/db.mjs");
|
||||
const { db, run, get, isPostgres } = await import("../src/db.mjs");
|
||||
const { sha256 } = await import("../src/lib/crypto.mjs");
|
||||
const { credshareRouter } = await import("../src/routes/credshare.mjs");
|
||||
const { pagesRouter } = await import("../src/routes/pages.mjs");
|
||||
|
||||
// Against a real Postgres (PWA_TEST_DATABASE_URL) start from an empty schema;
|
||||
// run with --test-concurrency=1 then, the files share one database.
|
||||
if (isPostgres) {
|
||||
await db.execute("DROP SCHEMA public CASCADE");
|
||||
await db.execute("CREATE SCHEMA public");
|
||||
}
|
||||
for (const file of ["001_auth.sql", "002_credshare.sql"]) {
|
||||
const sql = readFileSync(join(here, "..", "src", "migrations", file), "utf8");
|
||||
const sql = readFileSync(join(here, "..", "src", isPostgres ? "migrations-pg" : "migrations", file), "utf8");
|
||||
for (const statement of sql.split(/;\s*$/m).map((s) => s.trim()).filter(Boolean)) await db.execute(statement);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue