{ pkgs, ... }:
{
  services = {
    postgresql = {
      enable = true;

      # version is tied to stateVersion
      # manual update required
      # MIGRATION REQUIRED WHEN UPDATING
      package = pkgs.postgresql_15;

      ensureDatabases = [
        "dendrite"
        "matrix-sliding-sync"
      ];

      ensureUsers = [
        {
          name = "dendrite";
          ensureDBOwnership = true;
        }
        {
          name = "matrix-sliding-sync";
          ensureDBOwnership = true;
        }
      ];
    };

    postgresqlBackup = {
      enable = true;
      backupAll = true;

      # borg will do compression and deduplication
      compression = "none";

      startAt = "*-*-* 02:00:00";
    };
  };
}