Do not introduce sub-variables exposing implementation details

This commit is contained in:
Slavi Pantaleev 2020-12-14 10:51:53 +02:00
parent f1e85f7112
commit d91aa5a060
3 changed files with 26 additions and 22 deletions

View file

@ -70,7 +70,7 @@ matrix_appservice_discord_homeserver_token: "{{ matrix_synapse_macaroon_secret_k
# We only make this use Postgres if our own Postgres server is enabled.
# It's only then (for now) that we can automatically create the necessary database and user for this service.
matrix_appservice_discord_database_engine: "{{ 'postgres' if matrix_postgres_enabled else 'sqlite' }}"
matrix_appservice_discord_database_connString_password: "{{ matrix_synapse_macaroon_secret_key | password_hash('sha512', 'as.discord.db') | to_uuid }}"
matrix_appservice_discord_postgres_password: "{{ matrix_synapse_macaroon_secret_key | password_hash('sha512', 'as.discord.db') | to_uuid }}"
######################################################################
#
@ -950,10 +950,10 @@ matrix_postgres_db_name: "homeserver"
matrix_postgres_additional_databases: |
{{
([{
'name': matrix_appservice_discord_database_connString_db_name,
'username': matrix_appservice_discord_database_connString_username,
'password': matrix_appservice_discord_database_connString_password,
}] if (matrix_appservice_discord_enabled and matrix_appservice_discord_database_engine == 'postgres' and matrix_appservice_discord_database_connString_hostname == 'matrix-postgres') else [])
'name': matrix_appservice_discord_postgres_db_name,
'username': matrix_appservice_discord_postgres_username,
'password': matrix_appservice_discord_postgres_password,
}] if (matrix_appservice_discord_enabled and matrix_appservice_discord_database_engine == 'postgres' and matrix_appservice_discord_postgres_hostname == 'matrix-postgres') else [])
+ ([{
'name': matrix_appservice_slack_database_db_name
'username': matrix_appservice_slack_database_username

View file

@ -47,16 +47,23 @@ matrix_appservice_discord_bridge_enableSelfServiceBridging: false
#
# To use Postgres:
# - change the engine (`matrix_appservice_discord_database_engine: 'postgres'`)
# - adjust your database credentials
# - adjust your database credentials via the `matrix_appservice_discord_postgres_*` variables
matrix_appservice_discord_database_engine: 'sqlite'
matrix_appservice_discord_database_filename: "/data/{{ matrix_appservice_discord_database_filename_name }}"
matrix_appservice_discord_database_filename_name: "discord.db"
matrix_appservice_discord_database_connString: 'postgresql://{{ matrix_appservice_discord_database_connString_username }}:{{ matrix_appservice_discord_database_connString_password }}@{{ matrix_appservice_discord_database_connString_hostname }}:{{ matrix_appservice_discord_database_connString_port }}/{{ matrix_appservice_discord_database_connString_db_name }}'
matrix_appservice_discord_database_connString_username: 'matrix_appservice_discord'
matrix_appservice_discord_database_connString_password: 'some-password'
matrix_appservice_discord_database_connString_hostname: 'matrix-postgres'
matrix_appservice_discord_database_connString_port: 5432
matrix_appservice_discord_database_connString_db_name: 'matrix_appservice_discord'
matrix_appservice_discord_sqlite_database_path_local: "{{ matrix_appservice_discord_data_path }}/discord.db"
matrix_appservice_discord_sqlite_database_path_in_container: "/data/discord.db"
matrix_appservice_discord_postgres_username: 'matrix_appservice_discord'
matrix_appservice_discord_postgres_password: 'some-password'
matrix_appservice_discord_postgres_hostname: 'matrix-postgres'
matrix_appservice_discord_postgres_port: 5432
matrix_appservice_discord_postgres_db_name: 'matrix_appservice_discord'
# These 2 variables are what actually ends up in the bridge configuration.
# It's best if you don't change them directly, but rather redefine the sub-variables that constitute them.
matrix_appservice_discord_database_filename: "{{ matrix_appservice_discord_sqlite_database_path_in_container }}"
matrix_appservice_discord_database_connString: 'postgresql://{{ matrix_appservice_discord_postgres_username }}:{{ matrix_appservice_discord_postgres_password }}@{{ matrix_appservice_discord_postgres_hostname }}:{{ matrix_appservice_discord_postgres_port }}/{{ matrix_appservice_discord_postgres_db_name }}'
# Tells whether the bot should make use of "Privileged Gateway Intents".
#

View file

@ -1,26 +1,23 @@
---
- block:
- set_fact:
matrix_appservice_discord_sqlite_db_path: "{{ matrix_appservice_discord_data_path }}/{{ matrix_appservice_discord_database_filename_name }}"
- name: Check if an SQLite database already exists
stat:
path: "{{ matrix_appservice_discord_sqlite_db_path }}"
register: matrix_appservice_discord_sqlite_db_path_stat_result
path: "{{ matrix_appservice_discord_sqlite_database_path_local }}"
register: matrix_appservice_discord_sqlite_database_path_local_stat_result
- name: Fail if an SQLite database already exists when using Postgres
fail:
msg: >-
matrix_appservice_discord_database_engine has been set to `postgres` (which is our new default now).
However, we've discovered an existing SQLite database in {{ matrix_appservice_discord_data_path }}/{{ matrix_appservice_discord_database_filename_name }}.
However, we've discovered an existing SQLite database in {{ matrix_appservice_discord_sqlite_database_path_local }}.
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_appservice_discord_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_appservice_discord_sqlite_db_path }} postgres_db_connection_string={{ matrix_appservice_discord_database_connString }}'`)
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_appservice_discord_sqlite_database_path_local }} postgres_db_connection_string={{ matrix_appservice_discord_database_connString }}'`)
3. Re-run the playbook (`ansible-playbook -i inventory/hosts setup.yml --tags=setup-all,start`)
when: "matrix_appservice_discord_sqlite_db_path_stat_result.stat.exists"
when: "matrix_appservice_discord_sqlite_database_path_local_stat_result.stat.exists"
when: "matrix_appservice_discord_database_engine == 'postgres'"
- name: Ensure Appservice Discord image is pulled