Skip to content

Commit

Permalink
mysql service: Make initialDatabases.schema attribute optional
Browse files Browse the repository at this point in the history
(cherry picked from commit d22c1c0)
  • Loading branch information
florianjacob authored and fpletz committed Aug 31, 2017
1 parent e22826a commit 8cb6bfe
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions nixos/modules/services/databases/mysql.nix
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,13 @@ in

initialDatabases = mkOption {
default = [];
description = "List of database names and their initial schemas that should be used to create databases on the first startup of MySQL";
description = ''
List of database names and their initial schemas that should be used to create databases on the first startup
of MySQL. The schema attribute is optional: If not specified, an empty database is created.
'';
example = [
{ name = "foodatabase"; schema = literalExample "./foodatabase.sql"; }
{ name = "bardatabase"; schema = literalExample "./bardatabase.sql"; }
{ name = "bardatabase"; }
];
};

Expand Down Expand Up @@ -247,6 +250,8 @@ in
if ! test -e "${cfg.dataDir}/${database.name}"; then
echo "Creating initial database: ${database.name}"
( echo "create database ${database.name};"
${optionalString (database ? "schema") ''
echo "use ${database.name};"
if [ -f "${database.schema}" ]
Expand All @@ -256,6 +261,7 @@ in
then
cat ${database.schema}/mysql-databases/*.sql
fi
''}
) | ${mysql}/bin/mysql -u root -N
fi
'') cfg.initialDatabases}
Expand Down

0 comments on commit 8cb6bfe

Please sign in to comment.