mirror of
https://github.com/Unleash/unleash.git
synced 2025-06-27 01:19:00 +02:00
feat: do not lock until migrations are needed (#10170)
This commit is contained in:
parent
ef3ffc4d94
commit
967df825cb
@ -1,7 +1,7 @@
|
||||
import stoppable, { type StoppableServer } from 'stoppable';
|
||||
import { promisify } from 'util';
|
||||
import version from './util/version.js';
|
||||
import { migrateDb, resetDb } from '../migrator.js';
|
||||
import { migrateDb, requiresMigration, resetDb } from '../migrator.js';
|
||||
import getApp from './app.js';
|
||||
import type MetricsMonitor from './metrics.js';
|
||||
import { createMetricsMonitor } from './metrics.js';
|
||||
@ -336,6 +336,7 @@ async function start(
|
||||
if (config.db.disableMigration) {
|
||||
logger.info('DB migration: disabled');
|
||||
} else {
|
||||
if (await requiresMigration(config)) {
|
||||
logger.info('DB migration: start');
|
||||
if (config.flagResolver.isEnabled('migrationLock')) {
|
||||
logger.info('Running migration with lock');
|
||||
@ -351,6 +352,9 @@ async function start(
|
||||
}
|
||||
|
||||
logger.info('DB migration: end');
|
||||
} else {
|
||||
logger.info('DB migration: no migration needed');
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
logger.error('Failed to migrate db', err);
|
||||
|
@ -40,6 +40,28 @@ export async function migrateDb(
|
||||
});
|
||||
}
|
||||
|
||||
export async function requiresMigration({
|
||||
db,
|
||||
}: Pick<IUnleashConfig, 'db'>): Promise<boolean> {
|
||||
return noDatabaseUrl(async () => {
|
||||
const custom = {
|
||||
...db,
|
||||
connectionTimeoutMillis: secondsToMilliseconds(10),
|
||||
};
|
||||
|
||||
// disable Intellij/WebStorm from setting verbose CLI argument to db-migrator
|
||||
process.argv = process.argv.filter((it) => !it.includes('--verbose'));
|
||||
const dbm = getInstance(true, {
|
||||
cwd: __dirname,
|
||||
config: { custom },
|
||||
env: 'custom',
|
||||
});
|
||||
|
||||
const pendingMigrations = await dbm.check();
|
||||
return pendingMigrations.length > 0;
|
||||
});
|
||||
}
|
||||
|
||||
// This exists to ease testing
|
||||
export async function resetDb({ db }: IUnleashConfig): Promise<void> {
|
||||
return noDatabaseUrl(async () => {
|
||||
|
Loading…
Reference in New Issue
Block a user