WellNuo/backend/migrations/002_add_password_hash.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

40 lines
1.6 KiB
SQL

-- ============================================================
-- Migration: 002_add_password_hash
-- Date: 2025-12-19
-- Author: Claude
-- Description: Add password_hash column for secure password storage
-- ============================================================
-- UP: Apply migration
-- ============================================================
-- Add password_hash column for bcrypt hashes
ALTER TABLE person_details
ADD COLUMN IF NOT EXISTS password_hash TEXT;
-- Add comment explaining the column
COMMENT ON COLUMN person_details.password_hash IS 'Bcrypt hashed password. The old "key" column contains plain text passwords and should be deprecated.';
-- Create index for faster lookups (optional, email is usually used for login)
CREATE INDEX IF NOT EXISTS idx_person_details_email ON person_details(email);
CREATE INDEX IF NOT EXISTS idx_person_details_user_name ON person_details(user_name);
-- ============================================================
-- IMPORTANT: After applying this migration, run the password
-- migration script in Node.js to hash existing passwords:
--
-- node scripts/migrate-passwords.js
--
-- This will:
-- 1. Read all users with key != NULL
-- 2. Hash each password with bcrypt
-- 3. Store in password_hash column
-- 4. Optionally clear the key column
-- ============================================================
-- DOWN: Rollback migration (for reference only)
-- ============================================================
-- ALTER TABLE person_details DROP COLUMN IF EXISTS password_hash;
-- DROP INDEX IF EXISTS idx_person_details_email;
-- DROP INDEX IF EXISTS idx_person_details_user_name;