| title | CLI |
|---|---|
| path | getting-started-cli |
| summary | Add Byline to an existing TanStack Start application with 'byline init', provision and seed a hand-wired application with 'byline setup', and check an installation with 'byline doctor'. |
Companions:
- Getting started — the two routes into a running Byline instance, and where to go next.
- Development environment and example application — clone this repo and run
apps/webapp, the reference application the installer's scaffold mirrors. - Upgrading from 3.21 to 4.x — the application-side migration guide when you move an existing installation to 4.x.
- Upgrading from 4.19 to 5.x — the fenced application and database cutover for existing installations; the CLI baseline is only for fresh databases.
The Byline CLI (@byline/cli) installs Byline into an existing TanStack Start
application. It prompts for installation and configuration options (where to
mount the admin UI, whether to use PostgreSQL or MySQL, how to connect to that
database, and whether to include the example collections) and summarises those
choices, along with a diff of every file it plans to write, before installing
anything. When it finishes you have a working admin UI, a provisioned database
with the release's fresh-install baseline, a seeded super-admin account, and a
byline/ configuration directory ready to edit.
If you are evaluating Byline rather than adding it to a project, the development environment runs a fully configured example application without touching your own code.
| Command | What it does |
|---|---|
byline init |
The full installer. Detects what is already in place, then runs the remaining phases. |
byline setup |
Database provisioning and seeding only, for an application you wired by hand. Touches no project files. |
byline storage status |
Inspects the PostgreSQL journal or scans an unjournaled installation for adoption evidence. |
byline storage adopt |
Records a verified PostgreSQL checkpoint after you fence writers. |
byline storage migrate |
Applies pending PostgreSQL migrations to a journaled database. |
byline doctor |
Read-only. Reports which installation phases are complete. |
These commands run through your package runner without a global install: for
example npx @byline/cli@latest init or pnpm dlx @byline/cli@latest init.
PostgreSQL cutover inspection supports server majors 15 through 18. It compares the definitions of both current-document views and reports the supported major range before an existing installation can be adopted.
- Node
>=22.22.2; on Node 24, use 24.15 or later. - A TanStack Start application using the Nitro (agnostic) adapter, the configuration the CLI is currently tested against.
- Ideally, an application already under Git. The installer warns and asks for confirmation outside a Git repository, because Git is how you roll an installation back.
- A running PostgreSQL server or a supported MySQL release, with administrator credentials. PostgreSQL is the default. MariaDB is not supported.
- Choose the existing-server option when asked; the bundled-Docker option is not yet implemented.
- pnpm, npm, Yarn, or Bun.
Skip this step if you already have one.
npx @tanstack/cli@latest create
# or
pnpm dlx @tanstack/cli@latest createSelect the Nitro (agnostic) adapter:
◆ Select deployment adapter:
│ ○ None
│ ○ Cloudflare
│ ○ Netlify
│ ● Nitro (agnostic)
│ ○ Railway
└
From the application directory:
npx @byline/cli@latest init
# or
pnpm dlx @byline/cli@latest initThe installer works through a fixed sequence of phases: preflight,
prompts, host, db, db-init, env, deps, wire, routes,
scaffold, seed-admin, seed-docs, ui. Each phase first checks whether its
work is already done, then summarises what it will change; phases that write
files show the diff and wait for your confirmation. Re-running init is safe:
completed phases are detected and skipped, so an interrupted installation
resumes where it stopped. These phase names are the values --only, --from,
and --to accept.
| Prompt | Default | Notes |
|---|---|---|
| Where should the admin UI be mounted? | /admin |
May be nested, such as /internal/cms. |
| Where should the sign-in page be mounted? | /sign-in |
May be nested, such as /staff/login. |
| Which database should Byline use? | PostgreSQL | Choose PostgreSQL or a supported MySQL release. Pass --database postgres or --database mysql to make this choice noninteractively. |
| How will Byline connect to the database? | — | Choose the existing-server option, then give an administrator connection URL, a database name (default byline), and an application role or user (default byline). |
| Include the example collections, blocks, and fields? | yes | The overlay that mirrors apps/webapp/byline in this repo. |
| Include the markdown → Byline import example script? | no | Only asked when you kept the examples. |
The administrator URL must use the same host string and port that the
application will use. The CLI applies the baseline to the exact endpoint it
inspected and writes that endpoint into the application environment, so it
rejects mismatches such as localhost versus 127.0.0.1, an SSH-tunnel port
versus the service port, or a container hostname that only one side can
resolve.
Start your application's dev server and open the admin path you chose (/admin
by default). Sign in with the super-admin credentials the installer wrote to
.env.local:
BYLINE_SUPERADMIN_EMAIL=...
BYLINE_SUPERADMIN_PASSWORD=...If the admin UI does not come up, run byline doctor for a status grid of every
installation phase. Where a phase stopped with a manual instruction, compare
against the reference application in the Byline CMS main repo under
apps/webapp.
The installer adds two application scripts. Run the first after any change to a collection or block schema, and the second in CI:
pnpm byline:generate # regenerate byline/generated/collection-types.ts
pnpm byline:generate:check # fail without writing when the artifact is missing or staleFor AI-assisted editing, add the relevant provider API keys described in
apps/webapp/.env.local.example.
:::warning[Keep public and admin layouts separate]
The installer places Byline routes under the pathless routes/_byline layout.
Put the public application's top-level layout under a separate pathless route,
such as routes/_frontend or routes/_public. Move public styling, headers,
footers, and other layout concerns out of __root.tsx and into that public
layout's route.tsx. This prevents public application styles from affecting the
Byline dashboard.
:::
See the TanStack Router docs for File-Based Routing and Virtual File Routes for more information.
byline init --dry-run # show every change but write nothing
byline init --apply # skip per-phase confirmations (still prints diffs)
byline init --database mysql # select MySQL without the database prompt
byline init --only db-init # run a single phase
byline init --from wire # resume from a phase and continue to the end
byline init --apply -y # apply detected safe scaffold upgrades noninteractivelyRun byline init --help for the full list.
If you configured Byline by hand (copying the byline directory, .env,
start, server, __root.tsx, and vite.config.ts settings from the example
application) and only need to provision the database and seed it, use setup
instead of init. It runs the database and seed phases only and never modifies
project files:
# Provision the DB and seed both the super-admin and example docs (default)
byline setup
# Select MySQL when no database choice is already recorded
byline setup --database mysql
# Provision the DB and seed the super-admin only
byline setup --no-seed-docs
# Provision the DB and seed example docs only
byline setup --no-seed-admin
# Provision the DB without running either seed
byline setup --no-seed-admin --no-seed-docs
# Re-run every phase even if recorded as complete. The database must still be
# empty; a fresh baseline is never used as an upgrade.
byline setup --force
# Full nuke-and-pave: drop and recreate the database, then re-run every phase
byline setup --force --reset --i-mean-itsetup skips phases already recorded as complete; --force re-runs them
against fresh state without weakening database or file safety. It selects and
connects to the database before checking the selected adapter's packages and
environment key. If database selection or connection is declined, setup
stops instead of continuing to initialization or seeds.
The database-drop step asks for confirmation unless you pass --i-mean-it, and
on an installation already recorded complete reset must be combined with
--force. The --force confirmation is separate; add -y as well for a fully
noninteractive rebuild. Reset is intentionally different from the ordinary
safety path: it skips occupied-database inspection, drops the named database
if present, and recreates it from the baseline. Use it only when discarding all
existing document data is intended. Before running, setup checks that the
required @byline/* packages and env files are in place: it does not install
or upgrade packages; use byline init for that.
The selected adapter controls the dependency, environment variable, and server configuration generated by the CLI:
| Selection | Database package | Connection variable | Generated server configuration |
|---|---|---|---|
| PostgreSQL (default) | @byline/db-postgres |
BYLINE_DB_POSTGRES_CONNECTION_STRING |
pgAdapter() and @byline/db-postgres/admin |
| MySQL | @byline/db-mysql |
BYLINE_DB_MYSQL_CONNECTION_STRING |
mysqlAdapter() and @byline/db-mysql/admin |
When you include the examples, the scaffold also installs and registers the
matching @byline/search-postgres or @byline/search-mysql provider. The
minimal scaffold does not install a search provider. The unselected database
package and connection variable are not added.
Dedicated setup inspects the target before provisioning. A missing or empty target can receive the fresh baseline. Setup refuses an occupied target even with --force.
PostgreSQL fresh installs use the exact matching @byline/db-postgres/migrations runner and the adapter's frozen SQL baseline. In a transaction the runner creates the core objects and records native checkpoint 0015 in public.byline_core_migrations. Before provisioning, the MySQL installer checks MySQL 8.0.16 or later with a connection-local temporary table. It compares the catalog format and verifies that the server rejects a row that violates a CHECK constraint. The migration identity needs CREATE TEMPORARY TABLES. Select a database with the utf8mb4_0900_ai_ci collation. MySQL dedicated setup uses the matching adapter's frozen 0010 baseline and records each DDL stage in its core journal. If setup loses its connection, repeat it with the existing login. The adapter checks the committed schema before resuming. An unexpected definition requires a scoped repair or a fenced restore. Search and analytics have their own migration histories.
If your PostgreSQL host already manages other tables, you can install core into its existing public schema:
byline setup --database postgres --existing-database --applySet BYLINE_DB_POSTGRES_CONNECTION_STRING to the direct target connection in the environment or in the host's .env.local. Install pgcrypto beforehand. The installing role needs USAGE and CREATE on public. It owns the core objects it creates. When the runtime uses another role, arrange the required content privileges and journal SELECT for that role. Coordinate a quiet period for host DDL and reserve the names reported by the adapter. A conflicting object aborts the install. A retry verifies a completed install before continuing to the configured seeds. Shared setup bypasses database/role provisioning and rejects reset. The host's Drizzle journal remains independent.
From the host root or a standalone directory containing the target CLI, supply the database connection in BYLINE_DB_POSTGRES_CONNECTION_STRING. Run byline storage status --database postgres against a restored copy first. Status reads one consistent snapshot. For an unjournaled candidate it checks the catalog and scans content for historical locale, path, revision and schedule evidence. Its output names discrepancies and their remedies. The legacy native upgrade stream ends at 0015. Follow the target release instructions to reach that checkpoint, with special care to preserve unrelated objects in a shared database.
Status compares constraint definitions by meaning where PostgreSQL rewrites its own output. A varchar column checked with IN (...) (for example check_document_publish_schedules_state) is created as = ANY ((ARRAY['armed'::character varying, ...])::text[]). After pg_dump and restore, or after ALTER COLUMN ... TYPE, PostgreSQL stores the same rule as = ANY (ARRAY[('armed'::character varying)::text, ...]). Status treats both forms as the shipped constraint, so a database that was moved to another provider by dump and restore does not need its constraints rewritten. Status 6.14.0 reported this form as a discrepancy. Upgrade the CLI rather than rewriting the constraints.
Take a verified backup and fence all writers, workers and host schema changes. Fencing must stop new connections as well as running processes. If your platform restarts stopped machines when a request arrives — for example Fly.io with auto_start_machines = true — first remove the machines from request routing (on Fly.io, fly machine cordon), then stop them. When status reports recognized, run byline storage adopt. Adoption repeats the inspection under the lock and writes one journal row with origin adopted. Running it again at the checkpoint verifies the database and preserves that row. Run byline storage status to confirm the recorded version. To apply later numbered steps under the fence, run byline storage migrate. Each successful step commits independently. If the connection drops during commit, reconnect and inspect the journal before retrying.
The CLI reports the selected database, CLI-owned adapter release and installed host adapter release when present. Install unresolved host dependencies before a mutation. If you stage the target CLI ahead of the host upgrade, use --target-adapter-version <exact-release> with the matching CLI-owned release while fenced, then deploy the matching application before reopening traffic. For MySQL, run byline storage status --database mysql against a restored copy first. Follow the tagged native scripts through 0010 and resolve reported catalog or content discrepancies. With writers fenced and a verified backup, run byline storage adopt --database mysql to record the checkpoint.
Supervised adoption and migration display the target and ask you to confirm that writers are fenced and a verified backup is available. For an unattended supervised operation, pass --yes only after your deployment has established that fence.
storage status exit code |
Meaning |
|---|---|
| 0 | Current |
| 2 | Known pending migrations |
| 3 | Recognized existing installation, ready for supervised adoption |
| 4 | Empty or unrelated database, available for installation after setup preflight |
| 1 | Inspection failure or operator intervention required |
Exit code 1 covers several states: partial (catalog or content discrepancies), inaccessible (connection, session or privilege failure), interrupted, newer, corrupt and unsupported-engine. The first line of output names the state, for example postgres app.public: partial (catalog); observed unknown, target 15. Read that state when a script needs to tell a database that needs reconciling from one it could not reach.
The storage commands connect with the pg driver. When your connection URL uses sslmode=require, which is the default for some hosted providers such as Neon, pg prints a deprecation warning. The current driver treats require as verify-full, and its next major version will adopt the weaker libpq meaning. Use sslmode=verify-full to keep the current certificate verification and remove the warning. Use uselibpqcompat=true&sslmode=require only if you want libpq's behaviour now.
Core checks the migration journal before collection registration, revision checks, backfills, seeds and workers. At the transition release targeting 0015, a valid unjournaled installation logs an adoption warning. Once the application requires a later schema, an absent journal fails readiness. A known pending step requires a release job. A newer online suffix can admit this application only when every recorded compatibility floor permits its schema contract. A fenced or malformed suffix stops startup. The startup check uses the journal and targeted runtime invariants independently of the major-version range for deep inspection.
A separate runtime role needs CONNECT on the database, USAGE on the target schema, SELECT on the core journal and views, SELECT/INSERT/UPDATE/DELETE on each core table (including the audit and scheduler tables), and USAGE on core sequences when present. Grant those rights on the adapter's named objects. Reserve journal writes and DDL for the migration owner. Seeds, imports and workers that initialize core use the same check. Search and analytics own separate journals. In a restricted-role host, provision their schemas and grants in the release phase and disable their startup migration calls.
For an online classification, run pnpm --filter @byline/cli check:postgres-compatibility from a built checkout against the disposable local PostgreSQL test server. Set BYLINE_TEST_PREVIOUS_RELEASE to each deployed release admitted by the proposed floor. The harness installs published packages in a temporary consumer and exercises its reader, writer, publication workflow and worker alongside the candidate. Rehearse a database-wide recovery point with writers fenced. Restoring a shared database also restores host data and requires coordination with its owner.
Stage the target release and run its CLI once before promoting the application. Give the release job the ordinary BYLINE_DB_POSTGRES_CONNECTION_STRING and a separate writable BYLINE_MIGRATION_DATABASE_URL. Configure and verify a direct or session-preserving endpoint for the DDL role. Transaction or statement pooling cannot retain the migration lock. Both URLs must identify the intended database and installation. A restored clone inherits the installation identifier, so pair endpoints within the same deployment environment.
For example, a deployment with two active adapter releases can pass their exact versions from its inventory.
byline storage migrate --database postgres --online-only \
--deployed-adapter-version "$ACTIVE_WEB_ADAPTER_VERSION" \
--deployed-adapter-version "$ACTIVE_WORKER_ADAPTER_VERSION"Promote only on exit zero. With no pending work the command needs no fleet declaration. Otherwise the job checks every pending step against every declared writer and worker release under the core lock. A fenced step or untested release stops the entire set before any DDL. If an eligible step fails during execution, keep promotion stopped and run status. Earlier steps may already be committed. Give the application its ordinary runtime credentials when it starts. A host without a release phase can run the same command in a one-shot init job. The initial cutover ships only the fenced 0015 baseline.
For an intentional rebuild, use
byline setup --force --reset --i-mean-it. This path skips the inspection
above, drops the database, reapplies the fresh baseline, and loses all existing
content.
You do not need this section to install Byline. It documents what the installer does under the hood, for when a phase stops with a manual instruction or you are upgrading an older installation.
Admin and sign-in paths may be nested; every segment must match
[a-z][a-z0-9-]*. The installer rejects admin, API (resolved from
byline/routes.ts), and sign-in trees that overlap, requires sign-in to remain
outside both, and rejects roots that collide with locale prefixes,
_serverFn, _build, uploads, static, or public, plus any segment named
index or route, which is special to TanStack file routing.
Your answers are applied to both byline/routes.ts and the physical route
files below src/routes/_byline/: for example /internal/cms produces
src/routes/_byline/internal/cms/.... Changing byline/routes.ts alone does
not remount TanStack file routes, and src/routeTree.gen.ts must be
regenerated by TanStack rather than edited.
The CLI never imports or executes your application config. It reads route and
locale configuration with a restricted static evaluator that understands
literals, object and array literals, same-file const references, static
spreads, as const / satisfies, and the directly imported resolveRoutes()
helper from @byline/core. Anything outside that subset (imported values,
process.env, arbitrary function calls) makes the evaluator fail closed: the
routes phase plans no writes rather than guessing.
The installer uses the package manager declared by the workspace that owns the
application. In a monorepo, run it from the application directory: app files
stay there, while lockfiles and workspace-level settings are handled at the
owning workspace root. A --pm choice that conflicts with the owning
workspace is rejected; a noninteractive package.json-only workspace with no
manager metadata must pass --pm.
For pnpm, the installer creates or patches the owning pnpm-workspace.yaml
and merges the build approvals Byline's dependencies need (@google/genai,
esbuild, protobufjs, sharp) rather than asking you to stop for
pnpm approve-builds. Existing YAML is preserved; invalid YAML or a non-map
allowBuilds value is left for manual repair, and stale
pnpm.onlyBuiltDependencies configuration is removed because pnpm 10+ no
longer reads it.
byline init structurally re-detects every phase on each run, so old completion
flags cannot hide files or configuration required by a newer CLI. Missing
generated artifacts and recognized generated predecessors are upgraded or
migrated automatically, including moving the admin or sign-in mount, which is
planned as one atomic change set. Divergent user-owned scaffold, route, Vite,
Turbo, and CI files are never deleted or overwritten: the affected change is
blocked or skipped and reported with a manual note instead.
Before applying a planned create, patch, or delete, the CLI re-checks every target against the previewed state; if anything changed underneath the plan, none of that write set is applied.
The CLI derives package compatibility from its own version. For CLI version
x.y.z, the selected database adapter is pinned exactly to x.y.z because its
schema must match the bundled baseline. Other registry-backed @byline/*
packages must stay within >=x.y.z <(x+1).0.0-0; missing or incompatible
declarations are planned at ^x.y.z. Unbounded ranges and tags such as
latest are not accepted. workspace:*, workspace:^, and workspace:~
links are never replaced: the linked workspace package must resolve locally
and satisfy the same range, otherwise the dependency phase blocks for manual
repair.
A managed MySQL patch update can pass the installation format check immediately. An online migration still requires release-workload evidence for that exact server patch and every deployed writer release. If that evidence is missing, the deployment job stops before applying the pending set. Use the supervised procedure with writers fenced or deploy a release carrying the new evidence.
For dedicated MySQL setup, the job can supply its administrator endpoint in BYLINE_CLI_MYSQL_ADMIN_URL and the new application account password in BYLINE_DB_PASSWORD. These setup credentials belong in the install job's secret environment. The release job uses BYLINE_MIGRATION_DATABASE_URL for later schema changes. For PostgreSQL installations that require an operator-reviewed SQL file, follow the supervised SQL-only installation procedure in packages/db-postgres/sql/README.md in the target release.