AI Resource Pro / website / scripts / dump-blog-schema.js
| 1 | // Script to dump the blog_posts table schema from Supabase |
| 2 | import { config } from 'dotenv'; |
| 3 | import { createClient } from '@supabase/supabase-js'; |
| 4 | |
| 5 | // Load environment variables |
| 6 | config({ path: '.env.local' }); |
| 7 | |
| 8 | // Create Supabase client |
| 9 | const supabase = createClient( |
| 10 | process.env.NEXT_PUBLIC_SUPABASE_URL, |
| 11 | process.env.SUPABASE_SERVICE_ROLE_KEY |
| 12 | ); |
| 13 | |
| 14 | async function dumpTableSchema() { |
| 15 | try { |
| 16 | console.log('Dumping blog_posts table schema...'); |
| 17 | |
| 18 | // Get sample records to see the actual data structure |
| 19 | const { data: sampleData, error: sampleError } = await supabase |
| 20 | .from('blog_posts') |
| 21 | .select('*') |
| 22 | .limit(1); |
| 23 | |
| 24 | if (sampleError) { |
| 25 | console.error('Error fetching sample data:', sampleError); |
| 26 | return; |
| 27 | } |
| 28 | |
| 29 | console.log('Sample blog post data:'); |
| 30 | console.log(JSON.stringify(sampleData, null, 2)); |
| 31 | |
| 32 | // List available columns |
| 33 | if (sampleData && sampleData.length > 0) { |
| 34 | console.log('Available columns in the first record:'); |
| 35 | console.log(Object.keys(sampleData[0])); |
| 36 | |
| 37 | // Check if the tags column exists |
| 38 | const hasTagsColumn = 'tags' in sampleData[0]; |
| 39 | console.log(`Tags column exists: ${hasTagsColumn}`); |
| 40 | } else { |
| 41 | console.log('No blog posts found in the database.'); |
| 42 | } |
| 43 | } catch (error) { |
| 44 | console.error('Unexpected error:', error); |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | dumpTableSchema(); |