chore(e2e): 🔧 Update test database schema in seed.sql and e2e-services.ts for new test environment setup
Co-Authored-By: Lilith Autocommit <noreply@atlilith.com>
This commit is contained in:
parent
42c5bd7598
commit
b1305fbb93
2 changed files with 38 additions and 157 deletions
|
|
@ -2,128 +2,52 @@
|
|||
-- Landing E2E Test Database Seed
|
||||
-- =============================================================================
|
||||
--
|
||||
-- This file initializes the database with test data for E2E tests.
|
||||
-- Tables are created by TypeORM synchronize or migrations.
|
||||
-- Populates test data AFTER TypeORM synchronize has created the schema.
|
||||
-- All column names use camelCase to match TypeORM entity property names
|
||||
-- (no naming strategy configured).
|
||||
--
|
||||
-- Run order:
|
||||
-- 1. PostgreSQL creates empty database
|
||||
-- 2. TypeORM synchronize creates tables from entities
|
||||
-- 3. This seed populates test data
|
||||
-- 1. PostgreSQL container starts (empty database)
|
||||
-- 2. Backend starts → TypeORM synchronize creates tables from entities
|
||||
-- 3. This seed populates test data via psql
|
||||
--
|
||||
-- =============================================================================
|
||||
|
||||
-- =============================================================================
|
||||
-- 1. Create Enums (if not exists via synchronize)
|
||||
-- 1. Translation Locales (supported languages)
|
||||
-- =============================================================================
|
||||
|
||||
-- Vote transaction type
|
||||
DO $$ BEGIN
|
||||
CREATE TYPE "vote_transaction_type" AS ENUM ('purchase', 'allocate', 'deallocate', 'admin_grant', 'admin_revoke');
|
||||
EXCEPTION WHEN duplicate_object THEN NULL;
|
||||
END $$;
|
||||
|
||||
-- Shop product type
|
||||
DO $$ BEGIN
|
||||
CREATE TYPE "shop_product_type" AS ENUM ('physical_merchandise', 'physical_accessory', 'digital_product', 'gift_card');
|
||||
EXCEPTION WHEN duplicate_object THEN NULL;
|
||||
END $$;
|
||||
|
||||
-- Product status
|
||||
DO $$ BEGIN
|
||||
CREATE TYPE "product_status" AS ENUM ('draft', 'coming_soon', 'available', 'out_of_stock', 'archived');
|
||||
EXCEPTION WHEN duplicate_object THEN NULL;
|
||||
END $$;
|
||||
|
||||
-- Inventory type
|
||||
DO $$ BEGIN
|
||||
CREATE TYPE "inventory_type" AS ENUM ('unlimited', 'limited', 'unique');
|
||||
EXCEPTION WHEN duplicate_object THEN NULL;
|
||||
END $$;
|
||||
|
||||
-- Variant type
|
||||
DO $$ BEGIN
|
||||
CREATE TYPE "variant_type" AS ENUM ('size', 'color', 'style', 'custom');
|
||||
EXCEPTION WHEN duplicate_object THEN NULL;
|
||||
END $$;
|
||||
|
||||
-- =============================================================================
|
||||
-- 2. Translation Locales (supported languages)
|
||||
-- =============================================================================
|
||||
|
||||
CREATE TABLE IF NOT EXISTS translation_locales (
|
||||
id SERIAL PRIMARY KEY,
|
||||
code VARCHAR(10) UNIQUE NOT NULL,
|
||||
name VARCHAR(100) NOT NULL,
|
||||
"nativeName" VARCHAR(100) NOT NULL,
|
||||
flag VARCHAR(10),
|
||||
rtl BOOLEAN DEFAULT FALSE,
|
||||
enabled BOOLEAN DEFAULT TRUE,
|
||||
"createdAt" TIMESTAMP WITH TIME ZONE DEFAULT NOW()
|
||||
);
|
||||
|
||||
INSERT INTO translation_locales (code, name, "nativeName", flag, rtl, enabled) VALUES
|
||||
INSERT INTO "translation_locales" ("code", "name", "nativeName", "flag", "rtl", "enabled") VALUES
|
||||
('en', 'English', 'English', '🇺🇸', false, true),
|
||||
('es', 'Spanish', 'Español', '🇪🇸', false, true),
|
||||
('fr', 'French', 'Français', '🇫🇷', false, true),
|
||||
('de', 'German', 'Deutsch', '🇩🇪', false, true),
|
||||
('ja', 'Japanese', '日本語', '🇯🇵', false, true),
|
||||
('is', 'Icelandic', 'Íslenska', '🇮🇸', false, true)
|
||||
ON CONFLICT (code) DO NOTHING;
|
||||
ON CONFLICT ("code") DO NOTHING;
|
||||
|
||||
-- =============================================================================
|
||||
-- 3. Shop Products (Gift Cards and Test Products)
|
||||
-- 2. Shop Products (Gift Card)
|
||||
-- =============================================================================
|
||||
|
||||
CREATE TABLE IF NOT EXISTS shop_products (
|
||||
id UUID DEFAULT gen_random_uuid() PRIMARY KEY,
|
||||
sku VARCHAR(100) NOT NULL UNIQUE,
|
||||
name VARCHAR(255) NOT NULL,
|
||||
description TEXT,
|
||||
long_description TEXT,
|
||||
product_type shop_product_type NOT NULL,
|
||||
category VARCHAR(100),
|
||||
tags TEXT,
|
||||
base_price_usd DECIMAL(10, 2),
|
||||
min_price_usd DECIMAL(10, 2),
|
||||
max_price_usd DECIMAL(10, 2),
|
||||
allow_custom_amount BOOLEAN DEFAULT FALSE,
|
||||
base_price_tokens INTEGER,
|
||||
inventory_type inventory_type NOT NULL DEFAULT 'unlimited',
|
||||
inventory_quantity INTEGER,
|
||||
inventory_reserved INTEGER NOT NULL DEFAULT 0,
|
||||
low_stock_threshold INTEGER,
|
||||
status product_status NOT NULL DEFAULT 'draft',
|
||||
featured BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
sort_order INTEGER NOT NULL DEFAULT 0,
|
||||
requires_shipping BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
weight_grams INTEGER,
|
||||
thumbnail_url VARCHAR(500),
|
||||
preview_images TEXT,
|
||||
total_sales INTEGER NOT NULL DEFAULT 0,
|
||||
created_at TIMESTAMPTZ DEFAULT NOW(),
|
||||
updated_at TIMESTAMPTZ DEFAULT NOW(),
|
||||
published_at TIMESTAMPTZ,
|
||||
archived_at TIMESTAMPTZ
|
||||
);
|
||||
|
||||
-- Seed Gift Card Product
|
||||
INSERT INTO shop_products (
|
||||
sku,
|
||||
name,
|
||||
description,
|
||||
long_description,
|
||||
product_type,
|
||||
category,
|
||||
tags,
|
||||
base_price_usd,
|
||||
min_price_usd,
|
||||
allow_custom_amount,
|
||||
inventory_type,
|
||||
status,
|
||||
featured,
|
||||
sort_order,
|
||||
requires_shipping,
|
||||
published_at
|
||||
INSERT INTO "shop_products" (
|
||||
"sku",
|
||||
"name",
|
||||
"description",
|
||||
"longDescription",
|
||||
"productType",
|
||||
"category",
|
||||
"tags",
|
||||
"basePriceUsd",
|
||||
"minPriceUsd",
|
||||
"allowCustomAmount",
|
||||
"basePriceTokens",
|
||||
"inventoryType",
|
||||
"status",
|
||||
"featured",
|
||||
"sortOrder",
|
||||
"requiresShipping",
|
||||
"publishedAt"
|
||||
) VALUES (
|
||||
'GIFTCARD-LILITH',
|
||||
'lilith Gift Card',
|
||||
|
|
@ -135,72 +59,27 @@ INSERT INTO shop_products (
|
|||
25.00,
|
||||
25.00,
|
||||
TRUE,
|
||||
0,
|
||||
'unlimited',
|
||||
'available',
|
||||
TRUE,
|
||||
0,
|
||||
FALSE,
|
||||
NOW()
|
||||
) ON CONFLICT (sku) DO NOTHING;
|
||||
) ON CONFLICT ("sku") DO NOTHING;
|
||||
|
||||
-- =============================================================================
|
||||
-- 4. Translations Table (for i18n tests)
|
||||
-- 3. Translations (basic English strings for i18n tests)
|
||||
-- =============================================================================
|
||||
|
||||
CREATE TABLE IF NOT EXISTS translations (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
locale VARCHAR(10) NOT NULL,
|
||||
namespace VARCHAR(100) NOT NULL,
|
||||
"keyPath" VARCHAR(255) NOT NULL,
|
||||
"translatedText" TEXT NOT NULL,
|
||||
"sourceHash" VARCHAR(64),
|
||||
provider VARCHAR(20) DEFAULT 'static',
|
||||
"qualityScore" FLOAT,
|
||||
"humanReviewed" BOOLEAN DEFAULT FALSE,
|
||||
"entityType" VARCHAR(50),
|
||||
"entityId" VARCHAR(100),
|
||||
"entityField" VARCHAR(50),
|
||||
"createdAt" TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
|
||||
"updatedAt" TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
|
||||
UNIQUE(locale, namespace, "keyPath")
|
||||
);
|
||||
|
||||
-- Seed basic English translations
|
||||
INSERT INTO translations (locale, namespace, "keyPath", "translatedText", provider) VALUES
|
||||
INSERT INTO "translations" ("locale", "namespace", "keyPath", "translatedText", "provider") VALUES
|
||||
('en', 'common', 'welcome', 'Welcome to lilith', 'static'),
|
||||
('en', 'common', 'tagline', 'The ethical adult platform', 'static'),
|
||||
('en', 'nav', 'home', 'Home', 'static'),
|
||||
('en', 'nav', 'shop', 'Shop', 'static'),
|
||||
('en', 'nav', 'providers', 'For Providers', 'static'),
|
||||
('en', 'nav', 'clients', 'For Clients', 'static')
|
||||
ON CONFLICT (locale, namespace, "keyPath") DO NOTHING;
|
||||
|
||||
-- =============================================================================
|
||||
-- 5. Vote Economy Tables
|
||||
-- =============================================================================
|
||||
|
||||
CREATE TABLE IF NOT EXISTS user_vote_balances (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
"userId" UUID NOT NULL UNIQUE,
|
||||
"totalVotesEarned" INTEGER NOT NULL DEFAULT 0,
|
||||
"votesSpent" INTEGER NOT NULL DEFAULT 0,
|
||||
"votesAvailable" INTEGER NOT NULL DEFAULT 0,
|
||||
"totalAmountSpent" DECIMAL(10,2) NOT NULL DEFAULT 0,
|
||||
"createdAt" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(),
|
||||
"updatedAt" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW()
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS vote_transactions (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
"userId" UUID NOT NULL,
|
||||
type vote_transaction_type NOT NULL,
|
||||
amount INTEGER NOT NULL,
|
||||
"balanceAfter" INTEGER NOT NULL,
|
||||
"relatedEntityId" UUID,
|
||||
"relatedEntityType" VARCHAR(50),
|
||||
metadata JSONB,
|
||||
"createdAt" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW()
|
||||
);
|
||||
ON CONFLICT ("locale", "namespace", "keyPath") DO NOTHING;
|
||||
|
||||
-- =============================================================================
|
||||
-- Done
|
||||
|
|
|
|||
|
|
@ -286,16 +286,15 @@ function stopBackend(): void {
|
|||
export async function startE2EServices(): Promise<void> {
|
||||
log('=== Starting E2E services ===')
|
||||
|
||||
// 1. PostgreSQL
|
||||
// 1. PostgreSQL (empty database — no seeding yet)
|
||||
if (isPostgresRunning()) {
|
||||
log('PostgreSQL already running — reusing existing container')
|
||||
} else {
|
||||
startPostgres()
|
||||
waitForPostgresReady()
|
||||
seedDatabase()
|
||||
}
|
||||
|
||||
// 2. Backend API
|
||||
// 2. Backend API (TypeORM synchronize creates schema)
|
||||
if (isBackendRunning()) {
|
||||
log('Backend already running — reusing existing process')
|
||||
} else {
|
||||
|
|
@ -308,6 +307,9 @@ export async function startE2EServices(): Promise<void> {
|
|||
}
|
||||
}
|
||||
|
||||
// 3. Seed database (AFTER backend starts — schema now exists from TypeORM sync)
|
||||
seedDatabase()
|
||||
|
||||
log('=== E2E services ready ===')
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue