2022-02-05 20:32:54 +00:00
---
2020-12-22 17:56:52 +00:00
- name : Fail if Postgres not enabled
2022-07-18 07:39:08 +00:00
ansible.builtin.fail :
2020-12-22 17:56:52 +00:00
msg : "Postgres via the matrix-postgres role is not enabled (`matrix_postgres_enabled`). Cannot migrate."
2022-07-18 08:22:05 +00:00
when : "not matrix_postgres_enabled | bool"
2020-12-22 17:56:52 +00:00
# Defaults
- name : Set postgres_start_wait_time, if not provided
2022-07-18 07:39:08 +00:00
ansible.builtin.set_fact :
2020-12-22 17:56:52 +00:00
postgres_start_wait_time : 15
2022-07-18 08:22:05 +00:00
when : "postgres_start_wait_time | default('') == ''"
2020-12-22 17:56:52 +00:00
# Actual import work
- name : Ensure matrix-postgres is started
2022-07-18 07:39:08 +00:00
ansible.builtin.service :
2020-12-22 17:56:52 +00:00
name : matrix-postgres
state : started
2022-02-05 20:32:54 +00:00
daemon_reload : true
2020-12-22 17:56:52 +00:00
register : matrix_postgres_service_start_result
- name : Wait a bit, so that Postgres can start
2022-07-18 08:22:05 +00:00
ansible.builtin.wait_for :
2020-12-22 17:56:52 +00:00
timeout : "{{ postgres_start_wait_time }}"
delegate_to : 127.0 .0 .1
become : false
2022-07-18 08:22:05 +00:00
when : "matrix_postgres_service_start_result.changed | bool"
2020-12-22 17:56:52 +00:00
- name : Ensure matrix-appservice-slack is stopped
2022-07-18 07:39:08 +00:00
ansible.builtin.service :
2020-12-22 17:56:52 +00:00
name : matrix-appservice-slack
state : stopped
- name : Import appservice-slack NeDB database into Postgres
2022-07-18 07:39:08 +00:00
ansible.builtin.command :
2020-12-22 17:56:52 +00:00
cmd : >-
{{ matrix_host_command_docker }} run
--rm
--user={{ matrix_user_uid }}:{{ matrix_user_gid }}
--cap-drop=ALL
--network={{ matrix_docker_network }}
--mount type=bind,src={{ matrix_appservice_slack_data_path }},dst=/data
--entrypoint=/bin/sh
{{ matrix_appservice_slack_docker_image }}
-c
'/usr/local/bin/node /usr/src/app/lib/scripts/migrateToPostgres.js --dbdir /data --connectionString {{ matrix_appservice_slack_database_connection_string }}'
- name : Archive NeDB database files
2022-07-18 07:39:08 +00:00
ansible.builtin.command :
2020-12-22 17:56:52 +00:00
cmd : "mv {{ matrix_appservice_slack_data_path }}/{{ item }} {{ matrix_appservice_slack_data_path }}/{{ item }}.backup"
with_items :
- teams.db
- room-store.db
- user-store.db
- event-store.db
- name : Inject result
2022-07-18 07:39:08 +00:00
ansible.builtin.set_fact :
2020-12-22 17:56:52 +00:00
matrix_playbook_runtime_results : |
{{
2022-07-18 08:22:05 +00:00
matrix_playbook_runtime_results | default([])
2020-12-22 17:56:52 +00:00
+
[
"NOTE: Your appservice-slack database files have been imported into Postgres. The original database files have been moved from `{{ matrix_appservice_slack_data_path }}/*.db` to `{{ matrix_appservice_slack_data_path }}/*.db.backup`. When you've confirmed that the import went well and everything works, you should be able to safely delete these files."
]
}}