---

- name: Create archive dir
  file: path={{ penpot_root_dir }}/archives/{{ penpot_current_version }} state=directory
  tags: penpot

- name: Stop service during upgrade
  service: name={{ item }} state=stopped
  loop:
    - penpot-server
    - penpot-exporter
  tags: penpot

- name: Archive current version
  synchronize:
    src: "{{ penpot_root_dir }}/{{ item }}"
    dest: "{{ penpot_root_dir }}/archives/{{ penpot_current_version }}/"
    delete: True
    compress: False
  delegate_to: "{{ inventory_hostname }}"
  loop:
    - backend
    - frontend
    - etc
  tags: penpot

- name: Install postgresql client
  package: name=postgresql16
  tags: penpot

- name: Dump the database
  command: >
    /usr/pgsql-16/bin/pg_dump
    --clean
    --create
    --host={{ penpot_db_server | quote }}
    --port={{ penpot_db_port | quote }}
    --username={{ penpot_db_user | quote }} {{ penpot_db_name | quote }}
    --file="{{ penpot_root_dir }}/archives/{{ penpot_current_version }}/{{ penpot_db_name }}.sql"
  environment:
    - PGPASSWORD: "{{ penpot_db_pass }}"
  tags: penpot
