ovotech / pg-sql-migrate

A very small library for running sql migrations with postgres.
Other
2 stars 1 forks source link

Filenames aren't fully parsed #1

Closed nickreese closed 4 years ago

nickreese commented 4 years ago

Thanks for your great work. Small detail, really not important but figured it was worth logging somewhere.

I've got a single migration: 2020-03-06T22:16:39.659Z_update_date.pgsql

const { migrate } = require('@ovotech/pg-sql-migrate');

async function main() {
  const results = await migrate();

  console.log(results);
}

main();

console.log returns => [ { id: '2020-03-06T22:16:39.659Z', name: 'update', content: '' } ]

I've done this a few times and it never fully parses. Minimal, but worth noting.

nickreese commented 4 years ago

I need to fork this to handle some of my own issues.

That said, this issue is easily fixed in changing MigrationsReadable.ts:

From:

export const nameParts = (name: string): string[] => name.split('_', 2);

To:

export const nameParts = (name: string): string[] => {
  const [first, ...rest] = name.split('_');
  return [first, rest.join("_")]
}
ivank commented 4 years ago

Yeah noticed that one recently too. If you make a PR would love to merge it! Put credit where credit is due :)

nickreese commented 4 years ago

@ivank Unfortunately I forked the project to rename the files created to .sql instead of .pgsql and am not sure how to do a pull request just with a single file or refork it. No problem if you merge it without any credit.