Supporting up/down migrations in a single file
Would you open to a PR that adds support for up/down migrations in a single file, similar to the library careen? A combined migration file would have the following form:
CREATE TABLE people (first_name TEXT NOT NULL, last_name TEXT NOT NULL);
---
DROP TABLE people;
Thanks for reading!
I totally get why it might be a good idea to see the up and down in one file, but I'm reluctant to do this because it means the following:
- Supporting 2 kinds of file formats
- The format you propose is more difficult to work with in terms of you can't just combine the files and run them all at once etc. You'd have to split the files etc which adds complexity.
What do you think?
Added code complexity is certainly worth considering. For me, a combination of how much more I prefer the single-file format and my prediction that it wouldn’t require that much amount of code to write a “file adapter” leads me to not be too worried about this specific detail.
What I would be more worried about is the added cognitive complexity to the end user who needs to think about what format they want. It is more documentation and more configuration for them to be concerned with.
My perception is certainly skewed though, because of how much more strongly I prefer one file for migrations. The benefits that I see with the one file approach are:
- easier scannability in the file tree to see which migrations have been created
- create and tear down in a single file makes it more straightforward to verify that your migrations don’t have errors, because you can see them together in the one file
The two-file system strikes me as more tedious from a developer experience perspective.
Although I think one file is a better system, it’s totally cool if you aren’t interested in adding it to this lib. I can make due with two files.
Either way, I appreciate you taking the time to read through this issue and giving it such thoughtful consideration, @massimocode !
Based on my experience using Laravel I like the one file system. In case you're not familiar with it, in Laravel the up and down migrations are each enclosed in their own functions, for which migrate calls up() and rollback calls down(). It might be a little added code complexity compared to what you've got now, sure, but the tradeoff might be a better developer experience which might be worth it.
Either way, thanks for your work on this project. This is a very important tool to have available.
If we could make part of the software which reads the files as a module (i.e. class, function, whatever) which follows single responsibility principle then of course we could add support for other migration formats in the form of other implementations of the module's interface and swap them via config. I'd be happy to see such a PR if it helps support your use cases.