Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

165
Views
Umzug and Sequelize recreate/clean database after test again

We are using Umzug library with Sequelize and we want to use it for testing, but our problem is that we are unable to make the db clean after running first test suite. Maybe we misunderstand some principles of it.

How do you prepare testing db before running multiple test suites, which needs to recreate completely clean database and load again fixtures? Any tips&tricks welcomed.

Code we have so far (but it don't clean database correctly)

 describe('Create user password mutation - SUCCESS', () => {
                afterAll(async (done) => {
                    const dbModelsService = testService.getService(services.MODELS);
                    const sequelizeService = testService.getService(services.SEQUELIZE);
                    const sequelizeSetupOpts = getSequelizeSetupOpts(dbModelsService);
                    const umzug = getUmzugOptions(dbModelsService, sequelizeService);
                    await resetDbMigrations(sequelizeService, umzug);
                    await setupDevDb(sequelizeService, sequelizeSetupOpts, umzug, dbModelsService, true);
                    done();
                });
export const getSequelizeSetupOpts = (dbModels) => {
    return {
        models: dbModels,
        migrationsPath: '/app/lib/sequelize/migrations',
        fixtures: dbFixtures, // this is array of fixtures
        init: false,
    };
};
export const resetDbMigrations = async (sequelizeService, umzug) => {
    try {
        await sequelizeService.query('SET FOREIGN_KEY_CHECKS = 0');
        await resetMigrations(umzug);
        // await dbHardReset();
    } catch (e) {
        log.e('There occured an error when migrations were dropped down to 0.', e);
    } finally {
        await sequelizeService.query('SET FOREIGN_KEY_CHECKS = 1');
    }
};
export const setupDevDb = async (sequelizeService, sequelizeSetupOpts, umzug, dbModels, init = false) => {
    // Set up test database and load fixtures
    return runMigrations(umzug)
        .then(() => {
            if (init) {
                // return destroyModels(sequelizeService, dbModels);
            }
            return null;
        })
        .then(() => {
            if (init) {
                return loadFixtures(sequelizeSetupOpts);
            }
            return null;
        })
        .catch((e) => {
            log.e('There occured an error while running migrations with destroying models and loading fixtures.', e);
            throw e;
        });
};
function runMigrations(umzug) {
    // eslint-disable-next-line no-unused-vars
    return umzug
        .up()
        .then((migrations) => {
            console.info(`Running ${migrations.length} migrations...`);
        })
        .catch((err) => {
            log.e('Error while running migrations: ', err);
        });
}
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!