You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-- Migration: Create user_wallets table for multi-wallet support
-- EXECUTED: Applied to Supabase
CREATE TABLE IF NOT EXISTS public.user_wallets (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
user_id UUID NOT NULL REFERENCES auth.users(id) ON DELETE CASCADE,
wallet_address TEXT NOT NULL,
wallet_type TEXT NOT NULL CHECK (wallet_type IN ('custodial', 'freighter', 'lobstr', 'xbull', 'albedo', 'other')),
label TEXT,
is_primary BOOLEAN DEFAULT false,
is_verified BOOLEAN DEFAULT false,
verified_at TIMESTAMPTZ,
created_at TIMESTAMPTZ DEFAULT now(),
updated_at TIMESTAMPTZ DEFAULT now(),
UNIQUE(user_id, wallet_address)
);
CREATE INDEX IF NOT EXISTS idx_user_wallets_user_id ON public.user_wallets(user_id);
CREATE INDEX IF NOT EXISTS idx_user_wallets_wallet_address ON public.user_wallets(wallet_address);
CREATE UNIQUE INDEX IF NOT EXISTS idx_user_wallets_primary ON public.user_wallets(user_id) WHERE is_primary = true;
ALTER TABLE public.user_wallets ENABLE ROW LEVEL SECURITY;
CREATE POLICY "Users can view their own wallets" ON public.user_wallets FOR SELECT USING (auth.uid() = user_id);
CREATE POLICY "Users can insert their own wallets" ON public.user_wallets FOR INSERT WITH CHECK (auth.uid() = user_id);
CREATE POLICY "Users can update their own wallets" ON public.user_wallets FOR UPDATE USING (auth.uid() = user_id);
CREATE POLICY "Users can delete their own wallets" ON public.user_wallets FOR DELETE USING (auth.uid() = user_id);
COMMENT ON TABLE public.user_wallets IS 'Links multiple Stellar wallets to a single user account. Supports custodial (social login) and external wallets.';