mirror of
https://github.com/Unleash/unleash.git
synced 2025-02-19 00:15:43 +01: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) {
|
||||
logger.info('DB migrations disabled');
|
||||
} else {
|
||||
await migrator(options);
|
||||
await migrator.up(options);
|
||||
}
|
||||
} catch (err) {
|
||||
logger.error('Failed to migrate db', err);
|
||||
|
@ -50,7 +50,7 @@ const serverImpl = proxyquire('./server-impl', {
|
||||
},
|
||||
},
|
||||
'../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');
|
||||
|
||||
function migrateDb({ db, databaseSchema = 'public' }) {
|
||||
function getDbInstance({ db, databaseSchema = 'public' }) {
|
||||
const custom = { ...db, schema: databaseSchema };
|
||||
const dbmigrate = getInstance(true, {
|
||||
return getInstance(true, {
|
||||
cwd: __dirname,
|
||||
config: { 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) {
|
||||
const options = {
|
||||
db: { ...dbConfig.getDb(), pool: { min: 2, max: 8 } },
|
||||
db: { ...dbConfig.getDb(), pool: { min: 2, max: 20 } },
|
||||
databaseSchema,
|
||||
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(`CREATE SCHEMA IF NOT EXISTS ${options.databaseSchema}`);
|
||||
await migrator(options);
|
||||
await migrator.up(options);
|
||||
await db.destroy();
|
||||
const stores = await createStores(options, eventBus);
|
||||
stores.clientMetricsStore.setMaxListeners(0);
|
||||
@ -101,10 +101,18 @@ module.exports = async function init(databaseSchema = 'test', getLogger) {
|
||||
await resetDatabase(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 {
|
||||
stores,
|
||||
reset: async () => {
|
||||
await resetDatabase(stores);
|
||||
// await resetDatabase(stores);
|
||||
await reset();
|
||||
await setupDatabase(stores);
|
||||
},
|
||||
destroy: async () => {
|
||||
|
Loading…
Reference in New Issue
Block a user