Enabling apps from the API that haven't been "initialized"

Nextcloud version (eg, 18.0.2): 19.0.2
Operating system and version (eg, Ubuntu 20.04): Alpine 3.12
Apache or nginx version (eg, Apache 2.4.25): nginx 1.19.1
PHP version (eg, 7.1): 7.3

The issue you are facing:

Enabling an app via the API following these instructions:

for (at least) 2 apps: groupfolders (7.0.0) and user_saml (3.2.0)
doesn’t work the same as running php occ app:enable $app or clicking the enable button in the UI

we’re trying to automate the installation of apps in nextcloud using docker for use in kubernetes, but would like to install the apps into the container at compile time, and then enable it after it has been deployed via the API

the problem is, when using the API to enable instead of occ command or UI, the databases do not initialize, so nextcloud immediately crashes

NOTICE: PHP message: [owncloud][index][3] {"Exception":"Doctrine\\DBAL\\Exception\\TableNotFoundException","Message":"An exception occurred while executing 'SELECT \"f\".\"folder_id\", \"mount_point\", \"quota\", \"acl\", \"fileid\", \"storage\", \"path\", \"name\", \"mimetype\", \"mimepart\", \"size\", \"mtime\", \"storage_mtime\", \"etag\", \"encrypted\", \"parent\", \"a\".\"permissions\" AS \"group_permissions\", \"c\".\"permissions\" AS \"permissions\" FROM \"group_folders\" \"f\" INNER JOIN \"group_folders_groups\" \"a\" ON \"f\".\"folder_id\" = \"a\".\"folder_id\" LEFT JOIN \"filecache\" \"c\" ON (\"name\" = (\"f\".\"folder_id\" || '')) AND (\"parent\" = ?) WHERE \"a\".\"group_id\" = ?' with params [158, \"admin\"]:\n\nSQLSTATE[42P01]: Undefined table: 7 ERROR:  relation \"group_folders\" does not exist\nLINE 1: ...issions\", \"c\".\"permissions\" AS \"permissions\" FROM \"group_fol...\n                                                             ^","Code":0,"Trace":[{"file":"/var/www/html/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/DBALException.php","line":169,"function":"convertException","class":"Doctrine\\DBAL\\Driver\\AbstractPostgreSQLDriver","type":"->","args":["An exception occurred while executing 'SELECT \"f\".\"folder_id\", \"mount_point\", \"quota\", \"acl\", \"fileid\", \"storage\", \"path\", \"name\", \"mimetype\", \"mimepart\", \"size\", \"mtime\", \"storage_mtime\", \"etag\", \"encrypted\", \"parent\", \"a\".\"permissions\" AS \"group_permissions\", \"c\".\"permissions\" AS \"permissions\" FROM \"group_folders\" \"f\" INNER JOIN \"group_folders_groups\" \"a\" ON \"f\".\"folder_id\" = \"a\".\"folder_id\" LEFT JOIN \"filecache\" \"c\" ON (\"name\" = (\"f\".\"folder_id\" || '')) AND (\"parent\" = ?) WHERE \"a\".\"group_id\" = ?' with params [158, \"admin\"]:\n\nSQLSTATE[42P01]: Undefined table: 7 ERROR:  relation \"group_folders\" does not exist\nLINE 1: ...issions\", \"c\".\"permissions\" AS \"permissions\" FROM \"group_fol...\n                                                             ^",{"errorInfo":["42P01",7,"ERROR:  relation \"group_folders\" does not exist\nLINE 1: ...issions\", \"c\".\"permissions\" AS \"permissions\" FROM \"group_fol...\n                                                             ^"],"__class__":"Doctrine\\DBAL\\Driver\\PDOException"}]},{"file":"/var/www/html/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/DBALException.php","line":145,"function":"wrapException","class":"Doctrine\\DBAL\\DBALException","type":"::","args":[{"__class__":"Doctrine\\DBAL\\Driver\\PDOPgSql\\Driver"},{"errorInfo":["42P01",7,"ERROR:  relation \"group_folders\" does not exist\nLINE 1: ...issions\", \"c\".\"permissions\" AS \"permissions\" FROM \"group_fol...\n                                                             ^"],"__class__":"Doctrine\\DBAL\\Driver\\PDOException"},"An exception occurred while executing 'SELECT \"f\".\"folder_id\", \"mount_point\", \"quota\", \"acl\", \"fileid\", \"storage\", \"path\", \"name\", \"mimetype\", \"mimepart\", \"size\", \"mtime\", \"storage_mtime\", \"etag\", \"encrypted\", \"parent\", \"a\".\"permissions\" AS \"group_permissions\", \"c\".\"permissions\" AS \"permissions\" FROM \"group_folders\" \"f\" INNER JOIN \"group_folders_groups\" \"a\" ON \"f\".\"folder_id\" = \"a\".\"folder_id\" LEFT JOIN \"filecache\" \"c\" ON (\"name\" = (\"f\".\"folder_id\" || '')) AND (\"parent\" = ?) WHERE \"a\".\"group_id\" = ?' with params [158, \"admin\"]:\n\nSQLSTATE[42P01]: Undefined table: 7 ERROR:  relation \"group_folders\" does not exist\nLINE 1: ...issions\", \"c\".\"permissions\" AS \"permissions\" FROM \"group_fol...\n                                                             ^"]},{"file":"/var/www/html/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Connection.php","line":911,"function":"driverExceptionDuringQuery","class":"Doctrine\\DBAL\\DBALException","type":"::","args":[{"__class__":"Doctrine\\DBAL\\Driver\\PDOPgSql\\Driver"},{"errorInfo":["42P01",7,"ERROR:  relation \"group_folders\" does not exist\nLINE 1: ...issions\", \"c\".\"permissions\" AS \"permissions\" FROM \"group_fol...\n                                                             ^"],"__class__":"Doctrine\\DBAL\\Driver\\PDOException"},"SELECT \"f\".\"folder_id\", \"mount_point\", \"quota\", \"acl\", \"fileid\", \"storage\", \"path\", \"name\", \"mimetype\", \"mimepart\", \"size\", \"mtime\", \"storage_mtime\", \"etag\", \"encrypted\", \"parent\", \"a\".\"permissions\" AS \"group_permissions\", \"c\".\"permissions\" AS \"permissions\" FROM \"group_folders\" \"f\" INNER JOIN \"group_folders_groups\" \"a\" ON \"f\".\"folder_id\" = \"a\".\"folder_id\" LEFT JOIN \"filecache\" \"c\" ON (\"name\" = (\"f\".\"folder_id\" || '')) AND (\"parent\" = ?) WHERE \"a\".\"group_id\" = ?",{"1":158,"2":"*** sensitive parameter replaced ***"}]},{"file":"/var/www/html/lib/private/DB/Connection.php","line":194,"function":"executeQuery","class":"Doctrine\\DBAL\\Connection","type":"->","args":["SELECT \"f\".\"folder_id\", \"mount_point\", \"quota\", \"acl\", \"fileid\", \"storage\", \"path\", \"name\", \"mimetype\", \"mimepart\", \"size\", \"mtime\", \"storage_mtime\", \"etag\", \"encrypted\", \"parent\", \"a\".\"permissions\" AS \"group_permissions\", \"c\".\"permissions\" AS \"permissions\" FROM \"group_folders\" \"f\" INNER JOIN \"group_folders_groups\" \"a\" ON \"f\".\"folder_id\" = \"a\".\"folder_id\" LEFT JOIN \"filecache\" \"c\" ON (\"name\" = (\"f\".\"folder_id\" || '')) AND (\"parent\" = ?) WHERE \"a\".\"group_id\" = ?",[158,"*** sensitive parameter replaced ***"],[2,2],null]},{"file":"/var/www/html/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Query/QueryBuilder.php","line":200,"function":"executeQuery","class":"OC\\DB\\Connection","type":"->","args":["SELECT \"f\".\"folder_id\", \"mount_point\", \"quota\", \"acl\", \"fileid\", \"storage\", \"path\", \"name\", \"mimetype\", \"mimepart\", \"size\", \"mtime\", \"storage_mtime\", \"etag\", \"encrypted\", \"parent\", \"a\".\"permissions\" AS \"group_permissions\", \"c\".\"permissions\" AS \"permissions\" FROM \"group_folders\" \"f\" INNER JOIN \"group_folders_groups\" \"a\" ON \"f\".\"folder_id\" = \"a\".\"folder_id\" LEFT JOIN \"filecache\" \"c\" ON (\"name\" = (\"f\".\"folder_id\" || '')) AND (\"parent\" = :dcValue2) WHERE \"a\".\"group_id\" = :dcValue1",{"dcValue1":"*** sensitive parameter replaced ***","dcValue2":158},{"dcValue1":2,"dcValue2":2}]},{"file":"/var/www/html/lib/private/DB/QueryBuilder/QueryBuilder.php","line":216,"function":"execute","class":"Doctrine\\DBAL\\Query\\QueryBuilder","type":"->","args":[]},{"file":"/var/www/html/custom_apps/groupfolders/lib/Folder/FolderManager.php","line":320,"function":"execute","class":"OC\\DB\\QueryBuilder\\QueryBuilder","type":"->","args":[]},{"file":"/var/www/html/custom_apps/groupfolders/lib/Folder/FolderManager.php","line":462,"function":"getFoldersForGroup","class":"OCA\\GroupFolders\\Folder\\FolderManager","type":"->","args":["*** sensitive parameter replaced ***",2]},{"function":"OCA\\GroupFolders\\Folder\\{closure}","class":"OCA\\GroupFolders\\Folder\\FolderManager","type":"->","args":["*** sensitive parameters replaced ***"]},{"file":"/var/www/html/custom_apps/groupfolders/lib/Folder/FolderManager.php","line":463,"function":"array_reduce","args":[["*** sensitive parameter replaced ***"],{"__class__":"Closure"},"*** sensitive parameter replaced ***"]},{"file":"/var/www/html/custom_apps/groupfolders/lib/Mount/MountProvider.php","line":80,"function":"getFoldersForUser","class":"OCA\\GroupFolders\\Folder\\FolderManager","type":"->","args":[{"__class__":"OC\\User\\User"},2]},{"file":"/var/www/html/custom_apps/groupfolders/lib/Mount/MountProvider.php","line":84,"function":"getFoldersForUser","class":"OCA\\GroupFolders\\Mount\\MountProvider","type":"->","args":[{"__class__":"OC\\User\\User"}]},{"file":"/var/www/html/lib/private/Files/Config/MountProviderCollection.php","line":105,"function":"getMountsForUser","class":"OCA\\GroupFolders\\Mount\\MountProvider","type":"->","args":[{"__class__":"OC\\User\\User"},{"__class__":"OC\\Files\\Storage\\StorageFactory"}]},{"file":"/var/www/html/lib/private/Files/Filesystem.php","line":451,"function":"addMountFor...

Is this the first time you’ve seen this error? (Y/N): N

Steps to replicate it:

  1. have running, initialized nextcloud instance
  2. install app like groupfolders by unpacking archive into the proper directory
  3. enable via the api instead of UI or occ command
  4. you will get database errors and a 500 if you try to load nextcloud
  5. disable again via the api, and enable via the UI or occ command
  6. databases initialize and everything will work fine
  7. then the api call to disable/enable works fine