WellNuo/backend/migrations/003_create_push_tokens.sql
Sergei ec63a2c1e2 Add admin panel, optimized API, OTP auth, migrations
Admin Panel (Next.js):
- Dashboard with stats
- Users list with relationships (watches/watched_by)
- User detail pages
- Deployments list and detail pages
- Devices, Orders, Subscriptions pages
- OTP-based admin authentication

Backend Optimizations:
- Fixed N+1 query problem in admin APIs
- Added pagination support
- Added .range() and count support to Supabase wrapper
- Optimized batch queries with lookup maps

Database:
- Added migrations for schema evolution
- New tables: push_tokens, notification_settings
- Updated access model

iOS Build Scripts:
- build-ios.sh, clear-apple-cache.sh
- EAS configuration updates

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-20 11:05:39 -08:00

43 lines
1.7 KiB
SQL

-- ============================================================
-- Migration: 003_create_push_tokens
-- Date: 2025-12-19
-- Author: Claude
-- Description: Create table for storing push notification tokens
-- ============================================================
-- UP: Apply migration
-- ============================================================
CREATE TABLE IF NOT EXISTS push_tokens (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
user_id INTEGER REFERENCES person_details(user_id) ON DELETE CASCADE,
token TEXT NOT NULL,
platform VARCHAR(20) CHECK (platform IN ('ios', 'android', 'web')),
device_id TEXT,
device_name TEXT,
app_version TEXT,
is_active BOOLEAN DEFAULT true,
created_at TIMESTAMPTZ DEFAULT NOW(),
updated_at TIMESTAMPTZ DEFAULT NOW(),
last_used_at TIMESTAMPTZ,
-- One token per device per user
UNIQUE(user_id, device_id)
);
-- Indexes for common queries
CREATE INDEX IF NOT EXISTS idx_push_tokens_user ON push_tokens(user_id);
CREATE INDEX IF NOT EXISTS idx_push_tokens_token ON push_tokens(token);
CREATE INDEX IF NOT EXISTS idx_push_tokens_active ON push_tokens(is_active) WHERE is_active = true;
-- Comments
COMMENT ON TABLE push_tokens IS 'Stores push notification tokens for mobile and web clients';
COMMENT ON COLUMN push_tokens.token IS 'Expo Push Token (ExponentPushToken[xxx]) or FCM token';
COMMENT ON COLUMN push_tokens.platform IS 'Device platform: ios, android, or web';
COMMENT ON COLUMN push_tokens.device_id IS 'Unique device identifier';
-- ============================================================
-- DOWN: Rollback migration (for reference only)
-- ============================================================
-- DROP TABLE IF EXISTS push_tokens;