initialize generic rms-software repository
Add the reusable RMS core application (server, web UI, plugins, tests, tools) with generic defaults, GPL licensing, and maintainer context documentation so deployments can consume this repo as software source independent of station-specific overlays.
This commit is contained in:
53
tools/migrate-json-to-sqlite.js
Normal file
53
tools/migrate-json-to-sqlite.js
Normal file
@@ -0,0 +1,53 @@
|
||||
const path = require("path");
|
||||
const fs = require("fs");
|
||||
const fsp = require("fs/promises");
|
||||
|
||||
const { createJsonStorage } = require("../server/storage/providers/json");
|
||||
const { createSqliteStorage } = require("../server/storage/providers/sqlite");
|
||||
|
||||
async function main() {
|
||||
const rootDir = path.resolve(__dirname, "..");
|
||||
const dataDir = path.resolve(rootDir, process.env.DATA_DIR || "./data");
|
||||
const sqlitePath = path.resolve(rootDir, process.env.STORAGE_SQLITE_PATH || "./data/rms-storage.db");
|
||||
|
||||
await fsp.mkdir(dataDir, { recursive: true });
|
||||
|
||||
const json = createJsonStorage({ dataDir });
|
||||
await json.init();
|
||||
const sqlite = createSqliteStorage({ sqlitePath });
|
||||
await sqlite.init();
|
||||
|
||||
const files = [
|
||||
"users.json",
|
||||
"station-state.json",
|
||||
"auth-state.json",
|
||||
"plugin-state.json"
|
||||
].map((name) => path.join(dataDir, name));
|
||||
|
||||
for (const filePath of files) {
|
||||
if (!fs.existsSync(filePath)) {
|
||||
continue;
|
||||
}
|
||||
const value = await json.readJson(filePath, null);
|
||||
if (value !== null) {
|
||||
await sqlite.writeJson(filePath, value);
|
||||
console.log(`migrated json: ${filePath}`);
|
||||
}
|
||||
}
|
||||
|
||||
const auditPath = path.join(dataDir, "audit.log");
|
||||
if (fs.existsSync(auditPath)) {
|
||||
const content = await json.readText(auditPath, "");
|
||||
if (content) {
|
||||
await sqlite.writeText(auditPath, content);
|
||||
console.log(`migrated text: ${auditPath}`);
|
||||
}
|
||||
}
|
||||
|
||||
console.log(`done -> ${sqlitePath}`);
|
||||
}
|
||||
|
||||
main().catch((error) => {
|
||||
console.error("migration failed", error);
|
||||
process.exit(1);
|
||||
});
|
||||
Reference in New Issue
Block a user