-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for automatic (nedb -> Postgres) migration to matrix-apps…
…ervice-slack
- Loading branch information
1 parent
9b95e19
commit 8675ded
Showing
9 changed files
with
123 additions
and
144 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
roles/matrix-bridge-appservice-slack/tasks/migrate_nedb_to_postgres.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
- name: Fail if Postgres not enabled | ||
fail: | ||
msg: "Postgres via the matrix-postgres role is not enabled (`matrix_postgres_enabled`). Cannot migrate." | ||
when: "not matrix_postgres_enabled|bool" | ||
|
||
# Defaults | ||
|
||
- name: Set postgres_start_wait_time, if not provided | ||
set_fact: | ||
postgres_start_wait_time: 15 | ||
when: "postgres_start_wait_time|default('') == ''" | ||
|
||
# Actual import work | ||
|
||
- name: Ensure matrix-postgres is started | ||
service: | ||
name: matrix-postgres | ||
state: started | ||
daemon_reload: yes | ||
register: matrix_postgres_service_start_result | ||
|
||
- name: Wait a bit, so that Postgres can start | ||
wait_for: | ||
timeout: "{{ postgres_start_wait_time }}" | ||
delegate_to: 127.0.0.1 | ||
become: false | ||
when: "matrix_postgres_service_start_result.changed|bool" | ||
|
||
- name: Ensure matrix-appservice-slack is stopped | ||
service: | ||
name: matrix-appservice-slack | ||
state: stopped | ||
|
||
- name: Import appservice-slack NeDB database into Postgres | ||
command: | ||
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 | ||
command: | ||
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 | ||
set_fact: | ||
matrix_playbook_runtime_results: | | ||
{{ | ||
matrix_playbook_runtime_results|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." | ||
] | ||
}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters