existing-app

command
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 7, 2026 License: MIT Imports: 13 Imported by: 0

README

existing-app

Bolting bun-migrator onto an app that already has models, a database handle and a CLI, rather than a fresh project built around it.

  • db.go -- the app's existing DB(), built on pgdriver directly and cached with sync.OnceValue so it dials once, on first use.
  • models.go -- Account and Widget, written before bun-migrator existed, rel: tags and all. Table reads only their plain column tags.
  • migrations.go -- the registry, in its own file, with sequence numbers 10 and 20 (not 1 and 2) so a table can be inserted later without renumbering one bun already recorded as applied.
  • main.go -- the app's existing serve subcommand, plus migrate bolted on as a second one, sharing the app's own DB() instead of opening a connection of its own.

Run it

go run ./examples/existing-app serve            # the app's existing command
go run ./examples/existing-app migrate --dry-run # what bun-migrator adds

migrate --dry-run needs no DATABASE_URL -- it never calls DB(), since rendering SQL text only needs bun's dialect, not a live connection. A real go run ./examples/existing-app migrate does call it, and so does need DATABASE_URL (or PG_*) set, same as the rest of this app already requires.

What you should see

--dry-run prints two migrations, accounts then widgets, the second depending on and following the first because of DependsOn("Account"). serve prints a one-line stub -- standing in for whatever this app already does, unchanged by adding migrate next to it.

Documentation

Overview

Command existing-app simulates bolting bun-migrator onto an app that already has models, a database handle and a CLI. serve is the app's existing subcommand; migrate is the only thing this example adds.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址