---

- name: Create the archive dir
  file: path={{ odoo_root_dir }}/archives/{{ odoo_current_version }} state=directory
  tags: odoo

- name: Install postgresql client
  package:
    name:
      - postgresql15
  tags: odoo

- name: Stop the server during upgrade
  service: name=odoo-server state=stopped
  tags: odoo

- name: Archive previous version
  synchronize:
    src: "{{ odoo_root_dir }}/{{ item }}"
    dest: "{{ odoo_root_dir }}/archives/{{ odoo_current_version }}/"
    recursive: True
    delete: True
    compress: False
  loop:
    - venv
    - app
  delegate_to: "{{ inventory_hostname }}"
  tags: odoo

- name: Dump the database
  command: >
    /usr/pgsql-15/bin/pg_dump
    --clean
    --create
    --host={{ odoo_db_server | quote }}
    --port={{ odoo_db_port | quote }}
    --username={{ odoo_db_user }} {{ odoo_db_name | quote }}
    --file="{{ odoo_root_dir }}/archives/{{ odoo_current_version }}/{{ odoo_db_name }}.sql"
  environment:
    - PGPASSWORD: "{{ odoo_db_pass }}"
  tags: odoo

