#!/bin/bash
# Script to rename status column to propertyStatus in PostgreSQL

echo "Renaming status column to propertyStatus..."

psql -U postgres -d nre <<EOF
-- Rename the column
ALTER TABLE properties RENAME COLUMN status TO "propertyStatus";

-- Update any invalid values
UPDATE properties 
SET "propertyStatus" = 'upcoming' 
WHERE "propertyStatus" NOT IN ('upcoming', 'ongoing', 'completed') 
   OR "propertyStatus" IS NULL;

-- Verify the changes
SELECT id, title, "propertyStatus" FROM properties LIMIT 5;

EOF

echo "Done! Column renamed successfully."

