Catalog backfill for Building Blocks and Playbooks
Upsert extension and stack listings from JSON after deploy or local db reset.
Connect your agent today
Draft from chat, review in your calendar, and publish only what you approve.
What this does
The listings catalog backfill applies Building Blocks (listing_kind = extension) and Playbooks (listing_kind = stack) rows from versioned JSON into:
- listings
- listings_listing_tags_association
- listing_stack_members (playbooks only)
Official hub listings use owner openquok (see user-management catalog creator seed). The runner writes slug explicitly from JSON — the secret-admin API derives slug from title, so catalog JSON must stay the source of stable slugs (for example openquok-core, viral-tiktok-carousel).
New catalog-only extensions or playbooks can ship in the repo JSON without a dedicated SQL seed migration. Operators run the script with the Supabase service role key, the same operational model as pnpm backend:db:promote-platform-admin.
| Hub | Catalog shards | CLI kind |
|---|---|---|
| Building Blocks | backend/scripts/catalog/building-blocks/*.json (e.g. openquok-core.json) | extension |
| Playbooks | backend/scripts/catalog/playbooks/*.json (e.g. viral-tiktok-carousel.json) | stack |
Runner: backend/scripts/backfill_listings_catalog.mjs
When to use this vs Secret admin
| Situation | Use |
|---|---|
| Ship a new catalog listing from the repo (append JSON, run backfill) | This CLI backfill |
| One-off copy edits, publish toggles, image upload, or stack membership tweaks on existing rows | Secret admin → Building Blocks or Playbooks |
| Pull production editorial copy into repo JSON | pnpm sync:listings-building-blocks-catalog-from-prod or pnpm sync:listings-playbooks-catalog-from-prod |
The backfill skips overwriting populated editorial fields on existing rows unless you pass --force. Secret admin remains the day-to-day editor for live copy. Image assets in JSON use HTTPS URLs only — upload new files in secret admin when needed (v1 does not upload to storage from the CLI).
Note
Run order: backfill Building Blocks before Playbooks when playbook stack_members reference extension slugs that are new or only exist in JSON.
Before you start
The script loads env from backend/.env.development.local by default (or backend/.env.production.local for production).
| Variable | Role |
|---|---|
| PUBLIC_SUPABASE_URL | Supabase project URL |
| SUPABASE_SECRET_KEY | Service role — required for direct table upserts |
Warning
This path writes through the service role and does not run the API cache invalidation that secret-admin mutations trigger. Published hub and listing-detail responses may be cached for up to about five minutes. After production backfill, wait for TTL expiry or restart your cache layer before you expect every edge to show new rows immediately.
Local development (after db reset)
SQL migrations and legacy seeds repopulate categories, tags, and exemplar listings, but catalog-only rows (JSON-only entries) are not re-inserted automatically when you reset.
Reset the local database
From backend/:
supabase db reset See Database & migrations for the full local workflow (CLI, env keys, optional typegen).
Backfill Building Blocks
From the repo root:
pnpm backend:db:backfill-listings-building-blocks Limit to one listing while testing:
pnpm backend:db:backfill-listings-building-blocks -- --dry-run --slug openquok-core Backfill Playbooks (after extensions exist)
pnpm backend:db:backfill-listings-playbooks Example dry-run for the exemplar stack:
pnpm backend:db:backfill-listings-playbooks -- --dry-run --slug viral-tiktok-carousel Verify in the app
With the web and API dev servers running, open Building Blocks and OpenQuok Core (detail URLs are /creators/{owner}/building-blocks/{slug}), then Playbooks and Viral TikTok Carousel. Confirm cards, publish state, tags, and playbook stack members match the JSON catalogs.
Note
If CACHE_ENABLED is true but Redis is not running, listing API responses can hang until cache read times out. Use a running Redis instance or disable cache in backend/.env.development.local while verifying locally.
Idempotency: run the same backfill again without --force — existing rows with editorial content should log a skip; missing rows are inserted.
Production rollout
Dry-run first:
pnpm backend:db:backfill-listings-building-blocks:prod -- --dry-run --slug openquok-core
pnpm backend:db:backfill-listings-playbooks:prod -- --dry-run --slug viral-tiktok-carousel Apply:
pnpm backend:db:backfill-listings-building-blocks:prod -- --slug openquok-core
pnpm backend:db:backfill-listings-playbooks:prod -- --slug viral-tiktok-carousel The :prod script aliases pass --env-file .env.production.local.
Command flags
| Flag | Effect |
|---|---|
| --dry-run | Log planned upserts; no writes |
| --force | Replace existing listing rows and re-sync tag associations and stack members |
| --slug openquok-core | Process only this listing slug (repeat the flag for multiple slugs) |
| --list-missing | List catalog slugs that are not yet in listings |
| --catalog <path> | Hub directory or a single <slug>.json (npm scripts point at each hub folder) |
| --kind extension\|stack | Reject entries whose listing_kind does not match (guardrail) |
| --env-file <path> | Env file relative to backend/ |
Equivalent from the backend package:
pnpm --filter ./backend run db:backfill-listings-building-blocks
pnpm --filter ./backend run db:backfill-listings-playbooks Pass script options after — when invoking from the repo root.
Idempotency and safety
- Second run without --force: Existing rows with editorial content are left intact; missing rows are inserted. Engagement counters (likes, views, ratings, bookmarks) are never reset on update.
- --force: Overwrites catalog-shaped fields and replaces tag associations from tag_slugs in JSON; for stacks, replaces listing_stack_members from stack_members.
- Stable UUIDs in the catalog keep upserts deterministic across environments. Set published_at when both publish flags are true on new or previously unpublished rows.
Adding a future catalog listing
- Add backend/scripts/catalog/building-blocks/<slug>.json or catalog/playbooks/<slug>.json with a listing object and optional stack_members array (use a new UUID; resolve category_slug and tag_slugs).
- For playbooks, add stack_members with member_listing_slug — ensure member extensions exist (backfill building blocks first).
- Run backfill with --slug <slug> in dev, then production — no migration PR required for catalog-only listings.