Enable automatic (SQLite -> Postgres) migration for matrix-reminder-bot

This commit is contained in:
Slavi Pantaleev 2020-12-14 16:03:32 +02:00
parent dc7850e83c
commit ac37091d01

View File

@ -1,23 +1,29 @@
--- ---
- set_fact:
matrix_bot_matrix_reminder_bot_requires_restart: false
- block: - block:
- name: Check if an SQLite database already exists - name: Check if an SQLite database already exists
stat: stat:
path: "{{ matrix_bot_matrix_reminder_bot_sqlite_database_path_local }}" path: "{{ matrix_bot_matrix_reminder_bot_sqlite_database_path_local }}"
register: matrix_bot_matrix_reminder_bot_sqlite_database_path_local_stat_result register: matrix_bot_matrix_reminder_bot_sqlite_database_path_local_stat_result
- name: Fail if an SQLite database already exists when using Postgres - block:
fail: - set_fact:
msg: >- matrix_postgres_db_migration_request:
matrix_bot_matrix_reminder_bot_database_engine has been set to `postgres` (which is our new default now). src: "{{ matrix_bot_matrix_reminder_bot_sqlite_database_path_local }}"
However, we've discovered an existing SQLite database in {{ matrix_bot_matrix_reminder_bot_sqlite_database_path_local }}. dst: "{{ matrix_bot_matrix_reminder_bot_database_connection_string }}"
It appears that you've been using this bridge with the SQLite engine until now. caller: "{{ role_path|basename }}"
To continue using SQLite, opt into it explicitly: add `matrix_bot_matrix_reminder_bot_database_engine: sqlite` to your vars.yml file and re-run this same command. engine_variable_name: 'matrix_bot_matrix_reminder_bot_database_engine'
Alternatively, to migrate your existing SQLite database to Postgres: engine_old: 'sqlite'
1. Stop all services (`ansible-playbook -i inventory/hosts setup.yml --tags=stop`) systemd_services_to_stop: ['matrix-bot-matrix-reminder-bot.service']
2. Import the SQLite database into Postgres (`ansible-playbook -v -i inventory/hosts setup.yml --tags=import-generic-sqlite-db --extra-vars='sqlite_database_path={{ matrix_bot_matrix_reminder_bot_sqlite_database_path_local }} postgres_connection_string_variable_name=matrix_bot_matrix_reminder_bot_database_connection_string'`)
3. Re-run the playbook (`ansible-playbook -i inventory/hosts setup.yml --tags=setup-all,start`) - import_tasks: "roles/matrix-postgres/tasks/util/migrate_db_to_postgres.yml"
when: "matrix_bot_matrix_reminder_bot_sqlite_database_path_local_stat_result.stat.exists"
- set_fact:
matrix_bot_matrix_reminder_bot_requires_restart: true
when: "matrix_bot_matrix_reminder_bot_sqlite_database_path_local_stat_result.stat.exists|bool"
when: "matrix_bot_matrix_reminder_bot_database_engine == 'postgres'" when: "matrix_bot_matrix_reminder_bot_database_engine == 'postgres'"
- name: Ensure matrix-reminder-bot paths exist - name: Ensure matrix-reminder-bot paths exist
@ -59,3 +65,9 @@
service: service:
daemon_reload: yes daemon_reload: yes
when: "matrix_bot_matrix_reminder_bot_systemd_service_result.changed|bool" when: "matrix_bot_matrix_reminder_bot_systemd_service_result.changed|bool"
- name: Ensure matrix-bot-matrix-reminder-bot.service restarted, if necessary
service:
name: "matrix-bot-matrix-reminder-bot.service"
state: restarted
when: "matrix_bot_matrix_reminder_bot_requires_restart|bool"