AI Resource Pro / website / scripts / check-tools-schema.ts
| 1 | import { createClient } from '@supabase/supabase-js'; |
| 2 | import * as dotenv from 'dotenv'; |
| 3 | import path from 'path'; |
| 4 | import fs from 'fs'; |
| 5 | |
| 6 | // Load environment variables from .env.local |
| 7 | const envLocalPath = path.resolve(process.cwd(), '../.env.local'); |
| 8 | if (fs.existsSync(envLocalPath)) { |
| 9 | console.log(`Loading environment from: ${envLocalPath}`); |
| 10 | dotenv.config({ path: envLocalPath }); |
| 11 | } else { |
| 12 | console.log(`No .env.local file found at: ${envLocalPath}`); |
| 13 | dotenv.config(); // Try loading from default .env |
| 14 | } |
| 15 | |
| 16 | async function main() { |
| 17 | const supabaseUrl = process.env.NEXT_PUBLIC_SUPABASE_URL; |
| 18 | const supabaseServiceKey = process.env.SUPABASE_SERVICE_ROLE_KEY; |
| 19 | |
| 20 | if (!supabaseUrl || !supabaseServiceKey) { |
| 21 | console.error('Missing Supabase environment variables. Please set NEXT_PUBLIC_SUPABASE_URL and SUPABASE_SERVICE_ROLE_KEY.'); |
| 22 | return; |
| 23 | } |
| 24 | |
| 25 | const supabase = createClient(supabaseUrl, supabaseServiceKey); |
| 26 | |
| 27 | console.log('Checking tools table schema...'); |
| 28 | |
| 29 | // Query to get table information |
| 30 | const { data: tableInfo, error: tableError } = await supabase |
| 31 | .rpc('exec_sql', { |
| 32 | sql_query: ` |
| 33 | SELECT column_name, data_type, is_nullable |
| 34 | FROM information_schema.columns |
| 35 | WHERE table_name = 'tools' |
| 36 | ORDER BY ordinal_position; |
| 37 | ` |
| 38 | }); |
| 39 | |
| 40 | if (tableError) { |
| 41 | console.error('Error fetching table schema:', tableError.message); |
| 42 | |
| 43 | // Try a simpler approach - just query the tools table with a single row |
| 44 | console.log('Trying alternative approach to check schema...'); |
| 45 | const { data: sampleTool, error: sampleError } = await supabase |
| 46 | .from('tools') |
| 47 | .select('*') |
| 48 | .limit(1) |
| 49 | .single(); |
| 50 | |
| 51 | if (sampleError) { |
| 52 | console.error('Error fetching sample tool:', sampleError.message); |
| 53 | return; |
| 54 | } |
| 55 | |
| 56 | console.log('Tool table columns:'); |
| 57 | console.log(Object.keys(sampleTool)); |
| 58 | return; |
| 59 | } |
| 60 | |
| 61 | console.log('Tools table schema:'); |
| 62 | console.log(tableInfo); |
| 63 | } |
| 64 | |
| 65 | main().catch(console.error); |