-
-
Notifications
You must be signed in to change notification settings - Fork 158
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
Conversation
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. |
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>
Thanks for your input! I just pushed the updated files. @kf6kjg do you mean something like this? |
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. |
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 |
@kf6kjg okay, it's ready 😊 |
There was a problem hiding this 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!
Okay, I added it including the example of the file extension removal. |
Co-Authored-By: Pedro Augusto de Paula Barbosa <papb1996@gmail.com>
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.