After several days of ripping my hair out I finally found a solution detailed here:
https://forums.plex.tv/t/upgrade-to-1-40-0-7998-causes-error/869556/38
and here:
After running the command below the server was able to migrate its database successfully.
