import { createClient } from '@supabase/supabase-js'; import * as dotenv from 'dotenv'; import * as fs from 'fs'; import * as path from 'path'; // Load environment variables from .env.local const envLocalPath = path.resolve(process.cwd(), '.env.local'); if (fs.existsSync(envLocalPath)) { console.log(`Loading environment from: ${envLocalPath}`); dotenv.config({ path: envLocalPath }); } else { console.log(`No .env.local file found at: ${envLocalPath}`); dotenv.config(); // Try loading from default .env } async function checkToolCategories() { try { console.log('Checking tool-categories relationship...'); const supabaseUrl = process.env.NEXT_PUBLIC_SUPABASE_URL; const supabaseServiceKey = process.env.SUPABASE_SERVICE_ROLE_KEY; if (!supabaseUrl || !supabaseServiceKey) { console.error('Missing Supabase environment variables. Please set NEXT_PUBLIC_SUPABASE_URL and SUPABASE_SERVICE_ROLE_KEY.'); process.exit(1); } const supabase = createClient(supabaseUrl, supabaseServiceKey, { auth: { autoRefreshToken: false, persistSession: false }, db: { schema: 'public' } }); // First check if a tools_categories table exists by trying to select from it console.log('Checking for tools_categories table...'); const { data: toolCategoriesData, error: toolCategoriesError } = await supabase .from('tools_categories') .select('*') .limit(5); if (toolCategoriesError) { console.error('Error or table does not exist:', toolCategoriesError); // Try alternative table name console.log('Checking for tools_categories table...'); const { data: toolsCategoriesData, error: toolsCategoriesError } = await supabase .from('tools_categories') .select('*') .limit(5); if (toolsCategoriesError) { console.error('Error or table does not exist:', toolsCategoriesError); } else { console.log('Found tools_categories table with data:', JSON.stringify(toolsCategoriesData, null, 2)); // Also check for specific tools const { data: specificToolCategories, error: specificError } = await supabase .from('tools_categories') .select('*') .in('tool_id', [672, 673, 674, 675, 678, 679]) .limit(20); if (specificError) { console.error('Error fetching specific tool categories:', specificError); } else { console.log('Categories for featured tools:', JSON.stringify(specificToolCategories, null, 2)); } } } else { console.log('Found tools_categories table with data:', JSON.stringify(toolCategoriesData, null, 2)); // Also check for specific tools const { data: specificToolCategories, error: specificError } = await supabase .from('tools_categories') .select('*') .in('tool_id', [672, 673, 674, 675, 678, 679]) .limit(20); if (specificError) { console.error('Error fetching specific tool categories:', specificError); } else { console.log('Categories for featured tools:', JSON.stringify(specificToolCategories, null, 2)); } } // Also check tool_category table as another possibility console.log('Checking for tool_category table...'); const { data: toolCategoryData, error: toolCategoryError } = await supabase .from('tool_category') .select('*') .limit(5); if (toolCategoryError) { console.error('Error or table does not exist:', toolCategoryError); } else { console.log('Found tool_category table with data:', JSON.stringify(toolCategoryData, null, 2)); } } catch (error) { console.error('Error in script:', error); } } checkToolCategories();