Upgrade MM 5.3.1 to latest version fails

It would come from the configuration of the Database formatting, schema, etc that, if incorrect, would hinder the proper operations of Mattermost even while it is running. I have been referring to this Mattermost Github issue, which seems to be exactly what you are experiencing. If you read it from top-down, you will see me asking about the schema of the table is related to the first posted possible solution in the Github thread. At this point in time, I am now asking about this possible solution, which from what I can see, is what your configuration is set to be:

cedarice commented on Feb 28, 2019
I found a solution:
For mariadb, update your *my.cnf file with following configuration,

innodb_default_row_format=dynamic
innodb_file_format=barracuda
innodb_file_per_table=true
innodb_large_prefix=true

Then, you have to restart mariadb service for updated configuration to take effect.

reference: https://stackoverflow.com/a/52778785

If you take a look at that, could you let me know what you find, from the various schemas that you may want to check, as well as from your configuration files?