File size: 2,148 Bytes
521a9b6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/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);
});