mirror of
https://github.com/Unleash/unleash.git
synced 2025-07-12 13:48:35 +02:00
wip: can we just reset db?
This commit is contained in:
parent
ad04eeb9b5
commit
6531ad0bbc
@ -116,7 +116,7 @@ async function start(opts) {
|
|||||||
if (options.disableDBMigration) {
|
if (options.disableDBMigration) {
|
||||||
logger.info('DB migrations disabled');
|
logger.info('DB migrations disabled');
|
||||||
} else {
|
} else {
|
||||||
await migrator(options);
|
await migrator.up(options);
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
logger.error('Failed to migrate db', err);
|
logger.error('Failed to migrate db', err);
|
||||||
|
@ -50,7 +50,7 @@ const serverImpl = proxyquire('./server-impl', {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
'../migrator': function() {
|
'../migrator': function() {
|
||||||
return Promise.resolve();
|
return { up: Promise.resolve() };
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -4,14 +4,24 @@ require('db-migrate-shared').log.setLogLevel('error');
|
|||||||
|
|
||||||
const { getInstance } = require('db-migrate');
|
const { getInstance } = require('db-migrate');
|
||||||
|
|
||||||
function migrateDb({ db, databaseSchema = 'public' }) {
|
function getDbInstance({ db, databaseSchema = 'public' }) {
|
||||||
const custom = { ...db, schema: databaseSchema };
|
const custom = { ...db, schema: databaseSchema };
|
||||||
const dbmigrate = getInstance(true, {
|
return getInstance(true, {
|
||||||
cwd: __dirname,
|
cwd: __dirname,
|
||||||
config: { custom },
|
config: { custom },
|
||||||
env: 'custom',
|
env: 'custom',
|
||||||
});
|
});
|
||||||
return dbmigrate.up();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = migrateDb;
|
async function up(options) {
|
||||||
|
return getDbInstance(options).up();
|
||||||
|
}
|
||||||
|
|
||||||
|
async function reset(options) {
|
||||||
|
return getDbInstance(options).reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
up,
|
||||||
|
reset,
|
||||||
|
};
|
||||||
|
@ -83,7 +83,7 @@ async function setupDatabase(stores) {
|
|||||||
|
|
||||||
module.exports = async function init(databaseSchema = 'test', getLogger) {
|
module.exports = async function init(databaseSchema = 'test', getLogger) {
|
||||||
const options = {
|
const options = {
|
||||||
db: { ...dbConfig.getDb(), pool: { min: 2, max: 8 } },
|
db: { ...dbConfig.getDb(), pool: { min: 2, max: 20 } },
|
||||||
databaseSchema,
|
databaseSchema,
|
||||||
getLogger,
|
getLogger,
|
||||||
};
|
};
|
||||||
@ -93,7 +93,7 @@ module.exports = async function init(databaseSchema = 'test', getLogger) {
|
|||||||
|
|
||||||
await db.raw(`DROP SCHEMA IF EXISTS ${options.databaseSchema} CASCADE`);
|
await db.raw(`DROP SCHEMA IF EXISTS ${options.databaseSchema} CASCADE`);
|
||||||
await db.raw(`CREATE SCHEMA IF NOT EXISTS ${options.databaseSchema}`);
|
await db.raw(`CREATE SCHEMA IF NOT EXISTS ${options.databaseSchema}`);
|
||||||
await migrator(options);
|
await migrator.up(options);
|
||||||
await db.destroy();
|
await db.destroy();
|
||||||
const stores = await createStores(options, eventBus);
|
const stores = await createStores(options, eventBus);
|
||||||
stores.clientMetricsStore.setMaxListeners(0);
|
stores.clientMetricsStore.setMaxListeners(0);
|
||||||
@ -101,10 +101,18 @@ module.exports = async function init(databaseSchema = 'test', getLogger) {
|
|||||||
await resetDatabase(stores);
|
await resetDatabase(stores);
|
||||||
await setupDatabase(stores);
|
await setupDatabase(stores);
|
||||||
|
|
||||||
|
const reset = async () => {
|
||||||
|
await db.raw(`DROP SCHEMA IF EXISTS ${options.databaseSchema} CASCADE`);
|
||||||
|
await db.raw(`CREATE SCHEMA IF NOT EXISTS ${options.databaseSchema}`);
|
||||||
|
await migrator.reset(options);
|
||||||
|
await migrator.up(options);
|
||||||
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
stores,
|
stores,
|
||||||
reset: async () => {
|
reset: async () => {
|
||||||
await resetDatabase(stores);
|
// await resetDatabase(stores);
|
||||||
|
await reset();
|
||||||
await setupDatabase(stores);
|
await setupDatabase(stores);
|
||||||
},
|
},
|
||||||
destroy: async () => {
|
destroy: async () => {
|
||||||
|
Loading…
Reference in New Issue
Block a user