@@ -213,8 +213,9 @@ setup_project() {
213213 export PGPASSWORD=" $SUPABASE_DB_PASSWORD "
214214
215215 # Run the link command directly - no retries to avoid confusion
216- echo -e " ${YELLOW} Running: supabase link --project-ref \" $PROJECT_REF \" --password \" $SUPABASE_DB_PASSWORD \" --debug${NC} "
217- supabase link --project-ref " $PROJECT_REF " --password " $SUPABASE_DB_PASSWORD " --debug
216+ # Add GODEBUG=netdns=4 to force IPv4 DNS resolution
217+ echo -e " ${YELLOW} Running: GODEBUG=netdns=4 supabase link --project-ref \" $PROJECT_REF \" --password \" $SUPABASE_DB_PASSWORD \" --debug${NC} "
218+ GODEBUG=netdns=4 supabase link --project-ref " $PROJECT_REF " --password " $SUPABASE_DB_PASSWORD " --debug
218219
219220 if [ $? -eq 0 ]; then
220221 echo -e " ${GREEN} Link successful!${NC} "
@@ -276,7 +277,18 @@ run_migrations() {
276277 fi
277278
278279 # Set up the database URL for direct cloud connection
279- DB_URL=" postgresql://postgres:${SUPABASE_DB_PASSWORD} @db.${PROJECT_REF} .supabase.co:5432/postgres"
280+ # Force IPv4 by resolving the hostname to an IPv4 address
281+ echo -e " ${YELLOW} Resolving db.${PROJECT_REF} .supabase.co to IPv4 address...${NC} "
282+ DB_HOST=$( getent ahostsv4 db.${PROJECT_REF} .supabase.co | head -n 1 | awk ' {print $1}' )
283+
284+ if [ -z " $DB_HOST " ]; then
285+ echo -e " ${YELLOW} Failed to resolve IPv4 address, using hostname...${NC} "
286+ DB_HOST=" db.${PROJECT_REF} .supabase.co"
287+ else
288+ echo -e " ${YELLOW} Using IPv4 address: $DB_HOST ${NC} "
289+ fi
290+
291+ DB_URL=" postgresql://postgres:${SUPABASE_DB_PASSWORD} @$DB_HOST :5432/postgres"
280292 echo -e " ${YELLOW} Using cloud database URL for migrations...${NC} "
281293
282294 # Run the migration command directly with the cloud database URL
@@ -286,8 +298,9 @@ run_migrations() {
286298 export PGPASSWORD=" $SUPABASE_DB_PASSWORD "
287299
288300 # Run the command with the cloud database URL - no retries to avoid confusion
289- echo -e " ${YELLOW} Running: supabase db push --db-url <DB_URL> --debug${NC} "
290- supabase db push --db-url " $DB_URL " --debug
301+ # Add GODEBUG=netdns=4 to force IPv4 DNS resolution
302+ echo -e " ${YELLOW} Running: GODEBUG=netdns=4 supabase db push --db-url <DB_URL> --debug${NC} "
303+ GODEBUG=netdns=4 supabase db push --db-url " $DB_URL " --debug
291304
292305 if [ $? -eq 0 ]; then
293306 echo -e " ${GREEN} Migration successful!${NC} "
0 commit comments