File size: 1,456 Bytes
beb354f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env node
/**
 * Quick SQL Executor for Supabase Migrations
 *
 * This script reads SQL migration files and outputs them for manual execution
 * in the Supabase SQL Editor, or can be used with a Supabase connection.
 *
 * Usage:
 *   node scripts/quick-sql.js < migration_file.sql
 *   node scripts/quick-sql.js migration_file.sql migration_file2.sql
 */

const fs = require('fs');
const path = require('path');

const migrations = process.argv.slice(2);

if (migrations.length === 0) {
  console.log('Usage: node scripts/quick-sql.js <migration1.sql> [migration2.sql ...]');
  console.log('\nOr pipe SQL directly:');
  console.log('  cat migrations/027_at_risk_stricter_thresholds.sql | node scripts/quick-sql.js');
  process.exit(1);
}

let allSql = '';

for (const migrationFile of migrations) {
  const filePath = path.join(__dirname, '..', 'migrations', migrationFile);

  if (!fs.existsSync(filePath)) {
    console.error(`Error: File not found: ${filePath}`);
    process.exit(1);
  }

  const sql = fs.readFileSync(filePath, 'utf8');
  allSql += `-- ============================================\n`;
  allSql += `-- Migration: ${migrationFile}\n`;
  allSql += `-- ============================================\n\n`;
  allSql += sql + '\n\n';
}

console.log('=== SQL OUTPUT FOR SUPABASE ===\n');
console.log('Copy and paste the following SQL into your Supabase SQL Editor:\n');
console.log('```sql');
console.log(allSql);
console.log('```');