sojorn/_legacy/supabase/migrations/create_sponsored_posts.sql
Patrick Britton 3c4680bdd7 Initial commit: Complete threaded conversation system with inline replies
**Major Features Added:**
- **Inline Reply System**: Replace compose screen with inline reply boxes
- **Thread Navigation**: Parent/child navigation with jump functionality
- **Chain Flow UI**: Reply counts, expand/collapse animations, visual hierarchy
- **Enhanced Animations**: Smooth transitions, hover effects, micro-interactions

 **Frontend Changes:**
- **ThreadedCommentWidget**: Complete rewrite with animations and navigation
- **ThreadNode Model**: Added parent references and descendant counting
- **ThreadedConversationScreen**: Integrated navigation handlers
- **PostDetailScreen**: Replaced with threaded conversation view
- **ComposeScreen**: Added reply indicators and context
- **PostActions**: Fixed visibility checks for chain buttons

 **Backend Changes:**
- **API Route**: Added /posts/:id/thread endpoint
- **Post Repository**: Include allow_chain and visibility fields in feed
- **Thread Handler**: Support for fetching post chains

 **UI/UX Improvements:**
- **Reply Context**: Clear indication when replying to specific posts
- **Character Counting**: 500 character limit with live counter
- **Visual Hierarchy**: Depth-based indentation and styling
- **Smooth Animations**: SizeTransition, FadeTransition, hover states
- **Chain Navigation**: Parent/child buttons with visual feedback

 **Technical Enhancements:**
- **Animation Controllers**: Proper lifecycle management
- **State Management**: Clean separation of concerns
- **Navigation Callbacks**: Reusable navigation system
- **Error Handling**: Graceful fallbacks and user feedback

This creates a Reddit-style threaded conversation experience with smooth
animations, inline replies, and intuitive navigation between posts in a chain.
2026-01-30 07:40:19 -06:00

44 lines
1.5 KiB
PL/PgSQL

-- Migration: Create sponsored_posts table for First-Party Contextual Ads
-- Created: 2026-01-12
-- Purpose: Silent launch infrastructure for sponsored content (table starts empty)
create table if not exists sponsored_posts (
id uuid default gen_random_uuid() primary key,
created_at timestamptz default now(),
advertiser_name text not null,
body text not null, -- Markdown content
image_url text, -- Optional banner
cta_link text not null,
cta_text text default 'Learn More',
target_categories text[] not null, -- Array of Category IDs to match against
active boolean default true,
-- Internal tracking (private)
impression_goal int default 1000,
current_impressions int default 0
);
-- RLS: Public Read-Only (authenticated), Service Role Write-Only
alter table sponsored_posts enable row level security;
create policy "Users can read active ads" on sponsored_posts
for select to authenticated using (active = true);
-- Index for efficient category matching queries
create index if not exists idx_sponsored_posts_categories
on sponsored_posts using gin (target_categories);
-- Index for active ads filtering
create index if not exists idx_sponsored_posts_active
on sponsored_posts (active) where active = true;
-- Function to increment ad impressions (called from client)
create or replace function increment_ad_impression(p_ad_id uuid)
returns void as $$
begin
update sponsored_posts
set current_impressions = current_impressions + 1
where id = p_ad_id;
end;
$$ language plpgsql security definer;