mirror of
https://github.com/ilyakooo0/nixpkgs.git
synced 2025-01-05 02:23:07 +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
@ -595,47 +595,9 @@ let
|
||||
tt-rss = {
|
||||
description = "Tiny Tiny RSS feeds update daemon";
|
||||
|
||||
preStart = let
|
||||
callSql = e:
|
||||
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;
|
||||
'');
|
||||
preStart = ''
|
||||
${pkgs.php81}/bin/php ${cfg.root}/www/update.php --update-schema
|
||||
'';
|
||||
|
||||
serviceConfig = {
|
||||
User = "${cfg.user}";
|
||||
|
Loading…
Reference in New Issue
Block a user