Skip to content

Commit eb3cee7

Browse files
committed
wait for pg to be ready before running db setup; create schemas if they dont exist
1 parent eac5a7c commit eb3cee7

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

docker/dev/docker-start

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,17 @@ rm -f /tmp/.s.PGSQL.*
1010
rm -f /var/log/api-umbrella/trafficserver/error.log
1111

1212
make
13+
14+
# Wait for PostgreSQL to be ready before running database setup.
15+
echo "Waiting for PostgreSQL to be ready..."
16+
until PGPASSWORD=dev_password psql -h postgres -U postgres -c '\q' 2>/dev/null; do
17+
echo "PostgreSQL is unavailable - sleeping"
18+
sleep 1
19+
done
20+
echo "PostgreSQL is ready"
21+
22+
# Run database setup as postgres superuser to create the database and roles.
23+
# This is idempotent and safe to run on every startup.
24+
DB_USERNAME=postgres DB_PASSWORD=dev_password api-umbrella db-setup
25+
1326
api-umbrella run

src/api-umbrella/cli/migrate.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ return function()
6363
local removing_comments = true
6464
for _, line in ipairs(lines) do
6565
if not removing_comments or (line ~= "" and not startswith(line, "--")) then
66+
if startswith(line, "CREATE SCHEMA") then
67+
line = line:gsub("^CREATE SCHEMA", "CREATE SCHEMA IF NOT EXISTS")
68+
end
6669
if startswith(line, "COMMENT ON EXTENSION") then
6770
line = "-- " .. line
6871
end

0 commit comments

Comments
 (0)