Spaces:
Sleeping
Sleeping
| /** | |
| * 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('```'); |