Skip to content

Commit

Permalink
matrix-synapse: default to postgresql on 18.03
Browse files Browse the repository at this point in the history
  • Loading branch information
corngood committed Feb 5, 2018
1 parent 1472fa8 commit a4b7de7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
14 changes: 14 additions & 0 deletions nixos/doc/manual/release-notes/rl-1803.xml
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,20 @@ following incompatible changes:</para>
<literal>lib.mkOverride</literal> can be used.
</para>
</listitem>
<listitem>
<para>
The following changes apply if the <literal>stateVersion</literal> is changed to 18.03 or higher.
For <literal>stateVersion = "17.09"</literal> or lower the old behavior is preserved.
</para>
<itemizedlist>
<listitem>
<para>
<literal>matrix-synapse</literal> uses postgresql by default instead of sqlite.
Migration instructions can be found <link xlink:href="https://github.com/matrix-org/synapse/blob/master/docs/postgres.rst#porting-from-sqlite"> here </link>.
</para>
</listitem>
</itemizedlist>
</listitem>
</itemizedlist>

</section>
Expand Down
4 changes: 3 additions & 1 deletion nixos/modules/services/misc/matrix-synapse.nix
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,9 @@ in {
};
database_type = mkOption {
type = types.enum [ "sqlite3" "psycopg2" ];
default = "sqlite3";
default = if versionAtLeast config.system.stateVersion "18.03"
then "psycopg2"
else "sqlite3";
description = ''
The database engine name. Can be sqlite or psycopg2.
'';
Expand Down

6 comments on commit a4b7de7

@jeschmidt
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@corngood Can you comment on why the default was changed from sqlite3 to postgresql? This just broke my matrix-synapse setup (which was not specifying the database_type variable) during a nixos-rebuild switch command. (Until I added database_type="sqlite3" of course.)

Could the package possibly detect whether sqlite3 was already in use on the system as another conditional before switching automatically to psycopg2?

@corngood
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jeschmidt I changed it after migrating myself because I was told multiple times not to use the sqlite database for a real server. I'm trying to find some actual docs on that, but I'm not seeing anything obvious aside from this, with no references:

matrix-org/synapse#2889

Did you already have your stateVersion set to 18.03? That's probably not a good idea for anything you want to keep working, because it's a moving target until release.

If you had it set < 18.03, then there's a serious problem.

@jeschmidt
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, interesting. As for stateVersion, what likely happened is that it was set to less than 18.03 then when I ran nix-channel --update and nixos-rebuild switch, it got bumped to >= 18.03. I'm using nixos-unstable for a channel, which could be the source of the issue. I don't specifically set stateVersion myself. (Nor actually do I know how to query it.)

Perhaps I will plan to migrate to postgresql at some point. Just wasn't expecting it to happen today! :)

I do recall a different nix package that went through a similar transition where a configuration variable default changed (in a "breaking" sort of way). That package had some check for whether the previous default was being used, and to keep the old default if so. Only fresh installations would get the new default. Seemed like a nice design pattern, but unfortunately I can't recall which nix package that was. If I find it, I will link it here.

@corngood
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nixos-generate-config should spit out a config file with the stateVersion set. If you don't have that I suppose it will just be set to the latest.

My advice is to keep it set to the latest released version (17.09 now) and once a new version is released, read the stateVersion section in the release notes before updating it. In this case the should be a note explaining the matrix change and a link to the migration docs. You can also just leave it at 17.09 as long as things are working fine.

@corngood
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could the package possibly detect whether sqlite3 was already in use on the system as another conditional before switching automatically to psycopg2?

It doesn't have any knowledge about the running system config. That would be fragile anyway. stateVersion is basically the way you do this.

I do recall a different nix package that went through a similar transition where a configuration variable default changed (in a "breaking" sort of way).

I don't think this would work here, because we want the same exact configuration to use postgres now instead of sqlite, so there's nothing you could use to differentiate them in general (aside from database_type).

@jeschmidt
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the advice. I have now added system.stateVersion = "17.09"; to my configuration.nix and it is working. It is likely that nixos-generate-config does specify this now, but I installed this version of nixos quite some time ago and I've just been dragging it (kicking and screaming, sometimes) through the major updates.

Please sign in to comment.