#!/usr/bin/env node /** * Script to verify the rate_limits table exists in Supabase */ const { createClient } = require('@supabase/supabase-js'); const fs = require('fs'); const path = require('path'); // Load .env.local manually const envPath = path.join(__dirname, '..', '.env.local'); if (fs.existsSync(envPath)) { const envContent = fs.readFileSync(envPath, 'utf8'); envContent.split('\n').forEach(line => { const trimmed = line.trim(); const match = trimmed.match(/^([^=:#]+)=(.*)$/); if (match) { const key = match[1].trim(); const value = match[2].trim(); if (!process.env[key]) { process.env[key] = value; } } }); } async function verifyMigration() { const supabaseUrl = process.env.NEXT_PUBLIC_SUPABASE_URL; const supabaseAnonKey = process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY; if (!supabaseUrl || !supabaseAnonKey) { console.error('❌ Error: Missing Supabase credentials in .env.local'); process.exit(1); } console.log('🔍 Verifying rate_limits table in Supabase...\n'); const supabase = createClient(supabaseUrl, supabaseAnonKey); try { // Try to query the rate_limits table const { data, error } = await supabase .from('rate_limits') .select('*') .limit(1); if (error) { if (error.code === '42P01') { console.error('❌ Table "rate_limits" does not exist yet.\n'); console.error('📝 Please apply the migration manually:'); console.error(' 1. Go to https://app.supabase.com/project/mxadgucxhmstlzsbgmoz/sql'); console.error(' 2. Copy the contents of supabase/migrations/20260125_create_rate_limits_table.sql'); console.error(' 3. Paste into the SQL editor and click "Run"'); console.error(' 4. Run this script again to verify\n'); process.exit(1); } else if (error.code === 'PGRST301' || error.message.includes('JWT')) { console.error('❌ Authentication error. Table may exist but is not accessible with anon key.\n'); console.error('📝 Please verify manually:'); console.error(' 1. Go to https://app.supabase.com/project/mxadgucxhmstlzsbgmoz/editor'); console.error(' 2. Check if "rate_limits" table appears in the table list\n'); process.exit(1); } else { throw error; } } console.log('✅ Table "rate_limits" exists and is accessible!'); console.log(`📊 Current records: ${data ? data.length : 0}\n`); // Try to get table schema info console.log('🔍 Verifying table schema...'); const { data: schemaData, error: schemaError } = await supabase .from('rate_limits') .select('identifier, count, window_start, created_at, updated_at') .limit(0); if (schemaError && !schemaError.message.includes('no rows')) { console.warn('⚠️ Could not verify all columns:', schemaError.message); } else { console.log('✅ All expected columns are present!\n'); } console.log('✅ Migration verification successful!'); console.log('📊 View table at: https://app.supabase.com/project/mxadgucxhmstlzsbgmoz/editor/rate_limits\n'); } catch (error) { console.error('❌ Error during verification:', error.message); console.error('\nDetails:', error); process.exit(1); } } verifyMigration();