Branchwell

AI Resource Pro / website / scripts / add_published_column.sql

1-- Add the published column to the blog_posts table if it doesn't exist
2DO $$
3BEGIN
4 IF NOT EXISTS (
5 SELECT FROM information_schema.columns
6 WHERE table_name = 'blog_posts' AND column_name = 'published'
7 ) THEN
8 ALTER TABLE blog_posts ADD COLUMN published BOOLEAN DEFAULT false;
9 -- Update existing posts to be published by default
10 UPDATE blog_posts SET published = true;
11 RAISE NOTICE 'Added published column to blog_posts table';
12 ELSE
13 RAISE NOTICE 'Column published already exists in blog_posts table';
14 END IF;
15END
16$$;
17
18-- Refresh the PostgREST schema cache (this may require admin privileges)
19NOTIFY pgrst, 'reload schema';
20
21-- Verify the column was added
22SELECT column_name, data_type
23FROM information_schema.columns
24WHERE table_name = 'blog_posts' AND column_name = 'published';