Latest migration incorrectly created the conditional indexes, which
potentially allowed duplicates into the table. There was also a bug
before the latest migration that allowed dupes, which would make the
migration fail when reinserting the data into the new table. Easiest
solution here, since this data 1. still largely exists for programs in
the program table, and 2. is largely unused, is to completely drop the
table, recreate it correctly, and let the BackfillProgramExternalIds run
and fix everything up.
Some verification:
No external_key mismatches after migration
> sqlite> select eid.*, p.title from program_external_id eid join
program p on eid.program_uuid = p.uuid where p.external_key !=
eid.external_key and eid.source_type = 'plex';
There are only 3 programs that we were not able to find rating keys for
however, this means that the programs will be "broken" anyway and will
have to be readded in the UI, since their rating_keys are dangling in
Plex.
> sqlite> select count(p.uuid) from program p left join
program_external_id eid on p.uuid = eid.program_uuid where eid.uuid is
null;
count(p.uuid)
-------------
3
Fixes#537
Plex will blindly append query parameters on the end of channel URLs
(e.g. ?transcode=heavy), instead of first checking if the URL has a
query param. It seems that Express (DTV) handled this differently than
Fastify; the latter seems to take the _last_ query string from the URL,
resulting in a 404.
This also hooks up dotenv for the server, making it much easier to set
env variables for different run modes (e.g. using
TUNARR_BIND_ADDR=0.0.0.0 to have Plex auto discover the HDHR tuner when
running the dev server)