Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add format function #196

Merged
merged 13 commits into from
Mar 29, 2020
Merged

feat: add format function #196

merged 13 commits into from
Mar 29, 2020

Conversation

jaulz
Copy link
Contributor

@jaulz jaulz commented Jan 27, 2020

Sometimes you want to modify the name of the migration (e.g. in my case I would like to remove the file suffix because it changes depending on whether I run the Typescript or compiled version). This PR introduces a format function in the options that takes care of it.

@kf6kjg
Copy link

kf6kjg commented Feb 26, 2020

Watch your whitespace, that's what's causing the CI to fail. Otherwise this looks good to me and would allow me to solve the same problem.

However I'd go one step further and provide a way to format the name that is in storage too. That way I can take an existing database that was migrated without a formatter and still not have a migration collision. You could use the same format function, it would just force the user to add additional logic. Or you can have different functions for each side: one for formatting files from disk, another for formatting migration names from storage.

src/migration.js Outdated Show resolved Hide resolved
src/migration.js Outdated Show resolved Hide resolved
src/migration.js Outdated Show resolved Hide resolved
src/index.js Outdated Show resolved Hide resolved
@papb
Copy link
Member

papb commented Mar 16, 2020

Hi @jaulz, thanks for the PR! Please address my comments and also address the suggestion by @kf6kjg. Thanks!

jaulz and others added 5 commits March 16, 2020 19:21
Co-Authored-By: Pedro Augusto de Paula Barbosa <papb1996@gmail.com>
Co-Authored-By: Pedro Augusto de Paula Barbosa <papb1996@gmail.com>
Co-Authored-By: Pedro Augusto de Paula Barbosa <papb1996@gmail.com>
@jaulz
Copy link
Contributor Author

jaulz commented Mar 16, 2020

Thanks for your input! I just pushed the updated files.

@kf6kjg do you mean something like this?
https://github.com/sequelize/umzug/pull/196/files#diff-410142b027abfe35d3351577b731ebcaR106-R107

@kf6kjg
Copy link

kf6kjg commented Mar 16, 2020

Yeah, that looks like it should work. I like it. It'd be good to give an example of how to use the option in the documentation such as

{
  nameFormatter: path => {
    const filename = Path.basename(path); // Isolate the file name from the full path.
    return filename.slice(0, filename.lastIndexOf(".")); // Remove the file extension, leaving just the unique name of the migration.
  }
}

At least that's what I'd use as I have migrations being run under Node on the live server at the moment and I'd like to eventually change over to using Node-TS, thus dropping the whole extra compile-to-JS step. This would prevent the extension change, .js to .ts, from causing any headaches.

@kf6kjg
Copy link

kf6kjg commented Mar 16, 2020

Though, reviewing the code a little, I think it'd be good for you to write up some unit tests to exercise this. Also to make sure to fix whatever's causing the existing unit tests to fail - but I suspect you are already on top of that! :D

@jaulz
Copy link
Contributor Author

jaulz commented Mar 17, 2020

@kf6kjg okay, it's ready 😊

test/fixtures/index.js Outdated Show resolved Hide resolved
Copy link
Member

@papb papb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Just one more thing, please take a look at our current readme and see if this feature should be mentioned somewhere. For example, I think it should be mentioned in this section - please take a look if it should be also mentioned somewhere else. Thanks!

README.md Show resolved Hide resolved
@jaulz
Copy link
Contributor Author

jaulz commented Mar 18, 2020

Okay, I added it including the example of the file extension removal.

README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
src/migration.js Show resolved Hide resolved
Co-Authored-By: Pedro Augusto de Paula Barbosa <papb1996@gmail.com>
@papb papb merged commit 80e4afb into sequelize:master Mar 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants