add postgres support for mx-puppet-* with fallback to sqlite in role and migration notice

This commit is contained in:
2020-12-14 12:38:51 +01:00
parent 087dbe4ddc
commit 5d70bc1376
18 changed files with 245 additions and 14 deletions

View File

@ -53,6 +53,21 @@ matrix_mx_puppet_skype_homeserver_token: ''
# Can be set to enable automatic double-puppeting via Shared Secret Auth (https://github.com/devture/matrix-synapse-shared-secret-auth).
matrix_mx_puppet_skype_login_shared_secret: ''
# Database configuration, role default is `sqlite` but playbook default is `postgres`
matrix_mx_puppet_skype_database_engine: sqlite
matrix_mx_puppet_skype_database_username: matrix_mx_puppet_skype
matrix_mx_puppet_skype_database_password: ~
matrix_mx_puppet_skype_database_hostname: 'matrix-postgres'
matrix_mx_puppet_skype_database_port: 5432
matrix_mx_puppet_skype_database_name: matrix_mx_puppet_skype
matrix_mx_puppet_skype_database_file: /data/database.db
matrix_mx_puppet_skype_database_connString: >-2
{%- if matrix_mx_puppet_skype_database_engine == 'postgres' -%}
postgresql://{{ matrix_mx_puppet_skype_database_username }}:{{ matrix_mx_puppet_skype_database_password }}@{{ matrix_mx_puppet_skype_database_hostname }}:{{ matrix_mx_puppet_skype_database_port }}/{{ matrix_mx_puppet_skype_database_name }}?sslmode=disable
{%- else if matrix_mx_puppet_skype_database_engine == 'sqlite' -%}
{{ matrix_mx_puppet_skype_database_engine }}://{{ matrix_mx_puppet_skype_database_file }}
{%- endif -%}
# Default configuration template which covers the generic use case.
# You can customize it by controlling the various variables inside it.
#

View File

@ -8,3 +8,23 @@
with_items:
- "matrix_mx_puppet_skype_appservice_token"
- "matrix_mx_puppet_skype_homeserver_token"
- block:
- name: Check if an SQLite database already exists
stat:
path: "{{ matrix_mx_puppet_skype_data_path }}/database.db"
register: matrix_mx_puppet_skype_sqlite_database_path_local_stat_result
- name: Fail if an SQLite database already exists when using Postgres
fail:
msg: >-
matrix_mx_puppet_skype_database_engine has been set to `postgres` (which is our new default now).
However, we've discovered an existing SQLite database in {{ matrix_mx_puppet_skype_data_path }}/database.db.
It appears that you've been using this bridge with the SQLite engine until now.
To continue using SQLite, opt into it explicitly: add `matrix_mx_puppet_skype_database_engine: sqlite` to your vars.yml file and re-run this same command.
Alternatively, to migrate your existing SQLite database to Postgres:
1. Stop all services (`ansible-playbook -i inventory/hosts setup.yml --tags=stop`)
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_mx_puppet_skype_data_path }}/database.db postgres_connection_string_variable_name=matrix_mx_puppet_skype_database_connString'`)
3. Re-run the playbook (`ansible-playbook -i inventory/hosts setup.yml --tags=setup-all,start`)
when: "matrix_mx_puppet_skype_sqlite_database_path_local_stat_result.stat.exists"
when: "matrix_mx_puppet_skype_database_engine == 'postgres'"

View File

@ -68,15 +68,18 @@ logging:
# - Store
database:
{% if matrix_mx_puppet_skype_database_engine == 'postgres' %}
# Use Postgres as a database backend
# If set, will be used instead of SQLite3
# Connection string to connect to the Postgres instance
# with username "user", password "pass", host "localhost" and database name "dbname".
# Modify each value as necessary
connString: "postgres://matrix_puppet_skype:{{ matrix_additional_databases | selectattr('name', 'equalto', 'matrix_puppet_skype') | map(attribute='pass') | first }}@{{ matrix_postgres_connection_hostname }}/matrix_puppet_skype?sslmode=disable"
connString: {{ matrix_mx_puppet_skype_database_connString | to_json }}
{% else %}
# Use SQLite3 as a database backend
# The name of the database file
#filename: /data/database.db
filename: {{ matrix_mx_puppet_skype_database_file }}
{% endif %}
provisioning:
# Regex of Matrix IDs allowed to use the puppet bridge