mirror of
https://github.com/hatchet-dev/hatchet.git
synced 2026-01-06 00:40:10 -06:00
* wip * wip: functional query * feat: expose affinity config * feat: add weight to proto * feat: upsert affinity state on worker start * fix: linting * feat: add upsert proto * feat: upsert handler * feat: revise model * fix: labels * feat: functional desired worker * wip: ui * feat: add state to step run events * fix: filter empty keys * fix: labels as badges * feat: empty state and descriptive text * chore: add todo * chore: whitespace * chore: cleanup * chore: cleanup * chore: fix hash * chore: squash migrations * fix: fair worker assignment * fix: remaining slots on valid desired workers * wip: sticky * fix: count slots * chore: rm log line * feat: expose sticky config * wip: sticky dag * feat: expose desired worker id to trigger * feat: trigger on desired worker * feat: typescript docs * feat: sticky python * feat: py sticky children * wip: py affinity * serverless note * feat: complete python examples * linting * feat: deduplicated enqueue * fix: address changes from PR review * chore: generate --------- Co-authored-by: gabriel ruttner <gabriel.ruttner@gmail.com>
70 lines
1.9 KiB
Bash
70 lines
1.9 KiB
Bash
#!/bin/bash
|
|
|
|
# Check whether DATABASE_URL is set
|
|
if [ -z "$DATABASE_URL" ]; then
|
|
echo "DATABASE_URL is not set"
|
|
exit 1
|
|
fi
|
|
|
|
# Wait up to 30 seconds for the database to be ready
|
|
echo "Waiting for database to be ready..."
|
|
timeout 30s bash -c '
|
|
until psql "$DATABASE_URL" -c "\q" 2>/dev/null; do
|
|
sleep 1
|
|
done
|
|
'
|
|
if [ $? -eq 124 ]; then
|
|
echo "Timed out waiting for the database to be ready"
|
|
exit 1
|
|
fi
|
|
|
|
# Function to attempt a psql connection with the given DATABASE_URL
|
|
attempt_psql_connection() {
|
|
local db_url=$1
|
|
psql "$db_url" -t -c "SELECT 1;" 2>/dev/null
|
|
return $?
|
|
}
|
|
|
|
# Check if sslmode is set in the DATABASE_URL
|
|
if [[ ! "$DATABASE_URL" =~ sslmode ]]; then
|
|
# Attempt a secure psql connection first if sslmode is not set
|
|
SECURE_DB_URL="${DATABASE_URL}?sslmode=require"
|
|
attempt_psql_connection "$SECURE_DB_URL"
|
|
if [ $? -ne 0 ]; then
|
|
# If secure connection fails, use sslmode=disable
|
|
echo "Secure connection failed. Using sslmode=disable"
|
|
|
|
DATABASE_URL="${DATABASE_URL}?sslmode=disable"
|
|
else
|
|
DATABASE_URL="$SECURE_DB_URL"
|
|
fi
|
|
fi
|
|
|
|
echo "DATABASE_URL: $DATABASE_URL"
|
|
# Check for prisma migrations
|
|
MIGRATION_NAME=$(psql "$DATABASE_URL" -t -c "SELECT migration_name FROM _prisma_migrations ORDER BY started_at DESC LIMIT 1;" 2>/dev/null | xargs)
|
|
MIGRATION_NAME=$(echo $MIGRATION_NAME | cut -d'_' -f1)
|
|
|
|
echo "Migration name: $MIGRATION_NAME"
|
|
|
|
if [ $? -eq 0 ] && [ -n "$MIGRATION_NAME" ]; then
|
|
echo "Using existing prisma migration: $MIGRATION_NAME"
|
|
|
|
atlas migrate apply \
|
|
--url "$DATABASE_URL" \
|
|
--baseline "$MIGRATION_NAME" \
|
|
--dir "file://sql/migrations"
|
|
else
|
|
echo "No prisma migration found. Applying migrations via atlas..."
|
|
|
|
atlas migrate apply \
|
|
--url "$DATABASE_URL" \
|
|
--dir "file://sql/migrations"
|
|
fi
|
|
|
|
# if either of the above commands failed, exit with an error
|
|
if [ $? -ne 0 ]; then
|
|
echo "Migration failed. Exiting..."
|
|
exit 1
|
|
fi
|