wacrm/supabase/migrations
Arnas Donauskas 95faf58e75 fix(ai): grant EXECUTE on claim_ai_reply_slot so auto-reply works (#345)
Migration 029 created claim_ai_reply_slot(uuid, integer) as SECURITY
DEFINER but never GRANTed EXECUTE — the only function in the schema
missing its grant (007/012/017/018/019/025/030 all grant theirs).

SECURITY DEFINER sets the privileges a function runs *with*, not who may
*call* it: the caller still needs EXECUTE. On instances where the default
PUBLIC execute privilege on public-schema functions has been revoked
(hardened / self-hosted Supabase), the service_role that PostgREST uses
cannot invoke it. The AI auto-reply path runs entirely under the
service-role client (the inbound webhook has no auth.uid()), so
db.rpc('claim_ai_reply_slot') fails permission-denied, the dispatch bails
before sending, and the bot silently never answers ANY inbound message.
The Playground works because it never claims a slot — matching the report.

- 031_ai_reply_slot_grant.sql: new migration granting EXECUTE to
  service_role (029 is already applied on existing installs, so it needs
  its own migration to reach them). service_role only — the sole caller —
  matching the 007/012 increment-counter precedent.
- 029_ai_reply.sql: add the same grant next to the definition so fresh
  installs are correct.
- auto-reply.ts: log a real claim RPC error instead of returning
  silently, so this class of deploy failure is diagnosable.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-07 10:43:03 +03:00
..
001_initial_schema.sql fix: make migration idempotent 2026-04-16 19:46:41 +03:00
002_pipelines_enhancements.sql feat(pipelines): Kanban drag-drop, analytics, deal sheet, contact deals tab 2026-04-16 22:38:45 +03:00
003_broadcast_recipient_wamid.sql fix(broadcasts): per-recipient variables, webhook status sync, rate limit 2026-04-17 11:22:38 +03:00
004_contact_delete_set_null.sql fix(contacts): allow deletion — SET NULL on broadcast_recipients, deals 2026-04-17 16:56:45 +03:00
005_broadcast_counts_incremental.sql fix(broadcasts): senior-review hardening pass 2026-04-17 17:38:52 +03:00
006_automations.sql feat(automations): visual flow builder, engine, and logs viewer 2026-04-17 19:39:02 +03:00
007_automations_increment_counter.sql fix(automations): atomic execution_count via SQL function (migration 007) 2026-04-17 21:45:27 +03:00
008_profile_avatars_storage.sql feat(settings): user profile management 2026-04-20 17:40:39 +03:00
009_message_actions.sql feat(inbox): reactions, reply-to, and copy on chat messages 2026-05-19 16:17:26 +03:00
010_flows.sql feat(flows): foundation for interactive WhatsApp messages (PR 1/4) 2026-05-22 13:12:27 +03:00
011_profile_beta_features.sql feat(beta): per-account beta_features flag on profiles, gating Flows 2026-05-22 12:57:33 +03:00
012_flows_increment_counter.sql fix(flows): atomic execution_count increment via SECURITY DEFINER RPC 2026-05-22 15:39:00 +03:00
013_whatsapp_config_phone_number_id_unique.sql fix(whatsapp): prevent silent inbound-message drop when two users share a phone_number_id 2026-05-26 10:35:59 +02:00
014_message_templates_meta_integration.sql fix(migration-014): drop subquery from buttons CHECK (Postgres disallows it) 2026-05-29 12:21:14 +02:00
015_whatsapp_config_registration.sql fix(whatsapp): register phone numbers on Meta + verify subscription state 2026-05-29 18:12:38 +02:00
016_flow_media.sql feat(flows): add send_media node for image / video / document sends 2026-05-29 19:11:29 +02:00
017_account_sharing.sql fix(migrations): make 017 RLS rewrite re-runnable 2026-06-22 09:48:47 +03:00
018_account_member_rpcs.sql feat(api): account + members management endpoints 2026-05-31 15:00:27 +03:00
019_invitation_rpcs.sql feat(api): invitation create + peek + redeem endpoints 2026-05-31 17:32:46 +03:00
020_account_sharing_followups.sql perf(db,webhook): backend follow-ups from the multi-user review 2026-05-31 19:18:58 +03:00
021_account_default_currency.sql feat(deals): make default deal currency configurable per account (#218) 2026-06-08 13:59:48 +03:00
022_contact_phone_dedup.sql feat(contacts): prevent duplicate phone numbers on create/import (#212) 2026-06-08 15:52:38 +03:00
023_chat_media.sql feat(inbox): send photo, video, document & voice in chat (#213) 2026-06-18 10:07:16 +03:00
024_member_presence.sql feat(team): member presence (online / away / offline) on the roster 2026-06-22 14:37:29 +03:00
025_filter_contacts_by_tags.sql feat(contacts): add filter_contacts_by_tags RPC migration 2026-06-22 15:50:40 +03:00
026_api_keys.sql feat(api): public API groundwork — scoped API keys + /api/v1/me 2026-06-23 15:35:43 +03:00
027_notifications.sql feat(notifications): implement account-based notification retrieval and update logic 2026-06-30 11:16:20 +05:30
028_webhook_endpoints.sql feat(api): outbound event webhooks — /api/v1/webhooks (#245) 2026-07-01 14:53:18 +03:00
029_ai_reply.sql fix(ai): grant EXECUTE on claim_ai_reply_slot so auto-reply works (#345) 2026-07-07 10:43:03 +03:00
030_ai_knowledge.sql fix(ai-kb): address code-review findings 2026-07-02 17:20:38 +03:00
031_ai_reply_slot_grant.sql fix(ai): grant EXECUTE on claim_ai_reply_slot so auto-reply works (#345) 2026-07-07 10:43:03 +03:00