mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-24 13:11:14 -05:00
Add action_type to submission items
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
-- 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;
|
||||
Reference in New Issue
Block a user