I didn’t find this topic yesterday when i upgraded nextcloud but i read the same post and i’ve adapted the script to be compatible with yunohost :
#!/bin/bash
password=$(grep db_pwd /etc/yunohost/apps/nextcloud/settings.yml | awk '{print $2}')
mysql -u nextcloud -p"$password" nextcloud -Bse "
SELECT CONCAT('ALTER TABLE \`', TABLE_NAME, '\` ROW_FORMAT=DYNAMIC;')
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA = 'nextcloud'
AND ENGINE = 'InnoDB'
" | mysql -u nextcloud -p"$password" nextcloud
I use root user to execute it to be able to read /etc/yunohost/apps/nextcloud/settings.yml and i put nextcloud in maintenance mode like you.