matrix-docker-ansible-deploy/roles/custom/matrix-bridge-appservice-slack/tasks/migrate_nedb_to_postgres.yml
Suguru Hirahara 8e63f12fbe
Setting up REUSE: add copyright statements to yml files in roles/custom/
Signed-off-by: Suguru Hirahara <acioustick@noreply.codeberg.org>
2024-12-08 05:01:07 +09:00

79 lines
2.9 KiB
YAML

# SPDX-FileCopyrightText: 2024 MDAD Team and contributors
#
# SPDX-License-Identifier: AGPL-3.0-or-later
---
- name: Fail if Postgres not enabled
ansible.builtin.fail:
msg: "Postgres via ansible-role-postgres role is not enabled (`postgres_enabled`). Cannot migrate."
when: "not postgres_enabled | bool"
# Defaults
- name: Set postgres_start_wait_time, if not provided
ansible.builtin.set_fact:
postgres_start_wait_time: 15
when: "postgres_start_wait_time | default('') == ''"
# Actual import work
- name: Ensure Postgres is started
ansible.builtin.service:
name: "{{ postgres_identifier }}"
state: started
daemon_reload: true
register: postgres_service_start_result
- name: Wait a bit, so that Postgres can start
ansible.builtin.wait_for:
timeout: "{{ postgres_start_wait_time }}"
delegate_to: 127.0.0.1
become: false
when: "postgres_service_start_result.changed | bool"
- name: Ensure matrix-appservice-slack is stopped
ansible.builtin.service:
name: matrix-appservice-slack
state: stopped
- name: Import appservice-slack NeDB database into Postgres
ansible.builtin.command:
cmd: >-
{{ devture_systemd_docker_base_host_command_docker }} run
--rm
--user={{ matrix_user_uid }}:{{ matrix_user_gid }}
--cap-drop=ALL
{% if matrix_appservice_slack_database_container_network %}
--network={{ matrix_appservice_irc_database_container_network }}
{% endif %}
--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 }}'
register: matrix_appservice_slack_import_nedb_to_postgres_result
changed_when: matrix_appservice_slack_import_nedb_to_postgres_result.rc == 0
- name: Archive NeDB database files
ansible.builtin.command:
cmd: "mv {{ matrix_appservice_slack_data_path }}/{{ item }} {{ matrix_appservice_slack_data_path }}/{{ item }}.backup"
register: matrix_appservice_slack_import_nedb_to_postgres_move_result
changed_when: matrix_appservice_slack_import_nedb_to_postgres_move_result.rc == 0
with_items:
- teams.db
- room-store.db
- user-store.db
- event-store.db
- name: Inject result
ansible.builtin.set_fact:
devture_playbook_runtime_messages_list: |
{{
devture_playbook_runtime_messages_list | default([])
+
[
"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."
]
}}