CI / Docker image (push) Successful in 12s
CI / Server (push) Successful in 25s
CI / CLI (push) Successful in 13s
Development image / Development image (push) Successful in 21s
CI / CLI (windows) (push) Successful in 57s
CI / CLI (linux-arm64, static) (push) Successful in 1m37s
Release / Prepare release (push) Successful in 2s
Release / Server (linux-x64) (push) Successful in 53s
Release / CLI (linux-arm64, static) (push) Successful in 1m32s
Release / Docker image (push) Successful in 2m48s
Release / Server (windows-x64) (push) Successful in 6m20s
Release / CLI (windows-x64) (push) Successful in 6m48s
Release / CLI (linux-x64) (push) Successful in 7m8s
Release / Publish release (push) Successful in 1s
Squash the tree into one commit, drop docs/architecture.html, reset the version line to 0.3.0, consolidate the changelog, enable Renovate automerge for non-major updates and add AGENTS.md.
43 lines
1.4 KiB
JavaScript
43 lines
1.4 KiB
JavaScript
const fs = require("node:fs");
|
|
const path = require("node:path");
|
|
const { Sequelize } = require("sequelize");
|
|
const { dataDir } = require("./paths");
|
|
const logger = require("./logger");
|
|
|
|
const storage = adoptLegacyDatabase(path.join(dataDir(), "frislit.db"));
|
|
|
|
/*
|
|
* A data directory that was served by tunlit still holds tunlit.db. Rename it
|
|
* instead of starting from an empty database; if the rename fails (read-only
|
|
* mount, different filesystem), use the old file in place.
|
|
*/
|
|
function adoptLegacyDatabase(target) {
|
|
const legacy = path.join(path.dirname(target), "tunlit.db");
|
|
if (fs.existsSync(target) || !fs.existsSync(legacy)) return target;
|
|
|
|
try {
|
|
fs.renameSync(legacy, target);
|
|
for (const suffix of ["-wal", "-shm"]) {
|
|
if (fs.existsSync(legacy + suffix)) fs.renameSync(legacy + suffix, target + suffix);
|
|
}
|
|
logger.info(`Adopted the tunlit database as ${path.basename(target)}`);
|
|
return target;
|
|
} catch (error) {
|
|
logger.warn(`Could not rename tunlit.db (${error.message}), using it in place`);
|
|
return legacy;
|
|
}
|
|
}
|
|
|
|
Sequelize.DATE.prototype._stringify = function (date) {
|
|
return (date instanceof Date ? date : new Date(date)).toISOString();
|
|
};
|
|
|
|
module.exports = new Sequelize({
|
|
dialect: "sqlite",
|
|
storage,
|
|
logging: message => logger.debug(message),
|
|
query: { raw: true },
|
|
});
|
|
|
|
module.exports.storagePath = storage;
|