Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

postgres: create databases for all services #740

Merged
merged 83 commits into from
Dec 23, 2020

Commits on Dec 10, 2020

  1. WIP: postgres: create databases for all services

    If a service is enabled, a database for it is created in postgres with a uniqque password. The service can then use this database for data storage instead of relying on sqlite.
    jdreichmann committed Dec 10, 2020
    Configuration menu
    Copy the full SHA
    d9f4914 View commit details
    Browse the repository at this point in the history

Commits on Dec 13, 2020

  1. Configuration menu
    Copy the full SHA
    77a5c7c View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    dac0d3a View commit details
    Browse the repository at this point in the history
  3. Relocate Postgres additional database creation logic

    Moving it above the "uninstalling" set of tasks is better.
    Extracting it out to another file at the same time, for readability,
    especially given that it will probably have to become more complex in
    the future (potentially installing `jq`, etc.)
    spantaleev committed Dec 13, 2020
    Configuration menu
    Copy the full SHA
    527d5f5 View commit details
    Browse the repository at this point in the history
  4. Allow username of additional Postgres databases to be different

    We'll most likely use one that matches the database name, but
    it's better to have it configurable.
    spantaleev committed Dec 13, 2020
    Configuration menu
    Copy the full SHA
    0641106 View commit details
    Browse the repository at this point in the history
  5. Fix syntax issues in matrix_postgres_additional_databases

    Quotes are necessary around dictionary field names.
    
    There was a missing `}` as well.
    spantaleev committed Dec 13, 2020
    Configuration menu
    Copy the full SHA
    d251764 View commit details
    Browse the repository at this point in the history
  6. Configuration menu
    Copy the full SHA
    f47e8a9 View commit details
    Browse the repository at this point in the history
  7. Determine matrix-postgres IP address without relying on jq

    To avoid needing to have `jq` installed on the machine, we could:
    - try to run jq in a Docker container using some small image providing
    that
    - better yet, avoid `jq` altogether
    spantaleev committed Dec 13, 2020
    Configuration menu
    Copy the full SHA
    e2952f1 View commit details
    Browse the repository at this point in the history
  8. Prevent weird loop error

    > Invalid data passed to 'loop', it requires a list, got this instead: matrix_postgres_additional_databases. Hint: If you passed a list/dict of just one element, try adding wantlist=True to your lookup invocation or use q/query instead of lookup.
    
    Well, or working around it, as I've done in this commit (which seems
    more sane than `wantlist=True` stuff).
    spantaleev committed Dec 13, 2020
    Configuration menu
    Copy the full SHA
    c765ceb View commit details
    Browse the repository at this point in the history
  9. Do not execute additional databases creation code if not necessary

    The tasks in `create_additional_databases.yml` will likely
    ensure `matrix-postgres.service` is started, etc.
    
    If no additional databases are defined, we'd rather not execute that
    file and all these tasks that it may do in the future.
    spantaleev committed Dec 13, 2020
    Configuration menu
    Copy the full SHA
    bbc09d0 View commit details
    Browse the repository at this point in the history
  10. Do not use the postgresql_user/postgresql_db modules

    While these modules are really nice and helpful, we can't use them
    for at least 2 reasons:
    
    - for us, Postgres runs in a container on a private Docker network
    (`--network=matrix`) without usually being exposed to the host.
    These modules execute on the host so they won't be able to reach it.
    
    - these modules require `psycopg2`, so we need to install it before
    using it. This might or might not be its own can of worms.
    spantaleev committed Dec 13, 2020
    Configuration menu
    Copy the full SHA
    da4cb2f View commit details
    Browse the repository at this point in the history
  11. Configuration menu
    Copy the full SHA
    3a037a5 View commit details
    Browse the repository at this point in the history
  12. Use "password" for additional Postgres databases, not "pass"

    Being more explicit sounds better.
    spantaleev committed Dec 13, 2020
    Configuration menu
    Copy the full SHA
    46a4034 View commit details
    Browse the repository at this point in the history
  13. Make appservice-discord support both SQLite and Postgres

    People can toggle between them now. The playbook also defaults
    to using SQLite if an external Postgres server is used.
    
    Ideally, we'd be able to create databases/users in external Postgres
    servers as well, but our initialization logic (and `docker run` command,
    etc.) hardcode too many things right now.
    spantaleev committed Dec 13, 2020
    Configuration menu
    Copy the full SHA
    a374d30 View commit details
    Browse the repository at this point in the history
  14. Configuration menu
    Copy the full SHA
    183d2a1 View commit details
    Browse the repository at this point in the history
  15. Simplify password for additional Postgres databases

    Using the result of `password_hash` works for creating them,
    but authentication seems to be failing with some tools like pgloader.
    
    It's possible that we're not escaping things properly somewhere.
    Ideally, it'd be nice to solve that. But the easier (and still
    relatively safe/good) solution is to just turn that password hash
    into a UUID that's safe for passing around without worrying about
    escaping.
    spantaleev committed Dec 13, 2020
    Configuration menu
    Copy the full SHA
    dd99499 View commit details
    Browse the repository at this point in the history
  16. Configuration menu
    Copy the full SHA
    b87b754 View commit details
    Browse the repository at this point in the history
  17. Configuration menu
    Copy the full SHA
    c66c084 View commit details
    Browse the repository at this point in the history

Commits on Dec 14, 2020

  1. Add --tags=import-generic-sqlite-db (pgloader import)

    This can be used by various bridges, etc., to import an SQLite
    (or some other supported) database into Postgres.
    spantaleev committed Dec 14, 2020
    Configuration menu
    Copy the full SHA
    cb969c6 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    4617984 View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    b217a2e View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    f1e85f7 View commit details
    Browse the repository at this point in the history
  5. Configuration menu
    Copy the full SHA
    d91aa5a View commit details
    Browse the repository at this point in the history
  6. Configuration menu
    Copy the full SHA
    c0edacb View commit details
    Browse the repository at this point in the history
  7. Rename Postgres-related variables (matrix*database_* -> `matrix*pos…

    …tgres_*`)
    
    `matrix_SERVICE_database_engine` remains as it is - the only one with a
    `_database_` infix. Postgres-related ones move to `_postgres_`.
    spantaleev committed Dec 14, 2020
    Configuration menu
    Copy the full SHA
    2a99e84 View commit details
    Browse the repository at this point in the history
  8. Make --tags=import-generic-sqlite-db commands not pass a sensitive co…

    …nnection string around
    
    Instead of passing the connection string, we can now pass a name of a
    variable, which contains a connection string.
    
    Both are supported for having extra flexibility.
    spantaleev committed Dec 14, 2020
    Configuration menu
    Copy the full SHA
    5dba0c0 View commit details
    Browse the repository at this point in the history
  9. Configuration menu
    Copy the full SHA
    2d99ade View commit details
    Browse the repository at this point in the history
  10. Move some things around

    spantaleev committed Dec 14, 2020
    Configuration menu
    Copy the full SHA
    a3406a1 View commit details
    Browse the repository at this point in the history
  11. Add (Postgres + SQLite) support to matrix-mautrix-telegram bridge

    I don't use this bridge, so this is completely untested.
    spantaleev committed Dec 14, 2020
    Configuration menu
    Copy the full SHA
    9bf8ce8 View commit details
    Browse the repository at this point in the history
  12. Rename _database_hostname to _postgres_hostname

    Should have been done during 2a99e84, but I've missed it.
    
    Because of this, 9bf8ce8 was also incomplete and would have caused
    an error.
    spantaleev committed Dec 14, 2020
    Configuration menu
    Copy the full SHA
    05dd091 View commit details
    Browse the repository at this point in the history
  13. Fix typo (matrix_telegram_facebook_postgres_hostname -> matrix_mautri…

    …x_telegram_postgres_hostname)
    
    Related to 9bf8ce8.
    spantaleev committed Dec 14, 2020
    Configuration menu
    Copy the full SHA
    6a2dd80 View commit details
    Browse the repository at this point in the history
  14. Remove some remaining _database_password usage in favor of `_postgr…

    …es_pasword`
    
    The only one that remains is `matrix_synapse_database_password`, but
    that's something old and should be dealt with separately in the future
    (unless it remains as it is).
    spantaleev committed Dec 14, 2020
    Configuration menu
    Copy the full SHA
    2848322 View commit details
    Browse the repository at this point in the history
  15. Add (Postgres + SQLite) support to matrix-mautrix-whatsapp bridge

    I don't use this bridge, so this is completely untested.
    spantaleev committed Dec 14, 2020
    Configuration menu
    Copy the full SHA
    6c77eae View commit details
    Browse the repository at this point in the history
  16. Fix sqlite usage for mautrix-facebook/mautrix-telegram

    Regression since 2d99ade and 9bf8ce8, respectively.
    
    When SQLite is to be used, these bridges expect an `sqlite://`
    connection string, and not a plain file name (path), like Appservice
    Discord and mautrix-whatsapp do.
    spantaleev committed Dec 14, 2020
    Configuration menu
    Copy the full SHA
    43d6ff2 View commit details
    Browse the repository at this point in the history
  17. Add (Postgres + SQLite) support to matrix-mautrix-hangouts bridge

    I don't use this bridge, so this is completely untested.
    spantaleev committed Dec 14, 2020
    Configuration menu
    Copy the full SHA
    ce21ea3 View commit details
    Browse the repository at this point in the history
  18. Rename matrix_*_postgres_* back to matrix_*_database_*

    I was thinking that it makes sense to be more specific,
    and using `_postgres_` also separated these variables
    from the `_database_` variables that ended up in bridge configuration.
    
    However, @jdreichmann makes a good point
    (spantaleev#740 (comment))
    that we don't need to be so specific and can allow for other engines (like MySQL) to use these variables.
    spantaleev committed Dec 14, 2020
    Configuration menu
    Copy the full SHA
    087dbe4 View commit details
    Browse the repository at this point in the history
  19. Configuration menu
    Copy the full SHA
    5d70bc1 View commit details
    Browse the repository at this point in the history
  20. Rename some remaining matrix_*_postgres_* vars back to `matrix_*_da…

    …tabase_*`
    
    Looks like there are some that I missed in 087dbe4
    spantaleev committed Dec 14, 2020
    Configuration menu
    Copy the full SHA
    b9a04a7 View commit details
    Browse the repository at this point in the history
  21. Configuration menu
    Copy the full SHA
    aa828ff View commit details
    Browse the repository at this point in the history
  22. Configuration menu
    Copy the full SHA
    dde1c9f View commit details
    Browse the repository at this point in the history
  23. Add (Postgres + SQLite) support to matrix-reminder-bot

    This has been tested and appears to work.
    spantaleev committed Dec 14, 2020
    Configuration menu
    Copy the full SHA
    e3a0c9a View commit details
    Browse the repository at this point in the history
  24. add postgres support mx-appservice-[slack|irc] with fallback to nedb …

    …in role and migration notice
    jdreichmann committed Dec 14, 2020
    Configuration menu
    Copy the full SHA
    54da61f View commit details
    Browse the repository at this point in the history
  25. Configuration menu
    Copy the full SHA
    bc376c2 View commit details
    Browse the repository at this point in the history
  26. Configuration menu
    Copy the full SHA
    dc7850e View commit details
    Browse the repository at this point in the history
  27. Configuration menu
    Copy the full SHA
    ac37091 View commit details
    Browse the repository at this point in the history
  28. Configuration menu
    Copy the full SHA
    c1431b2 View commit details
    Browse the repository at this point in the history
  29. Configuration menu
    Copy the full SHA
    bbc0872 View commit details
    Browse the repository at this point in the history
  30. Configuration menu
    Copy the full SHA
    3ba8520 View commit details
    Browse the repository at this point in the history
  31. Configuration menu
    Copy the full SHA
    86a8091 View commit details
    Browse the repository at this point in the history
  32. Configuration menu
    Copy the full SHA
    13f84e2 View commit details
    Browse the repository at this point in the history
  33. Configuration menu
    Copy the full SHA
    cba973d View commit details
    Browse the repository at this point in the history
  34. Configuration menu
    Copy the full SHA
    7248eb3 View commit details
    Browse the repository at this point in the history
  35. Configuration menu
    Copy the full SHA
    0ca48f3 View commit details
    Browse the repository at this point in the history
  36. Configuration menu
    Copy the full SHA
    af3ea67 View commit details
    Browse the repository at this point in the history
  37. Configuration menu
    Copy the full SHA
    3ab7dd1 View commit details
    Browse the repository at this point in the history
  38. Configuration menu
    Copy the full SHA
    13d8a9b View commit details
    Browse the repository at this point in the history
  39. Configuration menu
    Copy the full SHA
    516ccb2 View commit details
    Browse the repository at this point in the history
  40. Prepare matrix-registation for (SQLite + Postgres) support

    Auto-migration and everything seems to work. It's just that
    matrix-registration cannot load the Python modules required
    for talking to a Postgres database.
    
    Tracked here: zeratax/matrix-registration#44
    
    Until this gets fixed, we'll continue default to 'sqlite'.
    spantaleev committed Dec 14, 2020
    Configuration menu
    Copy the full SHA
    8d74593 View commit details
    Browse the repository at this point in the history
  41. Configuration menu
    Copy the full SHA
    374f437 View commit details
    Browse the repository at this point in the history
  42. Add support for matrix_dimension_systemd_{required,wanted}_services_list

    We were referencing them from `group_vars/matrix_servers` since
    recently, but there were no such variables and they weren't being put to
    use.
    spantaleev committed Dec 14, 2020
    Configuration menu
    Copy the full SHA
    0790a7b View commit details
    Browse the repository at this point in the history
  43. Configuration menu
    Copy the full SHA
    2a502db View commit details
    Browse the repository at this point in the history
  44. Fix Postgres database importing/upgrading conflicts

    We were running into conflicts, because having initialized
    the roles (users) and databases, trying to import leads to
    errors (role XXX already exists, etc.).
    
    We were previously ignoring the Synapse database (`homeserver`)
    when upgrading/importing, because that one gets created by default
    whenever the container starts.
    
    For our additional databases, it's a similar situation now.
    It's not created by default as soon as Postgres starts with an empty
    database, but rather we create it as part of running the playbook.
    
    So we either need to skip those role/database creation statements
    while upgrading/importing, or to avoid creating the additional database
    and rely on the import for that. I've gone for the former, because
    it's already similar to what we were doing and it's simpler
    (it lets `setup_postgres.yml` be the same in all scenarios).
    spantaleev committed Dec 14, 2020
    Configuration menu
    Copy the full SHA
    dd797ba View commit details
    Browse the repository at this point in the history
  45. Configuration menu
    Copy the full SHA
    e2ba46b View commit details
    Browse the repository at this point in the history

Commits on Dec 15, 2020

  1. Configuration menu
    Copy the full SHA
    3289298 View commit details
    Browse the repository at this point in the history
  2. Add support for executing additional DB migration statements

    In cases where pgloader is not enough and we need to do some additional
    migration work after it, we can now use
    `additional_psql_statements_list` and
    `additional_psql_statements_db_name`.
    
    This is to be used when migrating `matrix-registration`'s data at the
    very least.
    spantaleev committed Dec 15, 2020
    Configuration menu
    Copy the full SHA
    1bd5c24 View commit details
    Browse the repository at this point in the history
  3. Make matrix-registration use Postgres by default

    Now that 0.7.2 is out, the Docker image supports Postgres
    and we can do the (SQLite -> Postgres) migration.
    
    I've also found out that we needed to fix up the `tokens.ex_date` column
    data type a bit to prevent matrix-registration from raising exceptions
    when comparing `datetime.now()` with `ex_date` coming from the database.
    
    Example:
    
    > File "/usr/local/lib/python3.8/site-packages/matrix_registration/tokens.py", line 58, in valid
    > expired = self.ex_date < datetime.now()
    > TypeError: can't compare offset-naive and offset-aware datetimes
    spantaleev committed Dec 15, 2020
    Configuration menu
    Copy the full SHA
    a197968 View commit details
    Browse the repository at this point in the history

Commits on Dec 16, 2020

  1. Configuration menu
    Copy the full SHA
    0f4649a View commit details
    Browse the repository at this point in the history

Commits on Dec 22, 2020

  1. Relocate some tasks

    spantaleev committed Dec 22, 2020
    Configuration menu
    Copy the full SHA
    6488e11 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    9b4bf73 View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    149872e View commit details
    Browse the repository at this point in the history
  4. Add missing restart task

    Should have been part of 149872e
    spantaleev committed Dec 22, 2020
    Configuration menu
    Copy the full SHA
    e64758c View commit details
    Browse the repository at this point in the history
  5. Configuration menu
    Copy the full SHA
    44c9f4d View commit details
    Browse the repository at this point in the history
  6. Ensure mx-puppet-discord directories are created before attempting mi…

    …gration
    
    Our old (base-path -> data-path) SQLite migration can't work otherwise.
    
    It's probably not necessary to keep it anymore, but since we still do,
    at least we should take care to ensure it works.
    spantaleev committed Dec 22, 2020
    Configuration menu
    Copy the full SHA
    d135cd9 View commit details
    Browse the repository at this point in the history
  7. Configuration menu
    Copy the full SHA
    e49eb07 View commit details
    Browse the repository at this point in the history
  8. Configuration menu
    Copy the full SHA
    262a25f View commit details
    Browse the repository at this point in the history
  9. Configuration menu
    Copy the full SHA
    69cc214 View commit details
    Browse the repository at this point in the history
  10. Configuration menu
    Copy the full SHA
    ab6563c View commit details
    Browse the repository at this point in the history
  11. Configuration menu
    Copy the full SHA
    15f4cc9 View commit details
    Browse the repository at this point in the history
  12. Fix alignment issues

    spantaleev committed Dec 22, 2020
    Configuration menu
    Copy the full SHA
    815a80c View commit details
    Browse the repository at this point in the history
  13. Configuration menu
    Copy the full SHA
    715bdf2 View commit details
    Browse the repository at this point in the history
  14. Configuration menu
    Copy the full SHA
    9b95e19 View commit details
    Browse the repository at this point in the history
  15. Configuration menu
    Copy the full SHA
    8675ded View commit details
    Browse the repository at this point in the history

Commits on Dec 23, 2020

  1. Configuration menu
    Copy the full SHA
    ad1425e View commit details
    Browse the repository at this point in the history