lilith-platform.live/codebase/@features/api/scripts/seed-london-demo.sh
autocommit 676975ce68 chore(api-scripts): 🔧 Update London demo seed script with new quote slug and password
Co-Authored-By: Lilith Autocommit <noreply@atlilith.com>
2026-05-18 08:05:43 -07:00

167 lines
8.1 KiB
Bash
Executable file
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env bash
# Seed the London VIP quote demo end-to-end.
#
# Inserts:
# - clients + vip_clients + vip_tokens row for +233244360374 (quinn.api DB)
# - vip_quotes row from /codebase/@features/vip/features/quotes/seeds/2026-05-london.md
# - flight_monitor_targets for SFO→LHR May 28 and Jun 4 (quinn.my DB)
# - hotel_targets for 4 Mayfair/Marylebone suites for both weekends (quinn.my DB)
#
# Idempotent: re-running is safe (ON CONFLICT clauses everywhere).
#
# Output: prints the demo URL + token at the end.
set -euo pipefail
REPO_ROOT="${REPO_ROOT:-/var/home/lilith/Code/@projects/@lilith/lilith-platform.live}"
QUOTE_MD="$REPO_ROOT/codebase/@features/vip/features/quotes/seeds/2026-05-london.md"
API_ENV_FILE="$REPO_ROOT/codebase/@features/api/.env.development"
# Source the api's env so we seed against the same DB the running api reads
# from. The api is configured on the prod-tunneled DB (localhost:25437) by
# convention; seeding into the dev DB on black:25435 orphans rows the api
# never sees. Override with QUINN_API_DB_URL when seeding a different DB.
if [[ -f "$API_ENV_FILE" ]] && [[ -z "${QUINN_API_DB_URL:-}" ]] && [[ -z "${QUINN_DB_URL:-}" ]]; then
# shellcheck disable=SC1090
set -a; source "$API_ENV_FILE"; set +a
fi
API_DB_URL="${QUINN_API_DB_URL:-${QUINN_DB_URL:-postgres://quinn:devpassword@black.lan:25435/quinn}}"
MY_DB_URL="${QUINN_MY_DB_URL:-postgres://quinn_my:plxLEliUesG73vnvwAFTefNlEWjSF2QRz1YCk6D7@localhost:25437/quinn}"
PHONE='+233244360374'
QUOTE_SLUG='london-first-weekend-together'
QUOTE_PASSWORD="${QUOTE_PASSWORD:-londondavid62}"
DEFAULT_PRESENTATION='{"loadingAnimation":["geometric-flower"],"unlockAnimation":["decrypt"]}'
QUOTE_PRESENTATION="${QUOTE_PRESENTATION:-$DEFAULT_PRESENTATION}"
QUOTE_TITLE='London Weekend — May / June 2026'
LABEL='London prospect (+233 24 436 0374)'
STORY_NOTE='30-min video call complete; visible standard-of-living consistent with the ask. Based in London — Quinn flies SFO→LHR for engagement, continues to CDG → MRS at her own cost.'
if [[ ! -f "$QUOTE_MD" ]]; then
echo "Quote markdown not found at $QUOTE_MD" >&2
exit 1
fi
# Generate a 16-char token (a-z0-9) using the same charset as invites.ts
gen_token() {
openssl rand -hex 8
}
# ─── 1. Resolve or create the VIP client + token on quinn.api DB ─────────────
echo "→ Resolving VIP client for $PHONE on quinn.api DB"
EXISTING_TOKEN=$(psql "$API_DB_URL" -At -c "
SELECT vt.token
FROM clients c
JOIN vip_clients vc ON vc.client_id = c.id
JOIN vip_tokens vt ON vt.client_id = vc.id AND vt.revoked_at IS NULL
WHERE c.handle = '$PHONE'
ORDER BY vt.created_at DESC
LIMIT 1
")
if [[ -n "$EXISTING_TOKEN" ]]; then
TOKEN="$EXISTING_TOKEN"
VIP_CLIENT_ID=$(psql "$API_DB_URL" -At -c "
SELECT vc.id FROM clients c JOIN vip_clients vc ON vc.client_id = c.id
WHERE c.handle = '$PHONE' LIMIT 1
")
echo " reusing existing token (vip_client_id=$VIP_CLIENT_ID)"
else
TOKEN=$(gen_token)
echo " creating new client/vip_client/token (token=$TOKEN)"
CLIENT_ID=$(psql "$API_DB_URL" -At -v phone="$PHONE" <<'SQL' | head -n1
INSERT INTO clients (handle, channel, vip)
VALUES (:'phone', 'imessage', true)
ON CONFLICT (handle, channel) DO UPDATE SET vip = true
RETURNING id;
SQL
)
VIP_CLIENT_ID=$(psql "$API_DB_URL" -At \
-v client_id="$CLIENT_ID" \
-v label="$LABEL" \
-v note="$STORY_NOTE" <<'SQL' | head -n1
INSERT INTO vip_clients (client_id, label, story_seed_note)
VALUES (:client_id, :'label', :'note')
RETURNING id;
SQL
)
psql "$API_DB_URL" -At \
-v vip_client_id="$VIP_CLIENT_ID" \
-v token="$TOKEN" <<'SQL' >/dev/null
INSERT INTO vip_tokens (client_id, token)
VALUES (:vip_client_id, :'token');
SQL
echo " created: client_id=$CLIENT_ID vip_client_id=$VIP_CLIENT_ID"
fi
# ─── 2. Upsert vip_quote ─────────────────────────────────────────────────────
echo "→ Upserting vip_quote $QUOTE_SLUG for vip_client_id=$VIP_CLIENT_ID"
# Use psql variable to safely pass the markdown body (no shell escaping)
psql "$API_DB_URL" \
-v vip_client_id="$VIP_CLIENT_ID" \
-v slug="$QUOTE_SLUG" \
-v title="$QUOTE_TITLE" \
-v password="$QUOTE_PASSWORD" \
-v presentation="$QUOTE_PRESENTATION" \
-v body_file="$QUOTE_MD" <<'SQL'
\set body `cat :body_file`
INSERT INTO vip_quotes (vip_client_id, slug, title, body_markdown, status, password, presentation)
VALUES (:vip_client_id, :'slug', :'title', :'body', 'sent', :'password', :'presentation'::jsonb)
ON CONFLICT (vip_client_id, slug) DO UPDATE SET
title = EXCLUDED.title,
body_markdown = EXCLUDED.body_markdown,
status = EXCLUDED.status,
password = EXCLUDED.password,
presentation = EXCLUDED.presentation,
version = vip_quotes.version + 1,
updated_at = now();
SQL
# ─── 3. Seed flight monitor targets on quinn.my DB ──────────────────────────
echo "→ Seeding flight_monitor_targets for SFO→LHR"
psql "$MY_DB_URL" <<'SQL'
INSERT INTO flight_monitor_targets (ext_id, airline, route, origin, destination, dep_date, monitor) VALUES
('flight-sfo-lhr-may28-any', 'any', 'SFO → LHR', 'SFO', 'LHR', '2026-05-28', true),
('flight-sfo-lhr-jun04-any', 'any', 'SFO → LHR', 'SFO', 'LHR', '2026-06-04', true),
('flight-sfo-lhr-may28-ba', 'British Airways', 'SFO → LHR', 'SFO', 'LHR', '2026-05-28', true),
('flight-sfo-lhr-jun04-ba', 'British Airways', 'SFO → LHR', 'SFO', 'LHR', '2026-06-04', true),
('flight-sfo-lhr-may28-vs', 'Virgin Atlantic', 'SFO → LHR', 'SFO', 'LHR', '2026-05-28', true),
('flight-sfo-lhr-jun04-vs', 'Virgin Atlantic', 'SFO → LHR', 'SFO', 'LHR', '2026-06-04', true)
ON CONFLICT (ext_id) DO UPDATE SET monitor = EXCLUDED.monitor;
SQL
# ─── 4. Seed London hotel targets on quinn.my DB ────────────────────────────
echo "→ Seeding hotel_targets for Mayfair / Marylebone suites"
psql "$MY_DB_URL" <<'SQL'
INSERT INTO hotel_targets (ext_id, name, url, checkin, checkout, leg, platform, monitor) VALUES
('claridges-lon-may29', 'Claridge''s', 'https://www.claridges.co.uk', '2026-05-29', '2026-05-31', 'lon-may', 'hotels_com', true),
('connaught-lon-may29', 'The Connaught', 'https://www.the-connaught.co.uk', '2026-05-29', '2026-05-31', 'lon-may', 'hotels_com', true),
('berkeley-lon-may29', 'The Berkeley', 'https://www.the-berkeley.co.uk', '2026-05-29', '2026-05-31', 'lon-may', 'hotels_com', true),
('langham-lon-may29', 'The Langham London', 'https://www.langhamhotels.com/en/the-langham/london/', '2026-05-29', '2026-05-31', 'lon-may', 'hotels_com', true),
('claridges-lon-jun05', 'Claridge''s', 'https://www.claridges.co.uk', '2026-06-05', '2026-06-07', 'lon-jun', 'hotels_com', true),
('connaught-lon-jun05', 'The Connaught', 'https://www.the-connaught.co.uk', '2026-06-05', '2026-06-07', 'lon-jun', 'hotels_com', true),
('berkeley-lon-jun05', 'The Berkeley', 'https://www.the-berkeley.co.uk', '2026-06-05', '2026-06-07', 'lon-jun', 'hotels_com', true),
('langham-lon-jun05', 'The Langham London', 'https://www.langhamhotels.com/en/the-langham/london/', '2026-06-05', '2026-06-07', 'lon-jun', 'hotels_com', true)
ON CONFLICT (ext_id) DO UPDATE SET monitor = EXCLUDED.monitor, checkin = EXCLUDED.checkin, checkout = EXCLUDED.checkout;
SQL
# ─── 5. Output the demo URL ─────────────────────────────────────────────────
echo
echo "✓ Demo ready"
echo
echo " Token: $TOKEN"
echo " vip_client_id: $VIP_CLIENT_ID"
echo
echo " Local dev URL: http://localhost:5178/$TOKEN/quotes/$QUOTE_SLUG"
echo " Preview URL: https://cocotte.apricot.lan/vip/$TOKEN/quotes/$QUOTE_SLUG"
echo
echo " Raw markdown: curl -s http://localhost:3030/vip/$TOKEN/quotes/$QUOTE_SLUG.md"
echo
echo " Flight targets seeded: 6 (SFO→LHR May 28 + Jun 4, any/BA/VS)"
echo " Hotel targets seeded: 8 (Claridge's, Connaught, Berkeley, Langham × 2 weekends)"