// Script to check if the 'published' column exists in the blog_posts table import { config } from 'dotenv'; import { createClient } from '@supabase/supabase-js'; import { fileURLToPath } from 'url'; import { dirname, resolve } from 'path'; // Get the directory of the current module const __filename = fileURLToPath(import.meta.url); const __dirname = dirname(__filename); // Load environment variables from .env.local config({ path: resolve(__dirname, '../.env.local') }); 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 check your .env.local file.'); process.exit(1); } const supabase = createClient(supabaseUrl, supabaseServiceKey); async function checkPublishedColumn() { try { console.log('Checking if the published column exists in the blog_posts table...'); // Try to select a post with the published column const { data, error } = await supabase .from('blog_posts') .select('id, title, published') .limit(1); if (error) { console.error('Error checking published column:', error.message); if (error.message.includes("published")) { console.log('\nThe published column does NOT exist in the blog_posts table.'); console.log('\nPlease run the following SQL in your Supabase SQL Editor:'); console.log('\n-----------------------------------------------------------'); console.log(` ALTER TABLE blog_posts ADD COLUMN published BOOLEAN DEFAULT false; UPDATE blog_posts SET published = true; NOTIFY pgrst, 'reload schema'; `); console.log('-----------------------------------------------------------\n'); } } else { console.log('Successfully queried the blog_posts table with the published column.'); console.log('Sample data:', data); if (data.length > 0) { const hasPublishedProperty = 'published' in data[0]; console.log(`The published column ${hasPublishedProperty ? 'EXISTS' : 'DOES NOT EXIST'} in the blog_posts table.`); } else { console.log('No blog posts found to check the published column.'); } } } catch (error) { console.error('Error:', error.message); } } checkPublishedColumn();