Skip to content

Commit a12a3b3

Browse files
committed
fix(postgres): run postgres on update again after clearing
1 parent 9b2f2c3 commit a12a3b3

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

infrastructure/clear-all-data.sh

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ POSTGRES_DB="${STACK}__events"
154154
EVENTS_MIGRATOR_ROLE="${STACK}__events_migrator"
155155
EVENTS_APP_ROLE="${STACK}__events_app"
156156

157-
echo "Resetting roles and owned data in '${POSTGRES_DB}'..."
157+
echo "🔁 Dropping database '${POSTGRES_DB}' and roles..."
158158

159159
docker run --rm --network=dependencies_postgres_net \
160160
-e PGPASSWORD="${POSTGRES_PASSWORD}" \
@@ -163,15 +163,17 @@ docker run --rm --network=dependencies_postgres_net \
163163
-e EVENTS_MIGRATOR_ROLE="${EVENTS_MIGRATOR_ROLE}" \
164164
-e EVENTS_APP_ROLE="${EVENTS_APP_ROLE}" \
165165
postgres:17 bash -c '
166-
# Drop all objects and privileges owned by the roles
167-
psql -h postgres -U "$POSTGRES_USER" -d "$POSTGRES_DB" -v ON_ERROR_STOP=1 <<EOF
168-
-- prevents the schema itself from being dropped
169-
ALTER SCHEMA app OWNER TO "$POSTGRES_USER";
170-
171-
DROP OWNED BY "$EVENTS_MIGRATOR_ROLE" CASCADE;
172-
DROP OWNED BY "$EVENTS_APP_ROLE" CASCADE;
173-
ALTER SCHEMA app OWNER TO "$EVENTS_MIGRATOR_ROLE";
166+
psql -h postgres -U "$POSTGRES_USER" -d postgres -v ON_ERROR_STOP=1 <<EOF
167+
SELECT pg_terminate_backend(pid)
168+
FROM pg_stat_activity
169+
WHERE datname = '\''"$POSTGRES_DB"'\'' AND pid <> pg_backend_pid();
170+
171+
DROP DATABASE IF EXISTS "$POSTGRES_DB";
172+
173+
DROP ROLE IF EXISTS "$EVENTS_MIGRATOR_ROLE";
174+
DROP ROLE IF EXISTS "$EVENTS_APP_ROLE";
174175
EOF
175176
'
176-
177-
echo "Roles and their data dropped from '${POSTGRES_DB}'."
177+
echo "✅ Database and roles dropped."
178+
echo "🚀 Reinitializing with on-deploy.sh..."
179+
docker service update --force --update-parallelism 1 "${STACK}_postgres-on-update"

0 commit comments

Comments
 (0)