DevEx #811 Postgres migration to timestamptz
Issue number
Relevant issue number
- Resolves #811
- Resolves #825
Please check the following
- [x] Do the tests still pass? (see Run the Tests)
- [x] Is the code formatted properly? (see Linting (Formatting))
- For New Features:
- [ ] Have tests been added to cover any new features or fixes?
- [ ] Has the documentation been updated accordingly?
Please describe additional details for testing this change
This still needs a bunch of testing and a database migration, but I got a good start on the backend changes.
alter table "match"
add column "new_startTime" timestamptz,
add column "new_endTime" timestamptz;
update "match"
set "new_startTime" = to_timestamp("startTime"/1000.0),
"new_endTime" = to_timestamp("endTime"/1000.0);
alter table "match"
drop column "startTime",
drop column "endTime";
alter table "match"
rename column "new_startTime" to "startTime",
rename column "new_endTime" to "endTime";
The DB migration will probably look like this. Imo it makes sense to create the new columns and check a bunch of them before deleting and renaming.
apparently you can't use one ALTER for multiple renames
alter table "season"
add column "newStartTime" timestamptz,
add column "newEndTime" timestamptz;
update "season"
set "newStartTime" = to_timestamp("startTime"/1000.0),
"newEndTime" = to_timestamp("endTime" /1000.0);
alter table "season"
drop column "startTime",
drop column "endTime";
alter table "season"
rename column "newStartTime" to "startTime";
alter table "season"
rename column "newEndTime" to "endTime";
The SQL is the same for the season and match table, just with the table name changed respectively, the game will be almost the same thing just lockedAt
I tested this by staging the database on main locally and ran the first test in stats.spec.js to populate the database, I then ran the above migration on the match and season tables. Then switched branches to this PR, restarted the server with migrate: 'safe' in staging.js and was able to view all the stats from the stats fixture on the stats page.
This should probably be tested by at least one other person.