[server] [1/n] Adding migrations.js
Summary:
This is the automated MySQL migrations file, which is to be run when server is spun up by server.js.
migrate() is triggered in server.js before worker threads are forked (d2722). This diff only handles the migrate() function, not plugging it into server.js.
Test Plan:
I used test migrations, similar to the following from this "Inspired by In MySQL, use “utf8mb4” instead of “utf8” article".
I created {1} {2} simple migrations and added them to the migrations map, like so.
The migrations are run in conjunction with server.js changes in d2722.
Here are the tests I've run so far:
Tests run so far:
- migrations are valid, exits gracefully
- db_version >= migration index (in other words, the db_version is greater than the current migration key)
- continue;'s until a valid migration index is reached. Exits gracefully if such index exists, and also if it doesn't
- db_version >= all migration indices (db_version is higher than all referenced migrations)
- Exits gracefully
- db_version is not set in metadata table
- db_version is initialized to 0 in metadata table. Function continues to one of cases 1 to 3
- db_version is already set in metadata table
- db_version is not re-initialized to 0. Function continues to one of cases 1 to 3
- migration failure, does transaction rollback?
- yes
- migration success, does transaction commit?
- yes
Reviewers: atul, varun, ashoat
Reviewed By: atul, varun, ashoat
Subscribers: ashoat, palys-swm, Adrian, karol-bisztyga, benschac, boristopalov
Differential Revision: https://phabricator.ashoat.com/D2628