- Added UNIQUE constraint on system_automations (bot_id, kind, param) to prevent duplicate automations - Refactored execute_action to accept full Automation struct instead of just param - Simplified bot name resolution by using automation.bot_id directly - Improved error handling in action execution with proper error propagation - Removed redundant bot name lookup logic by leveraging existing bot_id
15 lines
484 B
SQL
15 lines
484 B
SQL
-- Migration 6.0.10: Add unique constraint for system_automations upsert
|
|
-- Description: Creates a unique constraint matching the ON CONFLICT target in set_schedule.rs
|
|
|
|
DO $$
|
|
BEGIN
|
|
IF NOT EXISTS (
|
|
SELECT 1 FROM pg_constraint
|
|
WHERE conname = 'system_automations_bot_kind_param_unique'
|
|
) THEN
|
|
ALTER TABLE public.system_automations
|
|
ADD CONSTRAINT system_automations_bot_kind_param_unique
|
|
UNIQUE (bot_id, kind, param);
|
|
END IF;
|
|
END
|
|
$$;
|