mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-06-13 05:05:29 +03:00
nixos/tt-rss: fix and significantly simplify database setup
the schema files referenced in the current preStart are empty. other ones exist, but don't apply cleanly either. calling update.php with --update-schema works for initial setup and updates. if the database schema is already up to date, it's idempotent.
This commit is contained in:
parent
eda85eb31d
commit
f8df5ffdfe
1 changed files with 3 additions and 41 deletions
|
@ -595,47 +595,9 @@ let
|
||||||
tt-rss = {
|
tt-rss = {
|
||||||
description = "Tiny Tiny RSS feeds update daemon";
|
description = "Tiny Tiny RSS feeds update daemon";
|
||||||
|
|
||||||
preStart = let
|
preStart = ''
|
||||||
callSql = e:
|
${pkgs.php81}/bin/php ${cfg.root}/www/update.php --update-schema
|
||||||
if cfg.database.type == "pgsql" then ''
|
'';
|
||||||
${optionalString (cfg.database.password != null) "PGPASSWORD=${cfg.database.password}"} \
|
|
||||||
${optionalString (cfg.database.passwordFile != null) "PGPASSWORD=$(cat ${cfg.database.passwordFile})"} \
|
|
||||||
${config.services.postgresql.package}/bin/psql \
|
|
||||||
-U ${cfg.database.user} \
|
|
||||||
${optionalString (cfg.database.host != null) "-h ${cfg.database.host} --port ${toString dbPort}"} \
|
|
||||||
-c '${e}' \
|
|
||||||
${cfg.database.name}''
|
|
||||||
|
|
||||||
else if cfg.database.type == "mysql" then ''
|
|
||||||
echo '${e}' | ${config.services.mysql.package}/bin/mysql \
|
|
||||||
-u ${cfg.database.user} \
|
|
||||||
${optionalString (cfg.database.password != null) "-p${cfg.database.password}"} \
|
|
||||||
${optionalString (cfg.database.host != null) "-h ${cfg.database.host} -P ${toString dbPort}"} \
|
|
||||||
${cfg.database.name}''
|
|
||||||
|
|
||||||
else "";
|
|
||||||
|
|
||||||
in (optionalString (cfg.database.type == "pgsql") ''
|
|
||||||
exists=$(${callSql "select count(*) > 0 from pg_tables where tableowner = user"} \
|
|
||||||
| tail -n+3 | head -n-2 | sed -e 's/[ \n\t]*//')
|
|
||||||
|
|
||||||
if [ "$exists" == 'f' ]; then
|
|
||||||
${callSql "\\i ${pkgs.tt-rss}/schema/ttrss_schema_${cfg.database.type}.sql"}
|
|
||||||
else
|
|
||||||
echo 'The database contains some data. Leaving it as it is.'
|
|
||||||
fi;
|
|
||||||
'')
|
|
||||||
|
|
||||||
+ (optionalString (cfg.database.type == "mysql") ''
|
|
||||||
exists=$(${callSql "select count(*) > 0 from information_schema.tables where table_schema = schema()"} \
|
|
||||||
| tail -n+2 | sed -e 's/[ \n\t]*//')
|
|
||||||
|
|
||||||
if [ "$exists" == '0' ]; then
|
|
||||||
${callSql "\\. ${pkgs.tt-rss}/schema/ttrss_schema_${cfg.database.type}.sql"}
|
|
||||||
else
|
|
||||||
echo 'The database contains some data. Leaving it as it is.'
|
|
||||||
fi;
|
|
||||||
'');
|
|
||||||
|
|
||||||
serviceConfig = {
|
serviceConfig = {
|
||||||
User = "${cfg.user}";
|
User = "${cfg.user}";
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue