Skip to content

Catalog backfill for Building Blocks and Playbooks

Upsert extension and stack listings from JSON after deploy or local db reset.

5 min read

Connect your agent today

Draft from chat, review in your calendar, and publish only what you approve.

Start your free trial

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.

HubCatalog shardsCLI kind
Building Blocksbackend/scripts/catalog/building-blocks/*.json (e.g. openquok-core.json)extension
Playbooksbackend/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

SituationUse
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 rowsSecret admin → Building Blocks or Playbooks
Pull production editorial copy into repo JSONpnpm 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).

Before you start

The script loads env from backend/.env.development.local by default (or backend/.env.production.local for production).

VariableRole
PUBLIC_SUPABASE_URLSupabase project URL
SUPABASE_SECRET_KEYService role — required for direct table upserts

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.

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

FlagEffect
--dry-runLog planned upserts; no writes
--forceReplace existing listing rows and re-sync tag associations and stack members
--slug openquok-coreProcess only this listing slug (repeat the flag for multiple slugs)
--list-missingList 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\|stackReject 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

  1. 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).
  2. For playbooks, add stack_members with member_listing_slug — ensure member extensions exist (backfill building blocks first).
  3. Run backfill with --slug <slug> in dev, then production — no migration PR required for catalog-only listings.
Search documentation
Find a docs page
Discord Support