Files
tidefront/packages/engine/scripts/relocate-bases.ts
T

36 lines
1.6 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// Karte 2: Häfen, Nester und Rohstofffelder einer bestehenden Welt auf die genaueren Küstenlinien bringen.
// Standard ist ein TROCKENLAUF (liest nur, schreibt den Bericht). Erst mit --apply wird in einer Transaktion versetzt
// und die Hafenmeisterei benachrichtigt die betroffenen Spieler.
//
// DATABASE_URL=postgres://… node packages/engine/scripts/relocate-bases.ts [--apply] [--report pfad.md]
//
// NICHT unbedacht gegen die Live-Datenbank: vorher Sicherung, zuerst Trockenlauf, Bericht prüfen. Läuft idempotent
// (ein zweiter Lauf findet nichts mehr). Logik: packages/engine/src/relocate.ts.
import { writeFileSync } from "node:fs";
import { createDb } from "@tidefront/db";
import { applyRelocation, planRelocation, relocationReport } from "../src/relocate.ts";
const args = process.argv.slice(2);
const apply = args.includes("--apply");
const ri = args.indexOf("--report");
const reportPath = ri >= 0 ? args[ri + 1] : `relocate-report-${new Date().toISOString().replace(/[:.]/g, "-")}.md`;
const url = process.env.DATABASE_URL;
if (!url) {
console.error("DATABASE_URL fehlt.");
process.exit(2);
}
const { db, client } = createDb(url, 1);
try {
const report = await db.transaction(async (tx) => {
const plan = await planRelocation(tx);
if (apply) await applyRelocation(tx, plan, Date.now());
return relocationReport(plan, apply);
});
writeFileSync(reportPath, report + "\n");
console.log(report);
console.log(`\nBericht: ${reportPath}${apply ? "" : "\nTrockenlauf – nichts geändert. Ausführen mit --apply."}`);
} finally {
await client.end();
}