dumb command arg order issue

This commit is contained in:
2025-12-26 12:40:18 -06:00
parent 1db236d965
commit d86498eac4
+12 -12
View File
@@ -120,42 +120,42 @@
echo "Bootstrapping PostgreSQL for database: $db"
# Create databases if not exists
if $psql_bin -c --port=${toString opts.port} "\l" | grep -ci ""$db" "; then
if $psql_bin --port=${toString opts.port} -c "\l" | grep -ci ""$db" "; then
echo "$db already exists, skipping creation."
else
echo "Creating database $db"
$psql_bin -c --port=${toString opts.port} "CREATE DATABASE "$db";"
$psql_bin --port=${toString opts.port} -c "CREATE DATABASE "$db";"
fi
if $psql_bin -c --port=${toString opts.port} "\l" | grep -ci "$db"_dev; then
if $psql_bin --port=${toString opts.port} -c "\l" | grep -ci "$db"_dev; then
echo ""$db"_dev already exists, skipping creation."
else
echo "Creating database "$db"_dev"
$psql_bin -c --port=${toString opts.port} "CREATE DATABASE "$db"_dev;"
$psql_bin --port=${toString opts.port} -c "CREATE DATABASE "$db"_dev;"
fi
# Create users if not exists
if $psql_bin -c --port=${toString opts.port} "\du" | grep -ci "$user_val"; then
if $psql_bin --port=${toString opts.port} -c "\du" | grep -ci "$user_val"; then
echo "$user_val already exists, skipping creation. WARN: password may not be correct. Delete user and allow to be recreated for assurity"
else
echo "Creating $user_val"
$psql_bin -c --port=${toString opts.port} "CREATE ROLE "$user_val" WITH LOGIN PASSWORD '$pass_val';"
$psql_bin --port=${toString opts.port} -c "CREATE ROLE "$user_val" WITH LOGIN PASSWORD '$pass_val';"
fi
if $psql_bin -c --port=${toString opts.port} "\du" | grep -ci "$dev_user_val"; then
if $psql_bin --port=${toString opts.port} -c "\du" | grep -ci "$dev_user_val"; then
echo "$dev_user_val already exists, skipping creation. WARN: password may not be correct. Delete user and allow to be recreated for assurity"
else
echo "Creating $dev_user_val"
$psql_bin -c --port=${toString opts.port} "CREATE ROLE "$dev_user_val" WITH LOGIN PASSWORD '$dev_pass_val';"
$psql_bin --port=${toString opts.port} -c "CREATE ROLE "$dev_user_val" WITH LOGIN PASSWORD '$dev_pass_val';"
fi
# Give users privileges on databases (always)
$psql_bin -c --port=${toString opts.port} "GRANT ALL PRIVILEGES ON DATABASE "$db" TO "$user_val";"
$psql_bin -c --port=${toString opts.port} "GRANT ALL PRIVILEGES ON DATABASE "$db"_dev TO "$dev_user_val";"
$psql_bin --port=${toString opts.port} -c "GRANT ALL PRIVILEGES ON DATABASE "$db" TO "$user_val";"
$psql_bin --port=${toString opts.port} -c "GRANT ALL PRIVILEGES ON DATABASE "$db"_dev TO "$dev_user_val";"
# Grant ownership
$psql_bin -c --port=${toString opts.port} "ALTER DATABASE "$db" OWNER TO "$user_val";"
$psql_bin -c --port=${toString opts.port} "ALTER DATABASE "$db"_dev OWNER TO "$dev_user_val";"
$psql_bin --port=${toString opts.port} -c "ALTER DATABASE "$db" OWNER TO "$user_val";"
$psql_bin --port=${toString opts.port} -c "ALTER DATABASE "$db"_dev OWNER TO "$dev_user_val";"
done
'';