AI Resource Pro / website / scripts / check-tool-categories.ts
| 1 | import { createClient } from '@supabase/supabase-js'; |
| 2 | import * as dotenv from 'dotenv'; |
| 3 | import * as fs from 'fs'; |
| 4 | import * as path from 'path'; |
| 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 checkToolCategories() { |
| 17 | try { |
| 18 | console.log('Checking tool-categories relationship...'); |
| 19 | |
| 20 | const supabaseUrl = process.env.NEXT_PUBLIC_SUPABASE_URL; |
| 21 | const supabaseServiceKey = process.env.SUPABASE_SERVICE_ROLE_KEY; |
| 22 | |
| 23 | if (!supabaseUrl || !supabaseServiceKey) { |
| 24 | console.error('Missing Supabase environment variables. Please set NEXT_PUBLIC_SUPABASE_URL and SUPABASE_SERVICE_ROLE_KEY.'); |
| 25 | process.exit(1); |
| 26 | } |
| 27 | |
| 28 | const supabase = createClient(supabaseUrl, supabaseServiceKey, { |
| 29 | auth: { |
| 30 | autoRefreshToken: false, |
| 31 | persistSession: false |
| 32 | }, |
| 33 | db: { |
| 34 | schema: 'public' |
| 35 | } |
| 36 | }); |
| 37 | |
| 38 | // First check if a tools_categories table exists by trying to select from it |
| 39 | console.log('Checking for tools_categories table...'); |
| 40 | const { data: toolCategoriesData, error: toolCategoriesError } = await supabase |
| 41 | .from('tools_categories') |
| 42 | .select('*') |
| 43 | .limit(5); |
| 44 | |
| 45 | if (toolCategoriesError) { |
| 46 | console.error('Error or table does not exist:', toolCategoriesError); |
| 47 | |
| 48 | // Try alternative table name |
| 49 | console.log('Checking for tools_categories table...'); |
| 50 | const { data: toolsCategoriesData, error: toolsCategoriesError } = await supabase |
| 51 | .from('tools_categories') |
| 52 | .select('*') |
| 53 | .limit(5); |
| 54 | |
| 55 | if (toolsCategoriesError) { |
| 56 | console.error('Error or table does not exist:', toolsCategoriesError); |
| 57 | } else { |
| 58 | console.log('Found tools_categories table with data:', JSON.stringify(toolsCategoriesData, null, 2)); |
| 59 | |
| 60 | // Also check for specific tools |
| 61 | const { data: specificToolCategories, error: specificError } = await supabase |
| 62 | .from('tools_categories') |
| 63 | .select('*') |
| 64 | .in('tool_id', [672, 673, 674, 675, 678, 679]) |
| 65 | .limit(20); |
| 66 | |
| 67 | if (specificError) { |
| 68 | console.error('Error fetching specific tool categories:', specificError); |
| 69 | } else { |
| 70 | console.log('Categories for featured tools:', JSON.stringify(specificToolCategories, null, 2)); |
| 71 | } |
| 72 | } |
| 73 | } else { |
| 74 | console.log('Found tools_categories table with data:', JSON.stringify(toolCategoriesData, null, 2)); |
| 75 | |
| 76 | // Also check for specific tools |
| 77 | const { data: specificToolCategories, error: specificError } = await supabase |
| 78 | .from('tools_categories') |
| 79 | .select('*') |
| 80 | .in('tool_id', [672, 673, 674, 675, 678, 679]) |
| 81 | .limit(20); |
| 82 | |
| 83 | if (specificError) { |
| 84 | console.error('Error fetching specific tool categories:', specificError); |
| 85 | } else { |
| 86 | console.log('Categories for featured tools:', JSON.stringify(specificToolCategories, null, 2)); |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | // Also check tool_category table as another possibility |
| 91 | console.log('Checking for tool_category table...'); |
| 92 | const { data: toolCategoryData, error: toolCategoryError } = await supabase |
| 93 | .from('tool_category') |
| 94 | .select('*') |
| 95 | .limit(5); |
| 96 | |
| 97 | if (toolCategoryError) { |
| 98 | console.error('Error or table does not exist:', toolCategoryError); |
| 99 | } else { |
| 100 | console.log('Found tool_category table with data:', JSON.stringify(toolCategoryData, null, 2)); |
| 101 | } |
| 102 | |
| 103 | } catch (error) { |
| 104 | console.error('Error in script:', error); |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | checkToolCategories(); |