|
| 1 | +-- Migration SQL for Campaign Wall Feature |
| 2 | +-- Run this SQL in your Supabase SQL editor |
| 3 | + |
| 4 | +-- 1. Add new columns to campaigns table for campaign wall feature |
| 5 | +ALTER TABLE public.campaigns |
| 6 | +ADD COLUMN IF NOT EXISTS is_open_for_applications boolean DEFAULT false, |
| 7 | +ADD COLUMN IF NOT EXISTS is_on_campaign_wall boolean DEFAULT false; |
| 8 | + |
| 9 | +-- 2. Add indexes for better query performance |
| 10 | +CREATE INDEX IF NOT EXISTS idx_campaigns_is_open_for_applications ON public.campaigns(is_open_for_applications) WHERE is_open_for_applications = true; |
| 11 | +CREATE INDEX IF NOT EXISTS idx_campaigns_is_on_campaign_wall ON public.campaigns(is_on_campaign_wall) WHERE is_on_campaign_wall = true; |
| 12 | +CREATE INDEX IF NOT EXISTS idx_campaigns_open_and_wall ON public.campaigns(is_open_for_applications, is_on_campaign_wall) WHERE is_open_for_applications = true AND is_on_campaign_wall = true; |
| 13 | + |
| 14 | +-- 3. Add new columns to campaign_applications table |
| 15 | +ALTER TABLE public.campaign_applications |
| 16 | +ADD COLUMN IF NOT EXISTS payment_min numeric, |
| 17 | +ADD COLUMN IF NOT EXISTS payment_max numeric, |
| 18 | +ADD COLUMN IF NOT EXISTS timeline_days integer, |
| 19 | +ADD COLUMN IF NOT EXISTS timeline_weeks integer, |
| 20 | +ADD COLUMN IF NOT EXISTS description text; |
| 21 | + |
| 22 | +-- 4. Add index for campaign_applications status filtering |
| 23 | +CREATE INDEX IF NOT EXISTS idx_campaign_applications_status ON public.campaign_applications(status); |
| 24 | +CREATE INDEX IF NOT EXISTS idx_campaign_applications_campaign_status ON public.campaign_applications(campaign_id, status); |
| 25 | +CREATE INDEX IF NOT EXISTS idx_campaign_applications_creator_status ON public.campaign_applications(creator_id, status); |
| 26 | + |
| 27 | +-- 5. Add 'reviewing' to application_status enum if it doesn't exist |
| 28 | +DO $$ |
| 29 | +BEGIN |
| 30 | + -- Check if 'reviewing' value exists in the enum |
| 31 | + IF NOT EXISTS ( |
| 32 | + SELECT 1 |
| 33 | + FROM pg_enum |
| 34 | + WHERE enumlabel = 'reviewing' |
| 35 | + AND enumtypid = (SELECT oid FROM pg_type WHERE typname = 'application_status') |
| 36 | + ) THEN |
| 37 | + -- Add 'reviewing' to the enum |
| 38 | + -- Note: PostgreSQL doesn't support IF NOT EXISTS for ALTER TYPE ADD VALUE |
| 39 | + -- So we check first, then add if needed |
| 40 | + ALTER TYPE application_status ADD VALUE 'reviewing'; |
| 41 | + END IF; |
| 42 | +EXCEPTION |
| 43 | + WHEN duplicate_object THEN |
| 44 | + -- Value already exists, ignore |
| 45 | + NULL; |
| 46 | +END $$; |
| 47 | + |
| 48 | +-- 6. Add comment for documentation |
| 49 | +COMMENT ON COLUMN public.campaigns.is_open_for_applications IS 'Whether this campaign accepts applications from creators'; |
| 50 | +COMMENT ON COLUMN public.campaigns.is_on_campaign_wall IS 'Whether this campaign is visible on the public campaign wall'; |
| 51 | +COMMENT ON COLUMN public.campaign_applications.payment_min IS 'Minimum payment amount the creator is requesting'; |
| 52 | +COMMENT ON COLUMN public.campaign_applications.payment_max IS 'Maximum payment amount the creator is requesting'; |
| 53 | +COMMENT ON COLUMN public.campaign_applications.timeline_days IS 'Number of days the creator estimates to complete the campaign'; |
| 54 | +COMMENT ON COLUMN public.campaign_applications.timeline_weeks IS 'Number of weeks the creator estimates to complete the campaign'; |
| 55 | +COMMENT ON COLUMN public.campaign_applications.description IS 'Creator description explaining why they should be chosen for this campaign'; |
| 56 | + |
0 commit comments