Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

fix: update reset.sh script for self-hosted supabase (#41361)

Andrey A.20f6e661a4d2
diff --git a/docker/reset.sh b/docker/reset.sh
index d5f3a41dae0..af0302a8227 100755
--- a/docker/reset.sh
+++ b/docker/reset.sh
@@ -1,44 +1,76 @@
-#!/bin/bash
-
-echo "WARNING: This will remove all containers and container data, and will reset the .env file. This action cannot be undone!"
-read -p "Are you sure you want to proceed? (y/N) " -n 1 -r
-echo # Move to a new line
-if [[ ! $REPLY =~ ^[Yy]$ ]]
-then
- echo "Operation cancelled."
- exit 1
+#!/bin/sh
+
+set -e
+
+auto_confirm=0
+
+confirm () {
+ if [ "$auto_confirm" = "1" ]; then
+ return 0
+ fi
+
+ printf "Are you sure you want to proceed? (y/N) "
+ read -r REPLY
+ case "$REPLY" in
+ [Yy])
+ ;;
+ *)
+ echo "Script canceled."
+ exit 1
+ ;;
+ esac
+}
+
+if [ "$1" = "-y" ]; then
+ auto_confirm=1
fi
-echo "Stopping and removing all containers..."
-docker compose -f docker-compose.yml -f ./dev/docker-compose.dev.yml down -v --remove-orphans
-
-echo "Cleaning up bind-mounted directories..."
-BIND_MOUNTS=(
- "./volumes/db/data"
-)
-
-for DIR in "${BIND_MOUNTS[@]}"; do
- if [ -d "$DIR" ]; then
- echo "Deleting $DIR..."
- rm -rf "$DIR"
- else
- echo "Directory $DIR does not exist. Skipping bind mount deletion step..."
- fi
-done
+echo ""
+echo "*** WARNING: This will remove all containers and container data, and optionally reset .env ***"
+echo ""
+
+confirm
+
+echo "===> Stopping and removing all containers..."
-echo "Resetting .env file..."
if [ -f ".env" ]; then
- echo "Removing existing .env file..."
- rm -f .env
+ docker compose -f docker-compose.yml -f ./dev/docker-compose.dev.yml down -v --remove-orphans
+elif [ -f ".env.example" ]; then
+ echo "No .env found, using .env.example for docker compose down..."
+ docker compose --env-file .env.example -f docker-compose.yml -f ./dev/docker-compose.dev.yml down -v --remove-orphans
+else
+ echo "Skipping 'docker compose down' because there's no env-file."
+fi
+
+echo "===> Cleaning up bind-mounted directories..."
+BIND_MOUNTS="./volumes/db/data ./volumes/storage"
+
+for dir in $BIND_MOUNTS; do
+ if [ -d "$dir" ]; then
+ echo "Removing $dir..."
+ confirm
+ rm -rf "$dir"
+ else
+ echo "$dir not found."
+ fi
+done
+
+echo "===> Resetting .env file (will save backup to .env.old)..."
+confirm
+if [ -f ".env" ] || [ -L ".env" ]; then
+ echo "Renaming existing .env file to .env.old"
+ mv .env .env.old
else
- echo "No .env file found. Skipping .env removal step..."
+ echo "No .env file found."
fi
if [ -f ".env.example" ]; then
- echo "Copying .env.example to .env..."
- cp .env.example .env
+ echo "===> Copying .env.example to .env"
+ cp .env.example .env
else
- echo ".env.example file not found. Skipping .env reset step..."
+ echo "No .env.example found, can't restore .env to default values."
fi
-echo "Cleanup complete!"
\ No newline at end of file
+echo "Cleanup complete!"
+echo "Re-run 'docker compose pull' to update images."
+echo ""