Reverted to commit 96a961d95c

This commit is contained in:
gpt-engineer-app[bot]
2025-10-11 15:58:11 +00:00
parent 092337ee9e
commit 1df9ada8ae
37 changed files with 173 additions and 2697 deletions

View File

@@ -1,52 +0,0 @@
-- Create blog_posts table
create table public.blog_posts (
id uuid primary key default gen_random_uuid(),
slug text unique not null,
title text not null,
content text not null,
featured_image_id text,
featured_image_url text,
author_id uuid references auth.users(id) not null,
status text not null default 'draft' check (status in ('draft', 'published')),
published_at timestamptz,
view_count integer default 0,
created_at timestamptz default now(),
updated_at timestamptz default now()
);
-- Indexes for performance
create index idx_blog_posts_slug on blog_posts(slug);
create index idx_blog_posts_status on blog_posts(status);
create index idx_blog_posts_published_at on blog_posts(published_at desc nulls last);
create index idx_blog_posts_author on blog_posts(author_id);
-- Enable RLS
alter table blog_posts enable row level security;
-- RLS Policies
create policy "Public can read published posts"
on blog_posts for select
using (status = 'published');
create policy "Admins can do everything"
on blog_posts for all
using (is_moderator(auth.uid()));
-- Auto-update updated_at timestamp
create trigger update_blog_posts_updated_at
before update on blog_posts
for each row
execute function update_updated_at_column();
-- Function to increment view count
create or replace function increment_blog_view_count(post_slug text)
returns void
language plpgsql
security definer
as $$
begin
update blog_posts
set view_count = view_count + 1
where slug = post_slug;
end;
$$;

View File

@@ -1,4 +0,0 @@
-- Fix blog_posts foreign key to reference profiles
ALTER TABLE blog_posts DROP CONSTRAINT IF EXISTS blog_posts_author_id_fkey;
ALTER TABLE blog_posts ADD CONSTRAINT blog_posts_author_id_fkey
FOREIGN KEY (author_id) REFERENCES profiles(user_id) ON DELETE CASCADE;

View File

@@ -1,10 +0,0 @@
-- Drop existing policy that allows moderators
DROP POLICY IF EXISTS "Admins can do everything" ON public.blog_posts;
-- Create new policy for admins and superusers only
CREATE POLICY "Admins and superusers can manage blog posts"
ON public.blog_posts FOR ALL
USING (
has_role(auth.uid(), 'admin'::app_role) OR
has_role(auth.uid(), 'superuser'::app_role)
);

View File

@@ -1,9 +0,0 @@
-- Add CAPTCHA bypass setting to admin_settings
INSERT INTO public.admin_settings (setting_key, setting_value, category, description)
VALUES (
'auth.captcha_bypass_enabled',
'false',
'auth',
'Allow CAPTCHA bypass for authentication (development only - requires VITE_ALLOW_CAPTCHA_BYPASS=true in environment)'
)
ON CONFLICT (setting_key) DO NOTHING;

View File

@@ -1,4 +0,0 @@
-- Remove the CAPTCHA bypass setting from admin_settings
-- This setting is now controlled exclusively via VITE_ALLOW_CAPTCHA_BYPASS environment variable
DELETE FROM public.admin_settings
WHERE setting_key = 'auth.captcha_bypass_enabled';