db-migrate / node-db-migrate

Database migration framework for node
Other
2.32k stars 360 forks source link

dbmigrate.create() is setting title arg to my test directory #770

Closed dschinkel closed 2 years ago

dschinkel commented 2 years ago

I am trying to run a migration to initially create a .sql file from my test like so:

it.only('returns a featured company', async () => {
  await createSQLAndMigrationFile('create-table-featured-company.sql', 'test');

  expect(company.featured.active).to.equal(newCompany.featured.active);
  expect(company.featured.order).to.equal(newCompany.featured.order);
});

createSQLAndMigrationFile exists inside my Migrate.ts which sets up db-migrate as such:

const dbmigrate = DBMigrate.getInstance(true, {
    config: path.join(__dirname, './database.json'),
    env: 'dev',
    cmdOptions: {
        'migrations-dir': path.join(__dirname, '/migrations'),
    },
});

the problem is it fails because it's adding the test directory relative path to the end of the migration create directory.

I looked in the db-migrate code and this is where it's setting title in createMigrationDir: internals.argv.title = folder[folder.length - 2] || folder[0];

So I end up with this error because the title arg is appending my test folder's path to the end /integration/**/:

no such file or directory, open '/Users/daveschinkel/code/projects/myProjeect/src/LocalDB/migrations/test/integration/**/20220223063816-**.js'

the right path is /Users/daveschinkel/code/projects/myProjeect/src/LocalDB/migrations/test