@@ -154,7 +154,7 @@ POSTGRES_DB="${STACK}__events"
154154EVENTS_MIGRATOR_ROLE=" ${STACK} __events_migrator"
155155EVENTS_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
159159docker run --rm --network=dependencies_postgres_net \
160160 -e PGPASSWORD=" ${POSTGRES_PASSWORD} " \
@@ -163,15 +163,20 @@ 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";
174175EOF
175176'
177+ echo " ✅ Database and roles dropped."
178+ echo " 🚀 Reinitializing with on-deploy.sh..."
179+
180+ sleep 30s
176181
177- echo " Roles and their data dropped from ' ${POSTGRES_DB} '. "
182+ docker service update --force --update-parallelism 1 " ${STACK} _postgres-on-update "
0 commit comments