Skip to content

Commit 4a82f1e

Browse files
refactor(nix,postgres): update initial database setup to use structured configuration to improving readability and maintainability
Refactor the initial database setup to utilize a more structured approach with an array of initialDatabases, improving readability and maintainability.
1 parent a87bccc commit 4a82f1e

1 file changed

Lines changed: 8 additions & 7 deletions

File tree

nix/module.nix

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -237,13 +237,14 @@ in
237237
inherit (cfg.postgres) port;
238238
};
239239

240-
initialScript = pkgs.writeText "teslamate-psql-init" ''
241-
\set password `echo $DATABASE_PASS`
242-
CREATE DATABASE ${cfg.postgres.database};
243-
CREATE USER ${cfg.postgres.user} with encrypted password :'password';
244-
GRANT ALL PRIVILEGES ON DATABASE ${cfg.postgres.database} TO ${cfg.postgres.user};
245-
ALTER USER ${cfg.postgres.user} WITH SUPERUSER;
246-
'';
240+
initialDatabases = [{
241+
name = cfg.postgres.database;
242+
user = cfg.postgres.user;
243+
pass = "\${DATABASE_PASS}";
244+
initialSQL = lib.literalExpression ''
245+
ALTER USER ${cfg.postgres.user} WITH SUPERUSER;
246+
'';
247+
}];
247248
};
248249

249250
# Include secrets in postgres as well

0 commit comments

Comments
 (0)