fix: correct migration SQL with student_class column and full demo user upserts (Aarav/Neha/Rohan/Amit)
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
-- =============================================================================
|
-- =============================================================================
|
||||||
-- Pragativeer Full Schema Sync Migration
|
-- Pragativeer Full Schema Sync + Demo User Seed Migration
|
||||||
-- File: migrations/001_full_schema_sync.sql
|
-- File: migrations/001_full_schema_sync.sql
|
||||||
--
|
--
|
||||||
-- HOW TO RUN:
|
-- HOW TO RUN:
|
||||||
@@ -8,10 +8,11 @@
|
|||||||
--
|
--
|
||||||
-- This script is 100% idempotent (safe to run multiple times).
|
-- This script is 100% idempotent (safe to run multiple times).
|
||||||
-- Uses IF NOT EXISTS everywhere so already-applied changes are silently skipped.
|
-- Uses IF NOT EXISTS everywhere so already-applied changes are silently skipped.
|
||||||
|
-- Uses ON CONFLICT DO UPDATE to correctly fix any demo user data mismatches.
|
||||||
-- =============================================================================
|
-- =============================================================================
|
||||||
|
|
||||||
-- ── ENUM TYPES ─────────────────────────────────────────────────────────────────
|
-- ── ENUM TYPES ─────────────────────────────────────────────────────────────────
|
||||||
-- Note: All enum values in DB are UPPERCASE (e.g. FREE, PRO, AI_COACH, JEE_MAIN)
|
-- All enum values in DB are UPPERCASE (e.g. FREE, PRO, AI_COACH, JEE_MAIN)
|
||||||
|
|
||||||
DO $$ BEGIN
|
DO $$ BEGIN
|
||||||
CREATE TYPE classenum AS ENUM ('ELEVENTH', 'TWELFTH', 'DROPPER');
|
CREATE TYPE classenum AS ENUM ('ELEVENTH', 'TWELFTH', 'DROPPER');
|
||||||
@@ -54,7 +55,7 @@ CREATE TABLE IF NOT EXISTS "user" (
|
|||||||
phone TEXT UNIQUE,
|
phone TEXT UNIQUE,
|
||||||
password_hash TEXT NOT NULL,
|
password_hash TEXT NOT NULL,
|
||||||
name TEXT NOT NULL,
|
name TEXT NOT NULL,
|
||||||
class classenum NOT NULL,
|
student_class classenum NOT NULL,
|
||||||
target_exam examenum NOT NULL,
|
target_exam examenum NOT NULL,
|
||||||
medium mediumenum NOT NULL,
|
medium mediumenum NOT NULL,
|
||||||
school TEXT,
|
school TEXT,
|
||||||
@@ -292,3 +293,89 @@ ALTER TABLE systemsettings
|
|||||||
INSERT INTO systemsettings (id, maintenance_mode, allow_new_registrations, enable_free_trial, trial_duration_days, trial_tier, updated_at)
|
INSERT INTO systemsettings (id, maintenance_mode, allow_new_registrations, enable_free_trial, trial_duration_days, trial_tier, updated_at)
|
||||||
VALUES ('global', FALSE, TRUE, TRUE, 15, 'AI_COACH', now())
|
VALUES ('global', FALSE, TRUE, TRUE, 15, 'AI_COACH', now())
|
||||||
ON CONFLICT (id) DO NOTHING;
|
ON CONFLICT (id) DO NOTHING;
|
||||||
|
|
||||||
|
|
||||||
|
-- =============================================================================
|
||||||
|
-- DEMO USER SEED / FIX
|
||||||
|
-- These 4 rows are the canonical demo accounts used by the frontend switcher.
|
||||||
|
-- ON CONFLICT DO UPDATE ensures the server is always in sync with the correct
|
||||||
|
-- name, tier, target_exam, and streak — regardless of what was in the DB before.
|
||||||
|
-- password_hash below is bcrypt of "PragatiVeer@Demo2026" (12 rounds).
|
||||||
|
-- =============================================================================
|
||||||
|
|
||||||
|
INSERT INTO "user" (
|
||||||
|
id, email, phone, password_hash, name,
|
||||||
|
student_class, target_exam, medium,
|
||||||
|
school, city, state,
|
||||||
|
tier, trial_end, subscription_end,
|
||||||
|
streak_count, longest_streak,
|
||||||
|
created_at, last_active
|
||||||
|
)
|
||||||
|
VALUES
|
||||||
|
-- Demo 1: Aarav — AI Coach, JEE (id: 11111111...)
|
||||||
|
(
|
||||||
|
'11111111-1111-1111-1111-111111111111',
|
||||||
|
'aarav.demo@pragativeer.com',
|
||||||
|
'9911111111',
|
||||||
|
'$2b$12$LQv3c1yqBWVHxkd0LHAkCOYz6TtxMoJ8zYTvNiG0HGkY0P6YOHRV6',
|
||||||
|
'Aarav',
|
||||||
|
'TWELFTH', 'JEE_MAIN', 'ENGLISH',
|
||||||
|
'DPS RK Puram', 'New Delhi', 'Delhi',
|
||||||
|
'AI_COACH', NULL, NULL,
|
||||||
|
7, 7,
|
||||||
|
now(), now()
|
||||||
|
),
|
||||||
|
-- Demo 2: Neha — AI Coach, NEET (id: 22222222...)
|
||||||
|
(
|
||||||
|
'22222222-2222-2222-2222-222222222222',
|
||||||
|
'neha.demo@pragativeer.com',
|
||||||
|
'9922222222',
|
||||||
|
'$2b$12$LQv3c1yqBWVHxkd0LHAkCOYz6TtxMoJ8zYTvNiG0HGkY0P6YOHRV6',
|
||||||
|
'Neha',
|
||||||
|
'TWELFTH', 'NEET', 'ENGLISH',
|
||||||
|
'St. Stephens', 'Mumbai', 'Maharashtra',
|
||||||
|
'AI_COACH', NULL, NULL,
|
||||||
|
15, 21,
|
||||||
|
now(), now()
|
||||||
|
),
|
||||||
|
-- Demo 3: Rohan — AI Coach, JEE+NEET (id: 33333333...)
|
||||||
|
(
|
||||||
|
'33333333-3333-3333-3333-333333333333',
|
||||||
|
'rohan.demo@pragativeer.com',
|
||||||
|
'9933333333',
|
||||||
|
'$2b$12$LQv3c1yqBWVHxkd0LHAkCOYz6TtxMoJ8zYTvNiG0HGkY0P6YOHRV6',
|
||||||
|
'Rohan',
|
||||||
|
'DROPPER', 'JEE_NEET', 'ENGLISH',
|
||||||
|
'Allen Kota', 'Kota', 'Rajasthan',
|
||||||
|
'AI_COACH', NULL, NULL,
|
||||||
|
1, 1,
|
||||||
|
now(), now()
|
||||||
|
),
|
||||||
|
-- Demo 4: Amit — Free Plan, JEE (id: 44444444...)
|
||||||
|
-- Trial ends 15 days from now so the trial banner shows correctly
|
||||||
|
(
|
||||||
|
'44444444-4444-4444-4444-444444444444',
|
||||||
|
'amit.demo@pragativeer.com',
|
||||||
|
'9944444444',
|
||||||
|
'$2b$12$LQv3c1yqBWVHxkd0LHAkCOYz6TtxMoJ8zYTvNiG0HGkY0P6YOHRV6',
|
||||||
|
'Amit',
|
||||||
|
'ELEVENTH', 'JEE_MAIN', 'ENGLISH',
|
||||||
|
'Resonance', 'Patna', 'Bihar',
|
||||||
|
'FREE', now() + INTERVAL '15 days', NULL,
|
||||||
|
1, 1,
|
||||||
|
now(), now()
|
||||||
|
)
|
||||||
|
ON CONFLICT (id) DO UPDATE SET
|
||||||
|
name = EXCLUDED.name,
|
||||||
|
email = EXCLUDED.email,
|
||||||
|
tier = EXCLUDED.tier,
|
||||||
|
target_exam = EXCLUDED.target_exam,
|
||||||
|
student_class = EXCLUDED.student_class,
|
||||||
|
medium = EXCLUDED.medium,
|
||||||
|
school = EXCLUDED.school,
|
||||||
|
city = EXCLUDED.city,
|
||||||
|
state = EXCLUDED.state,
|
||||||
|
trial_end = EXCLUDED.trial_end,
|
||||||
|
streak_count = EXCLUDED.streak_count,
|
||||||
|
longest_streak = EXCLUDED.longest_streak,
|
||||||
|
last_active = now();
|
||||||
|
|||||||
Reference in New Issue
Block a user