HomePhabricator
Diffusion Comm 8f70b079dcfe

[server] [1/n] Adding `migrations.js`

Description

[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:

  1. migrations are valid, exits gracefully
  2. db_version >= migration index (in other words, the db_version is greater than the current migration key)
    1. continue;'s until a valid migration index is reached. Exits gracefully if such index exists, and also if it doesn't
  3. db_version >= all migration indices (db_version is higher than all referenced migrations)
    1. Exits gracefully
  4. db_version is not set in metadata table
    1. db_version is initialized to 0 in metadata table. Function continues to one of cases 1 to 3
  5. db_version is already set in metadata table
    1. db_version is not re-initialized to 0. Function continues to one of cases 1 to 3
  6. migration failure, does transaction rollback?
    1. yes
  7. migration success, does transaction commit?
    1. 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

Details

Provenance
anandAuthored on Jan 4 2022, 11:52 AM
Reviewer
atul
Differential Revision
Restricted Differential Revision
Parents
rCOMMf29f9d86895d: [CommCoreModule] Return `jsi::Value::undefined()` in `Get()` else case
Branches
Unknown
Tags
Unknown

Event Timeline