mysql service: Make initialDatabases.schema attribute optional
This commit is contained in:
parent
a2bb174c63
commit
d22c1c0719
@ -108,10 +108,13 @@ in
|
|||||||
|
|
||||||
initialDatabases = mkOption {
|
initialDatabases = mkOption {
|
||||||
default = [];
|
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 = [
|
example = [
|
||||||
{ name = "foodatabase"; schema = literalExample "./foodatabase.sql"; }
|
{ name = "foodatabase"; schema = literalExample "./foodatabase.sql"; }
|
||||||
{ name = "bardatabase"; schema = literalExample "./bardatabase.sql"; }
|
{ name = "bardatabase"; }
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -247,6 +250,8 @@ in
|
|||||||
if ! test -e "${cfg.dataDir}/${database.name}"; then
|
if ! test -e "${cfg.dataDir}/${database.name}"; then
|
||||||
echo "Creating initial database: ${database.name}"
|
echo "Creating initial database: ${database.name}"
|
||||||
( echo "create database ${database.name};"
|
( echo "create database ${database.name};"
|
||||||
|
|
||||||
|
${optionalString (database ? "schema") ''
|
||||||
echo "use ${database.name};"
|
echo "use ${database.name};"
|
||||||
|
|
||||||
if [ -f "${database.schema}" ]
|
if [ -f "${database.schema}" ]
|
||||||
@ -256,6 +261,7 @@ in
|
|||||||
then
|
then
|
||||||
cat ${database.schema}/mysql-databases/*.sql
|
cat ${database.schema}/mysql-databases/*.sql
|
||||||
fi
|
fi
|
||||||
|
''}
|
||||||
) | ${mysql}/bin/mysql -u root -N
|
) | ${mysql}/bin/mysql -u root -N
|
||||||
fi
|
fi
|
||||||
'') cfg.initialDatabases}
|
'') cfg.initialDatabases}
|
||||||
|
Loading…
Reference in New Issue
Block a user