Add (SQLite + Postgres) support and automatic migration to matrix-ma1sd

This commit is contained in:
Slavi Pantaleev
2020-12-14 17:16:25 +02:00
parent 0ca48f3532
commit af3ea67bba
5 changed files with 82 additions and 4 deletions

View File

@ -39,6 +39,28 @@ matrix_ma1sd_systemd_wanted_services_list: []
# Enabling this is discouraged. Learn more here: https://github.com/ma1uta/ma1sd/blob/master/docs/features/identity.md#lookups
matrix_ma1sd_matrixorg_forwarding_enabled: false
# Database-related configuration fields.
#
# To use SQLite, stick to these defaults.
#
# To use Postgres:
# - change the engine (`matrix_ma1sd_database_engine: 'postgres'`)
# - adjust your database credentials via the `matrix_ma1sd_postgres_*` variables
matrix_ma1sd_database_engine: 'sqlite'
matrix_ma1sd_sqlite_database_path_local: "{{ matrix_ma1sd_data_path }}/ma1sd.db"
matrix_ma1sd_sqlite_database_path_in_container: "/var/ma1sd/ma1sd.db"
matrix_ma1sd_database_username: 'matrix_ma1sd'
matrix_ma1sd_database_password: 'some-password'
matrix_ma1sd_database_hostname: 'matrix-postgres'
matrix_ma1sd_database_port: 5432
matrix_ma1sd_database_db_name: 'matrix_ma1sd'
matrix_ma1sd_database_connection_string: 'postgresql://{{ matrix_ma1sd_database_username }}:{{ matrix_ma1sd_database_password }}@{{ matrix_ma1sd_database_hostname }}:{{ matrix_ma1sd_database_port }}/{{ matrix_ma1sd_database_db_name }}'
# ma1sd has serveral supported identity stores.
# One of them is storing identities directly in Synapse's database.
# Learn more here: https://github.com/ma1uta/ma1sd/blob/master/docs/stores/synapse.md

View File

@ -15,6 +15,36 @@
- import_tasks: "{{ role_path }}/tasks/migrate_mxisd.yml"
# These (SQLite -> Postgres) migration tasks are usually at the top,
# but we'd like to run them after `migrate_mxisd.yml`, which requires the ma1sd paths to exist.
- set_fact:
matrix_ma1sd_requires_restart: false
- block:
- name: Check if an SQLite database already exists
stat:
path: "{{ matrix_ma1sd_sqlite_database_path_local }}"
register: matrix_ma1sd_sqlite_database_path_local_stat_result
- block:
- set_fact:
matrix_postgres_db_migration_request:
src: "{{ matrix_ma1sd_sqlite_database_path_local }}"
dst: "{{ matrix_ma1sd_database_connection_string }}"
caller: "{{ role_path|basename }}"
engine_variable_name: 'matrix_ma1sd_database_engine'
engine_old: 'sqlite'
systemd_services_to_stop: ['matrix-ma1sd.service']
pgloader_options: ['--with "quote identifiers"']
- import_tasks: "roles/matrix-postgres/tasks/util/migrate_db_to_postgres.yml"
- set_fact:
matrix_ma1sd_requires_restart: true
when: "matrix_ma1sd_sqlite_database_path_local_stat_result.stat.exists|bool"
when: "matrix_ma1sd_database_engine == 'postgres'"
- name: Ensure ma1sd image is pulled
docker_image:
name: "{{ matrix_ma1sd_docker_image }}"
@ -102,3 +132,9 @@
service:
daemon_reload: yes
when: "matrix_ma1sd_systemd_service_result.changed|bool"
- name: Ensure matrix-ma1sd.service restarted, if necessary
service:
name: "matrix-ma1sd.service"
state: restarted
when: "matrix_ma1sd_requires_restart|bool"

View File

@ -11,9 +11,19 @@ key:
path: /var/ma1sd/sign.key
storage:
provider:
sqlite:
database: /var/ma1sd/ma1sd.db
{% if matrix_ma1sd_database_engine == 'sqlite' %}
backend: sqlite
provider:
sqlite:
database: {{ matrix_ma1sd_sqlite_database_path_in_container|to_json }}
{% elif matrix_ma1sd_database_engine == 'postgres' %}
backend: postgresql
provider:
postgresql:
database: //{{ matrix_ma1sd_database_hostname }}:{{ matrix_ma1sd_database_port }}/{{ matrix_ma1sd_database_db_name }}
username: {{ matrix_ma1sd_database_username|to_json }}
password: {{ matrix_ma1sd_database_password|to_json }}
{% endif %}
{% if matrix_ma1sd_dns_overwrite_enabled %}
dns: