nixos-postgresql/database-setup.nu
2023-08-10 15:34:31 -05:00

27 lines
664 B
Text

def main [
user_config: string
database_config: string
] {
alias psql = ^psql --tuples-only --no-align
if not ($user_config | path exists) {
print $"($user_config) does not exist!"
exit 1
}
if not ($database_config | path exists) {
print $"($database_config) does not exist!"
exit 1
}
let users = ($user_config | open)
let databases = ($database_config | open)
$users | debug
$databases | debug
$users | each {
|user|
let exists = ("SELECT 1 FROM pg_roles WHERE rolname=:'username';" | psql --variable username=$"($user.username)")
$exists | debug
}
}