Documentation
¶
Overview ¶
Package shmigrate implements sqlmigrate.Runner by generating POSIX shell commands that reference migration files on disk. It is used by the sql-migrate CLI to produce scripts that can be piped to sh.
Index ¶
Constants ¶
const ShHeader = `#!/bin/sh
set -e
set -u
if test -s ./.env; then
. ./.env
fi
`
ShHeader is the standard header for generated shell scripts.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Migrator ¶
type Migrator struct {
// Writer receives the generated shell script.
Writer io.Writer
// SqlCommand is the shell command template with %s for the file path.
// Example: `psql "$PG_URL" -v ON_ERROR_STOP=on -A -t --file %s`
SqlCommand string
// MigrationsDir is the path to the migrations directory on disk.
MigrationsDir string
// LogQueryPath is the path to the _migrations.sql query file.
// Used to sync the migrations log after each migration.
LogQueryPath string
// LogPath is the path to the migrations.log file.
LogPath string
// FS is an optional filesystem for reading the migrations log.
// When nil, the OS filesystem is used.
FS fs.FS
// contains filtered or unexported fields
}
Migrator generates shell scripts for migration execution. It implements sqlmigrate.Migrator so it can be used with sqlmigrate.Up, sqlmigrate.Down, and sqlmigrate.GetStatus.
func (*Migrator) Applied ¶
Applied reads the migrations log file and returns applied migrations. Supports two formats:
- New: "id\tname" (tab-separated, written by updated _migrations.sql)
- Old: "name" (name only, for backwards compatibility)
Returns an empty slice if the file does not exist. When FS is set, reads from that filesystem; otherwise reads from the OS filesystem.
func (*Migrator) ExecDown ¶
ExecDown outputs a shell command to run the .down.sql migration file. The sql parameter is ignored — shmigrate references files on disk.