-- Add published field to news table -- This migration adds a published field to track whether news items should be displayed on the site -- Check if the published column exists in the news table DO $$ BEGIN IF NOT EXISTS ( SELECT 1 FROM information_schema.columns WHERE table_name = 'news' AND column_name = 'published' ) THEN -- Add the published column with a default value of false ALTER TABLE public.news ADD COLUMN published BOOLEAN NOT NULL DEFAULT false; RAISE NOTICE 'Added published column to news table'; ELSE RAISE NOTICE 'Published column already exists in news table'; END IF; END $$; -- Update all existing news records to be published by default -- This ensures backward compatibility UPDATE public.news SET published = true WHERE published = false; -- Add an index to improve query performance for filtering by published status DO $$ BEGIN IF NOT EXISTS ( SELECT 1 FROM pg_indexes WHERE tablename = 'news' AND indexname = 'idx_news_published' ) THEN CREATE INDEX idx_news_published ON public.news (published); RAISE NOTICE 'Created index on published column'; ELSE RAISE NOTICE 'Index on published column already exists'; END IF; END $$;