seed_m3.sql 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. -- seed_m3.sql
  2. -- M3 seed. Adds the per-company telegram_bots row, sets
  3. -- telegram_invite_code on every individual, and **pre-links**
  4. -- Alice to a fake Telegram account so the smoke test can
  5. -- exercise the full M3 path (FCM + Telegram delivery) on
  6. -- the very first POST.
  7. --
  8. -- Bob and Carol get invite codes but are NOT linked. The
  9. -- smoke test simulates `/start <code>` via faketgmd's
  10. -- /admin/queue endpoint, watches the link happen, then
  11. -- continues.
  12. --
  13. -- Idempotent (ON CONFLICT DO UPDATE for the link, ON
  14. -- CONFLICT DO NOTHING for the rest). Safe to re-run.
  15. -- ── telegram_bots ────────────────────────────────────────────────
  16. -- One bot for acme-001. The bot_token is the faketgmd sentinel
  17. -- "fake-tg-bot-token-acme-001". In production this is a real
  18. -- token from @BotFather; see M3_VERIFICATION §Step 8.
  19. INSERT INTO telegram_bots (bot_id, company_id, name, bot_token) VALUES
  20. ('primary', 'acme-001', 'Acme Ops', 'fake-tg-bot-token-acme-001')
  21. ON CONFLICT (company_id, bot_id) DO NOTHING;
  22. -- ── individuals: invite codes + Alice's pre-link ───────────────
  23. -- All three individuals get an invite code. Re-running the
  24. -- seed is safe: the code is overwritten on conflict.
  25. UPDATE individuals SET telegram_invite_code = 'acme-alice-001' WHERE id = 'ind-acme-001';
  26. UPDATE individuals SET telegram_invite_code = 'acme-bob-002' WHERE id = 'ind-acme-002';
  27. UPDATE individuals SET telegram_invite_code = 'acme-carol-003' WHERE id = 'ind-acme-003';
  28. -- Alice is already linked. The faketgmd admin endpoint can
  29. -- override these later; for M3 verification step 2 we want
  30. -- her to be linked so the first POST already exercises
  31. -- both fcm and telegram delivery paths.
  32. UPDATE individuals
  33. SET telegram_chat_id = 1001,
  34. telegram_user_id = 900001
  35. WHERE id = 'ind-acme-001';
  36. -- ── channel_mask expansion ─────────────────────────────────────
  37. -- Bob's subscription was ['fcm'] in M2. M3 needs it to be
  38. -- ['fcm','telegram'] so that, once he's linked via /start,
  39. -- the resolver starts emitting telegram endpoints for him.
  40. -- For step 2 the existing fcm path still fires for him; the
  41. -- telegram path is no-op until step 5 (the /start sim).
  42. UPDATE subscriptions
  43. SET channel_mask = '["fcm","telegram"]'::jsonb
  44. WHERE company_id = 'acme-001'
  45. AND individual_id IN ('ind-acme-001','ind-acme-002','ind-acme-003');
  46. -- Carol stays with channel_mask = ['fcm','telegram'] too, so
  47. -- the same channel expansion is exercised. Her quiet_hours
  48. -- keep her out of any non-inminent_colapse alert regardless.