Branchwell

AI Resource Pro / website / scripts / check-categories.ts

1import { createClient } from '@supabase/supabase-js';
2import * as dotenv from 'dotenv';
3import * as fs from 'fs';
4import * as path from 'path';
5
6// Load environment variables from .env.local
7const envLocalPath = path.resolve(process.cwd(), '.env.local');
8if (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
16async function checkCategories() {
17 try {
18 console.log('Checking categories table...');
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 // Query categories
39 const { data: categoriesData, error: categoriesError } = await supabase
40 .from('categories')
41 .select('*')
42 .limit(20);
43
44 if (categoriesError) {
45 console.error('Error fetching categories:', categoriesError);
46 return;
47 }
48
49 console.log('Categories count:', categoriesData?.length || 0);
50 console.log('Categories data sample (first 5):', JSON.stringify(categoriesData?.slice(0, 5), null, 2));
51
52 // Also check for the specific categories related to the featured tools with IDs 26 and 27
53 const { data: specificCategories, error: specificError } = await supabase
54 .from('categories')
55 .select('*')
56 .in('id', [26, 27, 61]);
57
58 if (specificError) {
59 console.error('Error fetching specific categories:', specificError);
60 return;
61 }
62
63 console.log('Specific categories:', JSON.stringify(specificCategories, null, 2));
64 } catch (error) {
65 console.error('Error in script:', error);
66 }
67}
68
69checkCategories();