AI Resource Pro / website / scripts / check-tools.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...'); |
| 28 | const { data: tools, error: toolsError } = await supabase |
| 29 | .from('tools') |
| 30 | .select('id, name, slug') |
| 31 | .limit(5); |
| 32 | |
| 33 | if (toolsError) { |
| 34 | console.error('Error fetching tools:', toolsError.message); |
| 35 | return; |
| 36 | } |
| 37 | |
| 38 | console.log(`Found ${tools?.length || 0} tools:`); |
| 39 | console.log(tools); |
| 40 | |
| 41 | console.log('\nChecking categories table...'); |
| 42 | const { data: categories, error: categoriesError } = await supabase |
| 43 | .from('categories') |
| 44 | .select('id, name, slug') |
| 45 | .limit(5); |
| 46 | |
| 47 | if (categoriesError) { |
| 48 | console.error('Error fetching categories:', categoriesError.message); |
| 49 | return; |
| 50 | } |
| 51 | |
| 52 | console.log(`Found ${categories?.length || 0} categories:`); |
| 53 | console.log(categories); |
| 54 | |
| 55 | console.log('\nChecking tools_categories table...'); |
| 56 | const { data: toolCategories, error: toolCategoriesError } = await supabase |
| 57 | .from('tools_categories') |
| 58 | .select('id, tool_id, category_id') |
| 59 | .limit(5); |
| 60 | |
| 61 | if (toolCategoriesError) { |
| 62 | console.error('Error fetching tools_categories:', toolCategoriesError.message); |
| 63 | return; |
| 64 | } |
| 65 | |
| 66 | console.log(`Found ${toolCategories?.length || 0} tools_categories:`); |
| 67 | console.log(toolCategories); |
| 68 | } |
| 69 | |
| 70 | main().catch(console.error); |