---
- name: Flush handlers to ensure Gitea is up before DB patch
  meta: flush_handlers

- name: Patch Gitea DB host in app.ini
  command: >
    docker exec -i --user {{ gitea_user }} {{ gitea_container }}
    sed -ri "s|^(HOST\s*=\s*).*$|\1{{ database_host }}:{{ database_port }}|" {{ gitea_config }}
  notify: docker compose up

- name: Patch Gitea DB name in app.ini
  command: >
    docker exec -i --user {{ gitea_user }} {{ gitea_container }}
    sed -ri "s|^(NAME\s*=\s*).*$|\1{{ database_name }}|" {{ gitea_config }}
  notify: docker compose up

- name: Patch Gitea DB user in app.ini
  command: >
    docker exec -i --user {{ gitea_user }} {{ gitea_container }}
    sed -ri "s|^(USER\s*=\s*).*$|\1{{ database_username }}|" {{ gitea_config }}
  notify: docker compose up

- name: Patch Gitea DB password in app.ini
  command: >
    docker exec -i --user {{ gitea_user }} {{ gitea_container }}
    sed -ri "s|^(PASSWD\s*=\s*).*$|\1{{ database_password }}|" {{ gitea_config }}
  notify: docker compose up

- name: "Flush database patches"
  meta: flush_handlers