Files
pezkuwi-telegram-miniapp/supabase/migrations/20260427_add_p2p_user_id.sql
T
pezkuwichain 698c014682 feat: unified P2P identity across Telegram mini app and pwap/web
Add p2p_user_id column to tg_users to bridge citizen/visa UUID (v5)
used by pwap/web with the Supabase Auth UUID (v4) used by the mini app.

- Migration: tg_users.p2p_user_id UUID (nullable, indexed)
- 6 P2P edge functions: replace listUsers+find with direct tg_users
  lookup — resolves userId as p2p_user_id ?? id (backwards compatible)
- Eliminates O(N) auth.admin.listUsers scan in every P2P call

When p2p_user_id is populated (via TelegramConnect wallet link),
mini app users share the same P2P balance and offers as pwap/web.
2026-04-27 13:30:09 +03:00

10 lines
432 B
SQL

-- Add p2p_user_id to tg_users for unified P2P identity across platforms
--
-- p2p_user_id = UUID v5 derived from citizen/visa number (same as pwap/web)
-- When a Telegram user links their wallet, this is populated.
-- Edge functions use: p2p_user_id ?? id (fallback keeps old behaviour)
ALTER TABLE tg_users ADD COLUMN IF NOT EXISTS p2p_user_id UUID;
CREATE INDEX IF NOT EXISTS idx_tg_users_p2p_user_id ON tg_users(p2p_user_id);