Skip to content

Commit

Permalink
Reset db
Browse files Browse the repository at this point in the history
  • Loading branch information
JargeZ committed Oct 25, 2024
1 parent b6eb54e commit bf750d8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ inputs:
remote_only:
description: Add --remote-only flag to flyctl deploy command to use remote build. Improve build speed (default false)
default: false
reset_db:
description: Reset the database on each deploy (default false)
default: false
build_args:
description: Optional Docker --build-arg
build_secrets:
Expand Down
19 changes: 13 additions & 6 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,21 @@ if ! echo "$app" | grep "$PR_NUMBER"; then
echo "WARNING: The app's name does not contain the PR number. it is recommended to include the PR number in the app's name."
fi

# PR was closed - remove the Fly app if one exists and exit.
if [ "$EVENT_TYPE" = "closed" ]; then
flyctl apps destroy "$app" -y || true

if [ "$INPUT_POSTGRES_CLEAN_ON_CLOSE" == "true" && -n "$INPUT_POSTGRES" ]; then
function reset_db() {
flyctl postgres connect --app "$INPUT_POSTGRES" <<EOF || true
drop database ${database_name} with (force );
drop role ${database_role};
\q
EOF
fi
}

# PR was closed - remove the Fly app if one exists and exit.
if [ "$EVENT_TYPE" = "closed" ]; then
flyctl apps destroy "$app" -y || true

if [ "$INPUT_POSTGRES_CLEAN_ON_CLOSE" == "true" && -n "$INPUT_POSTGRES" ]; then
reset_db
fi
exit 0
fi

Expand Down Expand Up @@ -131,6 +134,10 @@ if [ -n "$INPUT_POSTGRES" ]; then
flyctl postgres attach "$INPUT_POSTGRES" --app "$app" --database-name "$database_name" --database-user "$database_role" || true
fi

if [ -n "$INPUT_RESET_DB" ] && [ -n "$INPUT_POSTGRES" ]; then
reset_db
fi

# Use remote builders
if [ -n "$INPUT_REMOTE_ONLY" ]; then
remote_only="--remote-only"
Expand Down

0 comments on commit bf750d8

Please sign in to comment.