Files
thrilltrack-explorer/supabase/migrations/20251013182948_4e9710fc-7ef6-4278-9cb7-ecec66eac4b3.sql
2025-10-13 18:31:29 +00:00

21 lines
771 B
SQL

-- Add action_type column to submission_items to preserve original submission intent
ALTER TABLE submission_items
ADD COLUMN IF NOT EXISTS action_type text DEFAULT 'create';
-- Add check constraint to ensure valid values
ALTER TABLE submission_items
ADD CONSTRAINT submission_items_action_type_check
CHECK (action_type IN ('create', 'edit', 'delete'));
-- Create index for better query performance
CREATE INDEX IF NOT EXISTS idx_submission_items_action_type
ON submission_items(action_type);
-- Backfill existing records based on original_data presence
UPDATE submission_items
SET action_type = CASE
WHEN item_type = 'photo_delete' THEN 'delete'
WHEN original_data IS NULL OR original_data::text = '{}' THEN 'create'
ELSE 'edit'
END
WHERE action_type IS NULL;