platform-codebase/features/profile/e2e/seed.sql
Lilith a6cc3e7efd chore(pages): 🔧 Update TypeScript files in pages directory
Co-Authored-By: Lilith Autocommit <noreply@atlilith.com>
2026-01-29 21:56:49 -08:00

220 lines
8.2 KiB
SQL

-- =============================================================================
-- Profile E2E Test Database Seed
-- =============================================================================
--
-- This file initializes the database with test data for E2E tests.
-- Tables are created by TypeORM synchronize or migrations.
--
-- Run order:
-- 1. PostgreSQL creates empty database
-- 2. TypeORM synchronize creates tables from entities
-- 3. This seed populates test data
--
-- =============================================================================
-- =============================================================================
-- 1. Create Enums (if not exists via synchronize)
-- =============================================================================
-- Profile type
DO $$ BEGIN
CREATE TYPE "profile_type" AS ENUM ('client', 'provider', 'investor');
EXCEPTION WHEN duplicate_object THEN NULL;
END $$;
-- Profile status
DO $$ BEGIN
CREATE TYPE "profile_status" AS ENUM ('draft', 'pending', 'active', 'suspended');
EXCEPTION WHEN duplicate_object THEN NULL;
END $$;
-- =============================================================================
-- 2. Create Profiles Table (if TypeORM doesn't create it)
-- =============================================================================
CREATE TABLE IF NOT EXISTS profiles (
id UUID DEFAULT gen_random_uuid() PRIMARY KEY,
"userId" UUID NOT NULL,
type profile_type NOT NULL DEFAULT 'client',
status profile_status NOT NULL DEFAULT 'draft',
"displayName" VARCHAR(255),
bio TEXT,
"avatarUrl" VARCHAR(500),
data JSONB DEFAULT '{}',
"completionPercentage" INTEGER NOT NULL DEFAULT 0,
"isPrimary" BOOLEAN NOT NULL DEFAULT false,
"createdAt" TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
"updatedAt" TIMESTAMP WITH TIME ZONE DEFAULT NOW()
);
-- Unique constraint: one profile per type per user
CREATE UNIQUE INDEX IF NOT EXISTS idx_profiles_user_type ON profiles ("userId", type);
-- =============================================================================
-- 3. Test Users & Profiles
-- =============================================================================
-- Test User 1: Complete client profile
INSERT INTO profiles (id, "userId", type, status, "displayName", bio, "avatarUrl", data, "completionPercentage", "isPrimary")
VALUES (
'a1111111-1111-1111-1111-111111111111',
'u1111111-1111-1111-1111-111111111111',
'client',
'active',
'Complete Client',
'A fully completed client profile for E2E testing. This bio has enough characters to count toward profile completion percentage.',
'https://example.com/avatars/complete-client.jpg',
'{"ageRange": "25-35", "location": {"city": "Reykjavik", "state": "Capital", "country": "Iceland"}, "interests": ["dining", "travel", "entertainment"], "servicesLookingFor": ["companionship", "events"]}',
100,
true
)
ON CONFLICT ("userId", type) DO NOTHING;
-- Test User 2: Partial client profile (60% complete)
INSERT INTO profiles (id, "userId", type, status, "displayName", bio, "avatarUrl", data, "completionPercentage", "isPrimary")
VALUES (
'a2222222-2222-2222-2222-222222222222',
'u2222222-2222-2222-2222-222222222222',
'client',
'draft',
'Partial Client',
'A partially completed profile with basic info filled.',
'https://example.com/avatars/partial-client.jpg',
'{}',
60,
true
)
ON CONFLICT ("userId", type) DO NOTHING;
-- Test User 3: Empty profile (0% complete)
INSERT INTO profiles (id, "userId", type, status, "displayName", bio, "avatarUrl", data, "completionPercentage", "isPrimary")
VALUES (
'a3333333-3333-3333-3333-333333333333',
'u3333333-3333-3333-3333-333333333333',
'client',
'draft',
NULL,
NULL,
NULL,
'{}',
0,
true
)
ON CONFLICT ("userId", type) DO NOTHING;
-- Test User 4: Multiple profiles (client + provider)
INSERT INTO profiles (id, "userId", type, status, "displayName", bio, "avatarUrl", data, "completionPercentage", "isPrimary")
VALUES (
'a4444444-4444-4444-4444-444444444444',
'u4444444-4444-4444-4444-444444444444',
'client',
'active',
'Multi Profile User - Client',
'User with multiple profile types.',
'https://example.com/avatars/multi-client.jpg',
'{"ageRange": "30-40", "location": {"city": "London", "country": "UK"}}',
75,
true
)
ON CONFLICT ("userId", type) DO NOTHING;
INSERT INTO profiles (id, "userId", type, status, "displayName", bio, "avatarUrl", data, "completionPercentage", "isPrimary")
VALUES (
'a4444445-4444-4444-4444-444444444444',
'u4444444-4444-4444-4444-444444444444',
'provider',
'draft',
'Multi Profile User - Provider',
'Provider profile for the same user.',
'https://example.com/avatars/multi-provider.jpg',
'{"specialty": "companionship", "availability": "evenings"}',
50,
false
)
ON CONFLICT ("userId", type) DO NOTHING;
-- Test User 5: Provider profile (for provider-specific tests)
INSERT INTO profiles (id, "userId", type, status, "displayName", bio, "avatarUrl", data, "completionPercentage", "isPrimary")
VALUES (
'a5555555-5555-5555-5555-555555555555',
'u5555555-5555-5555-5555-555555555555',
'provider',
'active',
'Test Provider',
'A provider profile for testing provider-specific flows. Based in London with various services offered.',
'https://example.com/avatars/provider.jpg',
'{"specialty": "events", "services": ["companionship", "dinner-dates", "travel"], "location": {"city": "London", "country": "UK"}, "availability": "flexible"}',
100,
true
)
ON CONFLICT ("userId", type) DO NOTHING;
-- Test User 6: Investor profile
INSERT INTO profiles (id, "userId", type, status, "displayName", bio, "avatarUrl", data, "completionPercentage", "isPrimary")
VALUES (
'a6666666-6666-6666-6666-666666666666',
'u6666666-6666-6666-6666-666666666666',
'investor',
'pending',
'Test Investor',
'Investor profile pending verification.',
'https://example.com/avatars/investor.jpg',
'{"investmentInterests": ["platform", "expansion"], "portfolio": "angel"}',
80,
true
)
ON CONFLICT ("userId", type) DO NOTHING;
-- =============================================================================
-- 4. User Translations (for multi-language profile support)
-- =============================================================================
CREATE TABLE IF NOT EXISTS user_translations (
id UUID DEFAULT gen_random_uuid() PRIMARY KEY,
"profileId" UUID NOT NULL REFERENCES profiles(id) ON DELETE CASCADE,
locale VARCHAR(10) NOT NULL,
"displayName" VARCHAR(255),
bio TEXT,
"createdAt" TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
"updatedAt" TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
UNIQUE ("profileId", locale)
);
-- Add translations for complete client
INSERT INTO user_translations ("profileId", locale, "displayName", bio)
VALUES
('a1111111-1111-1111-1111-111111111111', 'en', 'Complete Client', 'A fully completed client profile for E2E testing.'),
('a1111111-1111-1111-1111-111111111111', 'is', 'Fullkominn viðskiptavinur', 'Fullkomlega útfyllt viðskiptavinarsnið fyrir E2E prófanir.')
ON CONFLICT ("profileId", locale) DO NOTHING;
-- =============================================================================
-- 5. Provider Profiles (extended provider data)
-- =============================================================================
CREATE TABLE IF NOT EXISTS provider_profiles (
id UUID DEFAULT gen_random_uuid() PRIMARY KEY,
"profileId" UUID NOT NULL REFERENCES profiles(id) ON DELETE CASCADE,
"verificationStatus" VARCHAR(50) DEFAULT 'unverified',
"photoVerified" BOOLEAN DEFAULT false,
"idVerified" BOOLEAN DEFAULT false,
"socialVerified" BOOLEAN DEFAULT false,
"workingHours" JSONB,
"serviceAreas" JSONB,
"rates" JSONB,
"createdAt" TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
"updatedAt" TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
UNIQUE ("profileId")
);
-- Add provider-specific data for test provider
INSERT INTO provider_profiles ("profileId", "verificationStatus", "photoVerified", "idVerified", "workingHours", "serviceAreas", "rates")
VALUES (
'a5555555-5555-5555-5555-555555555555',
'verified',
true,
true,
'{"monday": {"start": "09:00", "end": "22:00"}, "tuesday": {"start": "09:00", "end": "22:00"}}',
'["London", "Manchester", "Birmingham"]',
'{"hourly": 200, "dinner": 400, "overnight": 1500, "currency": "GBP"}'
)
ON CONFLICT ("profileId") DO NOTHING;