mirror of
https://github.com/orangecoding/fredy.git
synced 2026-06-16 12:31:07 +00:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
28e885f6c7 | ||
|
|
1d99fc95f7 |
@@ -1,29 +1,14 @@
|
|||||||
import { setInterval } from 'node:timers';
|
|
||||||
import { removeJobsByUserId } from './storage/jobStorage.js';
|
import { removeJobsByUserId } from './storage/jobStorage.js';
|
||||||
import { config } from '../utils.js';
|
import { config } from '../utils.js';
|
||||||
import { getUsers } from './storage/userStorage.js';
|
import { getUsers } from './storage/userStorage.js';
|
||||||
import logger from './logger.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)
|
* if we are running in demo environment, we have to cleanup the db files (specifically the jobs table)
|
||||||
*/
|
*/
|
||||||
export function cleanupDemoAtMidnight() {
|
export function cleanupDemoAtMidnight() {
|
||||||
const now = new Date();
|
cron.schedule('0 0 * * *', cleanup);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function cleanup() {
|
function cleanup() {
|
||||||
|
|||||||
@@ -127,24 +127,12 @@ export async function runMigrations() {
|
|||||||
if (executed.has(m.name)) {
|
if (executed.has(m.name)) {
|
||||||
const prev = executed.get(m.name);
|
const prev = executed.get(m.name);
|
||||||
if (prev !== checksum) {
|
if (prev !== checksum) {
|
||||||
const allow = (process.env.MIGRATION_ALLOW_CHECKSUM_UPDATE || '').toLowerCase();
|
logger.info(`Mismatch found in migration ${m.name}. Fixing.`);
|
||||||
const allowUpdate = allow === '1' || allow === 'true' || allow === 'yes';
|
SqliteConnection.execute('UPDATE schema_migrations SET checksum = @checksum WHERE name = @name', {
|
||||||
if (allowUpdate) {
|
checksum,
|
||||||
logger.warn(
|
name: m.name,
|
||||||
`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.`,
|
executed.set(m.name, checksum);
|
||||||
);
|
|
||||||
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.`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "fredy",
|
"name": "fredy",
|
||||||
"version": "12.0.1",
|
"version": "12.0.2",
|
||||||
"description": "[F]ind [R]eal [E]states [d]amn eas[y].",
|
"description": "[F]ind [R]eal [E]states [d]amn eas[y].",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"prepare": "husky",
|
"prepare": "husky",
|
||||||
|
|||||||
Reference in New Issue
Block a user