2022-02-05 20:32:54 +00:00
---
2020-12-22 17:32:43 +00:00
- name : Fail if Postgres not enabled
2022-07-18 07:39:08 +00:00
ansible.builtin.fail :
2024-10-07 05:46:05 +00:00
msg : "Postgres via ansible-role-postgres role is not enabled (`postgres_enabled`). Cannot migrate."
2024-09-27 06:37:24 +00:00
when : "not postgres_enabled | bool"
2020-12-22 17:32:43 +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:32:43 +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:32:43 +00:00
# Actual import work
2022-11-27 05:23:41 +00:00
- name : Ensure Postgres is started
2022-07-18 07:39:08 +00:00
ansible.builtin.service :
2024-09-27 06:37:24 +00:00
name : "{{ postgres_identifier }}"
2020-12-22 17:32:43 +00:00
state : started
2022-02-05 20:32:54 +00:00
daemon_reload : true
2022-11-27 05:23:41 +00:00
register : postgres_service_start_result
2020-12-22 17:32:43 +00:00
- 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:32:43 +00:00
timeout : "{{ postgres_start_wait_time }}"
delegate_to : 127.0 .0 .1
become : false
2022-11-27 05:23:41 +00:00
when : postgres_service_start_result.changed | bool
2020-12-22 17:32:43 +00:00
2021-05-26 19:41:52 +00:00
- name : Check existence of matrix-appservice-irc service
2022-07-18 08:22:05 +00:00
ansible.builtin.stat :
2022-11-04 14:38:38 +00:00
path : "{{ devture_systemd_docker_base_systemd_path }}/matrix-appservice-irc.service"
2021-05-26 19:41:52 +00:00
register : matrix_appservice_irc_service_stat
2020-12-22 17:32:43 +00:00
- name : Ensure matrix-appservice-irc is stopped
2022-07-18 07:39:08 +00:00
ansible.builtin.service :
2020-12-22 17:32:43 +00:00
name : matrix-appservice-irc
state : stopped
2021-05-26 19:41:52 +00:00
when : "matrix_appservice_irc_service_stat.stat.exists"
2020-12-22 17:32:43 +00:00
- name : Import appservice-irc NeDB database into Postgres
2022-07-18 07:39:08 +00:00
ansible.builtin.command :
2020-12-22 17:32:43 +00:00
cmd : >-
2022-11-04 14:39:35 +00:00
{{ devture_systemd_docker_base_host_command_docker }} run
2020-12-22 17:32:43 +00:00
--rm
--user={{ matrix_user_uid }}:{{ matrix_user_gid }}
--cap-drop=ALL
2024-01-13 15:10:02 +00:00
{% if matrix_appservice_irc_database_container_network %}
--network={{ matrix_appservice_irc_database_container_network }}
{% endif %}
2020-12-22 17:32:43 +00:00
--mount type=bind,src={{ matrix_appservice_irc_data_path }},dst=/data
--entrypoint=/bin/sh
{{ matrix_appservice_irc_docker_image }}
-c
'/usr/local/bin/node /app/lib/scripts/migrate-db-to-pgres.js --dbdir /data --privateKey /data/passkey.pem --connectionString {{ matrix_appservice_irc_database_connection_string }}'
2022-07-18 12:08:10 +00:00
register : matrix_appservice_irc_import_nedb_to_postgres_result
changed_when : matrix_appservice_irc_import_nedb_to_postgres_result.rc == 0
2020-12-22 17:32:43 +00:00
- name : Archive NeDB database files
2022-07-18 07:39:08 +00:00
ansible.builtin.command :
2020-12-22 17:32:43 +00:00
cmd : "mv {{ matrix_appservice_irc_data_path }}/{{ item }} {{ matrix_appservice_irc_data_path }}/{{ item }}.backup"
with_items :
- rooms.db
- users.db
2022-07-18 12:08:10 +00:00
register : matrix_appservice_irc_import_nedb_to_postgres_move_result
changed_when : matrix_appservice_irc_import_nedb_to_postgres_move_result.rc == 0
2020-12-22 17:56:52 +00:00
- name : Inject result
2022-07-18 07:39:08 +00:00
ansible.builtin.set_fact :
2022-11-04 14:19:17 +00:00
devture_playbook_runtime_messages_list : |
2020-12-22 17:56:52 +00:00
{{
2022-11-04 14:19:17 +00:00
devture_playbook_runtime_messages_list | default([])
2020-12-22 17:56:52 +00:00
+
[
2024-10-14 17:47:38 +00:00
"Note: Your appservice-irc database files have been imported into Postgres. The original database files have been moved from `{{ matrix_appservice_irc_data_path }}/*.db` to `{{ matrix_appservice_irc_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."
2020-12-22 17:56:52 +00:00
]
}}