@@ -185,32 +185,8 @@ setup_project() {
185185
186186 echo -e " ${YELLOW} Project reference: ${PROJECT_REF}${NC} "
187187
188- # Test database connection
189- echo -e " ${YELLOW} Testing database connection...${NC} "
190-
191- # Create a temporary .pgpass file for the test
192- PGPASS_FILE=" $HOME /.pgpass"
193- HOST_PATTERN=" db.${PROJECT_REF} .supabase.co"
194-
195- # Create .pgpass file with both possible usernames
196- echo " ${HOST_PATTERN} :5432:postgres:postgres:${SUPABASE_DB_PASSWORD} " > " $PGPASS_FILE "
197- echo " ${HOST_PATTERN} :5432:postgres:postgres.${PROJECT_REF} :${SUPABASE_DB_PASSWORD} " >> " $PGPASS_FILE "
198- chmod 600 " $PGPASS_FILE "
199-
200- # Check if psql is installed
201- if command -v psql & > /dev/null; then
202- # Try connection with postgres.{project_ref} user
203- if psql -h " db.${PROJECT_REF} .supabase.co" -p 5432 -d postgres -U " postgres.${PROJECT_REF} " -c " SELECT 1" > /dev/null 2>&1 ; then
204- echo -e " ${GREEN} Database connection successful with postgres.${PROJECT_REF} user!${NC} "
205- # Try connection with postgres user
206- elif psql -h " db.${PROJECT_REF} .supabase.co" -p 5432 -d postgres -U postgres -c " SELECT 1" > /dev/null 2>&1 ; then
207- echo -e " ${GREEN} Database connection successful with postgres user!${NC} "
208- else
209- echo -e " ${YELLOW} Could not connect to database directly with psql. Continuing with Supabase CLI...${NC} "
210- fi
211- else
212- echo -e " ${YELLOW} psql not installed, skipping direct connection test...${NC} "
213- fi
188+ # Skip direct database connection test and proceed with Supabase CLI
189+ echo -e " ${YELLOW} Using Supabase CLI for database operations...${NC} "
214190
215191 # Initialize Supabase project if not already initialized
216192 if [ ! -d " supabase" ]; then
@@ -224,19 +200,8 @@ setup_project() {
224200 echo -e " ${YELLOW} Linking to Supabase cloud project...${NC} "
225201 echo " Using database password: ${SUPABASE_DB_PASSWORD: 0: 3} *****"
226202
227- # Create a temporary .pgpass file to avoid password prompt
228- echo " Creating temporary .pgpass file..."
229- PGPASS_FILE=" $HOME /.pgpass"
230-
231- # Extract project reference from URL for the hostname pattern
232- HOST_PATTERN=" db.${PROJECT_REF} .supabase.co"
233-
234- # Create or append to .pgpass file
235- echo " ${HOST_PATTERN} :5432:postgres:postgres:${SUPABASE_DB_PASSWORD} " > " $PGPASS_FILE "
236- echo " ${HOST_PATTERN} :5432:postgres:postgres.${PROJECT_REF} :${SUPABASE_DB_PASSWORD} " >> " $PGPASS_FILE "
237-
238- # Set proper permissions
239- chmod 600 " $PGPASS_FILE "
203+ # Set environment variables for Supabase CLI
204+ export SUPABASE_DB_PASSWORD=" $SUPABASE_DB_PASSWORD "
240205
241206 # Run the command with retry logic
242207 echo " Running supabase link with retry logic..."
@@ -255,7 +220,11 @@ setup_project() {
255220 fi
256221
257222 # Run the command with timeout to prevent hanging
258- timeout 60 supabase link --project-ref " $PROJECT_REF " --password " $SUPABASE_DB_PASSWORD " --debug
223+ # Set up PGPASSWORD environment variable
224+ export PGPASSWORD=" $SUPABASE_DB_PASSWORD "
225+
226+ # Run the command without --password flag
227+ timeout 60 supabase link --project-ref " $PROJECT_REF " --debug
259228
260229 if [ $? -eq 0 ]; then
261230 SUCCESS=true
@@ -295,19 +264,8 @@ run_migrations() {
295264 echo -e " ${YELLOW} Applying migrations to database...${NC} "
296265 echo " Using database password: ${SUPABASE_DB_PASSWORD: 0: 3} *****"
297266
298- # Create a temporary .pgpass file to avoid password prompt
299- echo " Creating temporary .pgpass file..."
300- PGPASS_FILE=" $HOME /.pgpass"
301-
302- # Extract project reference from URL for the hostname pattern
303- HOST_PATTERN=" db.${PROJECT_REF} .supabase.co"
304-
305- # Create or append to .pgpass file
306- echo " ${HOST_PATTERN} :5432:postgres:postgres:${SUPABASE_DB_PASSWORD} " > " $PGPASS_FILE "
307- echo " ${HOST_PATTERN} :5432:postgres:postgres.${PROJECT_REF} :${SUPABASE_DB_PASSWORD} " >> " $PGPASS_FILE "
308-
309- # Set proper permissions
310- chmod 600 " $PGPASS_FILE "
267+ # Set environment variables for Supabase CLI
268+ export SUPABASE_DB_PASSWORD=" $SUPABASE_DB_PASSWORD "
311269
312270 # Run the command with retry logic
313271 echo " Running supabase migration up with retry logic..."
@@ -326,7 +284,11 @@ run_migrations() {
326284 fi
327285
328286 # Run the command with timeout to prevent hanging
329- timeout 60 supabase migration up --password " $SUPABASE_DB_PASSWORD " --debug
287+ # Set up PGPASSWORD environment variable
288+ export PGPASSWORD=" $SUPABASE_DB_PASSWORD "
289+
290+ # Run the command without --password flag
291+ timeout 60 supabase migration up --debug
330292
331293 if [ $? -eq 0 ]; then
332294 SUCCESS=true
@@ -343,9 +305,6 @@ run_migrations() {
343305 exit 1
344306 fi
345307
346- # Remove the temporary .pgpass file
347- rm -f " $PGPASS_FILE "
348-
349308 echo -e " ${GREEN} Migrations applied successfully!${NC} "
350309}
351310
0 commit comments