3 ms·
To be honest this looks like half-baked. Couple of points: - migration queries for up and down should be persisted. Here migrations are always read from files.
by kklisura 5y ago
To be honest this looks like half-baked. Couple of points:
- migration queries for up and down should be persisted. Here migrations are always read from files. If one changes down migration it might not match the up migration.
- migration content should be tracked (crc, hashing, whatever) to prevent any changes to migrations once applied
- my opinion is that each migration should have strict order and not be relied upon file sorts to prevent adding migrations in the middle of existing ones. This is accomplished by enforcing each id/migration number in files to be incremental
- 1-to-1 mapping should be enforced and errors should be produced if there are migrations in database, but not present in files
- one nit pick: two tables for migrations seems overkill
This is mostly coming from Java background and having the above things was really life saver in some situations. I think the Playframwork's way of managing migrations was really good. Flyway is good too for SpringBoot (not sure if exists something besides it), but lacks down migrations.
- SahAssar 5y agoThe first four of your points seem to be the sort of things that could be handled based on being strict in your source control. If you enforce naming rules for the files, don't allow for changing the history of the repo and only run migrations in production from source-controlled files then those are not really problems, right? I'm guessing you could even have automatic checking of those rules in CI.
- tobyhinloopen 5y agoGood suggestions. I didn’t really care about crc checks, my idea is to not modify the files after you’ve submitted them. The program uses natural sorting, not dependent on filesystem. It is half-baked because my colleague posted it here while I was working on it for the lulz.