Let the showcase seed write a deployed database with --production
A database under /var/lib/ngu is still refused by default; adding --production allows it, for a server that exists to be tested, and the script says which database it is writing. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
422e521394
commit
9b6d9b9aff
2 changed files with 17 additions and 5 deletions
|
|
@ -22,7 +22,7 @@ Backend (`server/`, Node >= 22). The server reads `HOST` (default `127.0.0.1`),
|
|||
- `DB_PATH=./dev.db pnpm dev`: run with `node --watch`
|
||||
- `DB_PATH=./dev.db pnpm migrate`: apply migrations without starting the server
|
||||
- `DB_PATH=./dev.db node src/admin-cli.js add|list|passwd|role|disable|enable ...`: the only way accounts are created
|
||||
- `DB_PATH=./dev.db node src/seed-showcase.js [--listed]`: writes fully filled test records (a region, chapter, team, award, person, three events and a blog post with every content block type), ids starting `showcase-`, for checking pages. Unlisted unless `--listed`. Local only; refuses /var/lib/ngu.
|
||||
- `DB_PATH=./dev.db node src/seed-showcase.js [--listed]`: writes fully filled test records (a region, chapter, team, award, person, three events and a blog post with every content block type), ids starting `showcase-`, for checking pages. Unlisted unless `--listed`. Refuses a database under /var/lib/ngu unless `--production` is also given.
|
||||
|
||||
In dev, Vite proxies `/api` to the target set in `vite.config.ts`, so the API must listen on that port.
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
/* ═══════════════════════════════════════════════════════════════
|
||||
SHOWCASE: local test records with every field filled in
|
||||
SHOWCASE: test records with every field filled in
|
||||
|
||||
DB_PATH=./dev.db node src/seed-showcase.js
|
||||
DB_PATH=./dev.db node src/seed-showcase.js --listed
|
||||
DB_PATH=/var/lib/ngu/ngu.db node src/seed-showcase.js --production
|
||||
|
||||
Writes one of each record kind with every field and option used,
|
||||
so a change to any page can be checked against a record that
|
||||
|
|
@ -39,20 +40,31 @@
|
|||
Admin → Media and copy it to that name in the uploads directory,
|
||||
or leave it missing to check how each page copes without one.
|
||||
|
||||
It refuses the production database (anything under /var/lib/ngu).
|
||||
A database under /var/lib/ngu (where the deployed service keeps
|
||||
its data) is refused unless --production is given too. That's for
|
||||
a server that exists to be tested; on the live site, back up the
|
||||
database first and leave --listed off, so the showcase is only
|
||||
reachable by its links.
|
||||
═══════════════════════════════════════════════════════════════ */
|
||||
|
||||
import { openDatabase, migrate, tx } from "./db.js";
|
||||
|
||||
const DB_PATH = process.env.DB_PATH ?? "./ngu.db";
|
||||
const LISTED = process.argv.includes("--listed") ? 1 : 0;
|
||||
const PRODUCTION = process.argv.includes("--production");
|
||||
|
||||
// Matched anywhere in the path, not only at its start, so a shell
|
||||
// that rewrites /var/lib/... into its own form (Git Bash) is caught too.
|
||||
if (/(^|\/)var\/lib\/ngu(\/|$)/.test(DB_PATH.replace(/\\/g, "/"))) {
|
||||
console.error("✗ This is test content. It won't write to the production database.");
|
||||
const deployed = /(^|\/)var\/lib\/ngu(\/|$)/.test(DB_PATH.replace(/\\/g, "/"));
|
||||
|
||||
if (deployed && !PRODUCTION) {
|
||||
console.error(
|
||||
`✗ ${DB_PATH} is a deployed database. This writes test content;\n` +
|
||||
" add --production if that's what you mean.",
|
||||
);
|
||||
process.exit(1);
|
||||
}
|
||||
if (deployed) console.warn(`! Writing showcase records to the deployed database ${DB_PATH}.`);
|
||||
|
||||
const IMAGE = "/uploads/showcase.jpg";
|
||||
const POST_ID = "content-block-showcase";
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue