Compare commits

..

2 Commits

Author SHA1 Message Date
orangecoding
28e885f6c7 fixing migration checksum 2025-09-18 18:42:19 +02:00
orangecoding
1d99fc95f7 using cron to run demo cleanup every day at midnight 2025-09-18 18:04:49 +02:00
3 changed files with 9 additions and 36 deletions

View File

@@ -1,29 +1,14 @@
import { setInterval } from 'node:timers';
import { removeJobsByUserId } from './storage/jobStorage.js';
import { config } from '../utils.js';
import { getUsers } from './storage/userStorage.js';
import logger from './logger.js';
import cron from 'node-cron';
/**
* if we are running in demo environment, we have to cleanup the db files (specifically the jobs table)
*/
export function cleanupDemoAtMidnight() {
const now = new Date();
const millisUntilMidnightUTC =
(24 - now.getUTCHours()) * 60 * 60 * 1000 -
now.getUTCMinutes() * 60 * 1000 -
now.getUTCSeconds() * 1000 -
now.getUTCMilliseconds();
cleanup();
setTimeout(() => {
setInterval(
() => {
cleanup();
},
24 * 60 * 60 * 1000,
);
}, millisUntilMidnightUTC);
cron.schedule('0 0 * * *', cleanup);
}
function cleanup() {

View File

@@ -127,24 +127,12 @@ export async function runMigrations() {
if (executed.has(m.name)) {
const prev = executed.get(m.name);
if (prev !== checksum) {
const allow = (process.env.MIGRATION_ALLOW_CHECKSUM_UPDATE || '').toLowerCase();
const allowUpdate = allow === '1' || allow === 'true' || allow === 'yes';
if (allowUpdate) {
logger.warn(
`Checksum mismatch for already executed migration ${m.name}, but MIGRATION_ALLOW_CHECKSUM_UPDATE is enabled. ` +
`Updating recorded checksum and continuing without re-running the migration.`,
);
SqliteConnection.execute('UPDATE schema_migrations SET checksum = @checksum WHERE name = @name', {
checksum,
name: m.name,
});
executed.set(m.name, checksum);
} else {
throw new Error(
`Checksum mismatch for already executed migration ${m.name}. ` +
`Do not modify applied migrations. Create a new migration instead.`,
);
}
logger.info(`Mismatch found in migration ${m.name}. Fixing.`);
SqliteConnection.execute('UPDATE schema_migrations SET checksum = @checksum WHERE name = @name', {
checksum,
name: m.name,
});
executed.set(m.name, checksum);
}
continue;
}

View File

@@ -1,6 +1,6 @@
{
"name": "fredy",
"version": "12.0.1",
"version": "12.0.2",
"description": "[F]ind [R]eal [E]states [d]amn eas[y].",
"scripts": {
"prepare": "husky",