Skip to content

Decide host-cloudflare Postgres migration strategy: runtime ensure vs out-of-band drizzle-kit #13

Description

@amondnet

Summary

Decide (and optionally implement) the schema-migration strategy for
apps/host-cloudflare's opt-in Postgres seam: keep the current runtime
ensure
bring-up, or adopt out-of-band drizzle-kit migrations like
apps/cloud.

Follow-up to #10, which made the host-cloudflare db seam configurable (D1
default, Neon/Postgres-over-Hyperdrive opt-in). #10 intentionally deferred this
decision and shipped with runtime ensure.

Background

The Postgres seam currently brings the schema up at runtime via
ensureDrizzleRuntimeSchemaFromTables (idempotent CREATE TABLE IF NOT EXISTS

  • nullable ADD COLUMN), done once per isolate at boot. This preserves the
    template's zero-setup, self-provisioning ethos and is consistent with
    host-selfhost and apps/local. apps/cloud is the outlier: it uses generated
    drizzle-kit SQL migrations applied out-of-band (scripts/migrate.ts), because
    it is the multi-tenant production app where migration history and non-additive
    changes matter.

Decision

  • Keep runtime ensure (status quo), OR
  • Adopt out-of-band drizzle-kit migrations for the Postgres path, OR
  • Make it configurable

Options & trade-offs

Runtime ensure (current)

  • Zero deploy step, auto-provisioning; matches host-selfhost/local.
  • Cannot express non-additive changes: column rename / type change / drop,
    non-null column + backfill, data transforms. No migration history.
  • DDL runs at first-boot per isolate (idempotent, cheap, but implicit).

Out-of-band drizzle-kit (cloud-style)

  • Full migration history; supports non-additive changes and data migrations;
    reviewable SQL diffs.
  • Adds a separate db:migrate deploy step (breaks the one-command deploy), a
    static executor-schema.ts that must be hand-synced, a drizzle/ SQL folder,
    drizzle.config.ts, and scripts/migrate.ts (all cloneable from apps/cloud).

Recommendation

Keep runtime ensure for now: it fits a single-tenant, low/spiky template and
stays consistent with the other self-host apps. Revisit and adopt the
cloud-style out-of-band path the first time a non-additive schema change is
needed (the code is a near-verbatim clone of apps/cloud).

Tasks

  • Make the decision above
  • If adopting out-of-band: add drizzle.config.ts, static
    executor-schema.ts (pg), drizzle/ migrations, scripts/migrate.ts,
    and a deploy/CI migrate step; document it in README.md
  • Either way: document the chosen strategy and its limits in the
    host-cloudflare README

Related / also deferred from #10

References


Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions