#!/usr/bin/env node /** * Migration: add last_completed_step column to turnitin_jobs * Run: node migrate-last-completed-step.js */ const { createClient } = require('@supabase/supabase-js'); const SUPABASE_URL = 'https://zbvlvxpnmsccdmoihnpo.supabase.co'; const SUPABASE_SERVICE_KEY = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Inpidmx2eHBubXNjY2Rtb2lobnBvIiwicm9sZSI6InNlcnZpY2Vfcm9sZSIsImlhdCI6MTc4MjkxMjAwNSwiZXhwIjoyMDk4NDg4MDA1fQ.i6SfiVKB0YX4pi88OhQZyX8uCMREQcaOwdsB9CmGI1Q'; async function main() { const supabase = createClient(SUPABASE_URL, SUPABASE_SERVICE_KEY); console.log('Running migration: add last_completed_step to turnitin_jobs...'); // Supabase JS client doesn't support raw DDL. Use the pg extension workaround // by checking if the column already exists first. const { data: columns, error: checkError } = await supabase .from('information_schema.columns') .select('column_name') .eq('table_schema', 'public') .eq('table_name', 'turnitin_jobs') .eq('column_name', 'last_completed_step'); if (checkError) { console.log('Could not check column existence via information_schema (RLS?):', checkError.message); } if (columns && columns.length > 0) { console.log('✅ Column last_completed_step already exists — no migration needed.'); return; } // Try applying via the run_sql RPC if it exists const { error } = await supabase.rpc('run_sql', { sql: 'ALTER TABLE public.turnitin_jobs ADD COLUMN IF NOT EXISTS last_completed_step text;' }); if (error) { console.log('❌ run_sql RPC not available:', error.message); console.log(''); console.log('Please run this SQL manually in the Supabase Dashboard SQL editor:'); console.log(''); console.log(' ALTER TABLE public.turnitin_jobs ADD COLUMN IF NOT EXISTS last_completed_step text;'); console.log(''); console.log('URL: https://supabase.com/dashboard/project/zbvlvxpnmsccdmoihnpo/sql/new'); process.exit(1); } console.log('✅ Migration applied successfully.'); } main().catch((e) => { console.error('Fatal error:', e); process.exit(1); });