Nextcloud does not start anymore

Hello, my nextcloud is not working anymore. Error message:

Sep 10 22:32:32 server nextcloud-setup-start[532958]: Next Doctrine\DBAL\Exception\TableNotFoundException: An exception occurred while executing a query: SQLSTATE[42P01]: Undefined table: 7 ERROR:  relation "oc_appconfig" does not exist
Sep 10 22:32:32 server nextcloud-setup-start[532958]: LINE 1: SELECT * FROM "oc_appconfig"
Sep 10 22:32:32 server nextcloud-setup-start[532958]:                       ^ in /nix/store/9qnln1n8d9xgxqlhy0nbkd2v6l0x2hbm-nextcloud-2

I suspect it has something to do with the code I recently added to my config, because before it did not happen. Here the relevant snippet out of my config:

services.postgresql = {
    enable = true;
    package = pkgs.postgresql_15;
    ensureDatabases = [ "discordbot" ];
    authentication = pkgs.lib.mkOverride 10 ''
      #type database DBuser auth-method
      local all      all    trust
    '';
  };

nextcloud = {
      enable = true;
      package = pkgs.nextcloud27;
      hostName = "cloud.shaniag.com";
      database.createLocally = true;
      https = true;
      configureRedis = true;
      config = {
        dbtype = "pgsql";
        adminpassFile = "/var/run/nextcloud-pass.txt";
        defaultPhoneRegion = "DE";
      };
      extraOptions = {
        mail_smtpmode = "sendmail";
        mail_sendmailmode = "pipe";
        twofactor_enforced = false;
      };
      autoUpdateApps.enable = true;
    };
  };

Perhaps I am missing it in your post, but which part of the code was recently added?

mostly facing this issue: postgresql_15 requires granting permissions on schema public, ensureUsers insufficient · Issue #216989 · NixOS/nixpkgs · GitHub

I understand that there is a desire for additional config options to be added to the NixOS service to support this. In the meantime to get Nexcloud started again, is it possible to manually grant the permission? Since the database it stateful, it shouldn’t cause problems with future rebuilds and it could always be documented in comments in the .nix configuration.

Or is this more complicated than I am understanding?

BTW: I am also interested in this topic because I run Nextcloud on a NixOS server. I currently run it using an oci-container from Docker Hub along with an oci-container for mariadb; but I was thinking I may move to the services.nextcloud option.

@genson i tried to ensure user permissions but all of that does not really work. I land on a page where it asks me if i want to use sqlite or postgres even though i specified that