schemer

module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2025 License: MIT

README ΒΆ

Schemer

Schemer is a lightweight, delta-based database migration tool for PostgreSQL.


πŸš€ Features

  • Versioned .sql delta files (up, down, and optional post)
  • Apply deltas in order or cherry-pick specific versions
  • Post-delta support for deferred cleanup
  • Schema state tracked via a dedicated schemer table
  • Simple .env-based configuration optional
  • Built with Go β€” no runtime dependencies

πŸ“¦ Installation

go install github.com/yourusername/schemer@latest

Ensure $GOPATH/bin is in your system PATH.


πŸ“ Delta Format

Deltas live in the deltas/ directory and follow this naming convention:

<version>_<name>.<type>.sql
  • <version> β€” zero-padded integer (e.g. 001)
  • <name> β€” descriptive name (e.g. add_users)
  • <type> β€” one of up, down, or post
Example
deltas/
β”œβ”€β”€ 001_add_users.up.sql
β”œβ”€β”€ 001_add_users.down.sql
β”œβ”€β”€ 001_add_users.post.sql  # optional

πŸ›  Commands

schemer init

Initializes a new project in the current directory:

  • Creates a deltas/ directory
  • Generates a .env file with DATABASE_URL
  • Writes a schemer.sql template
Should only be used on new projects and never in a production
environment.

schemer create <name> [--post]

Creates a versioned delta group:

schemer create add_users
schemer create cleanup_sessions --post

This creates:

deltas/002_add_users.up.sql
deltas/002_add_users.down.sql
deltas/002_add_users.post.sql  # only if --post is used

schemer up [options]

Default behaviour: Applies all unapplied up deltas.

Options:

  • --from <tag> β€” start from a specific tag
  • --to <tag> β€” apply up to a tag
  • --cherry-pick <tag> <tag> β€” apply specific tags
  • --prune β€” skip no-op deltas

schemer down [options]

Default behaviour: Rolls back last applied delta.

Options:

  • --from <tag> β€” rollback from this tag
  • --to <tag> β€” rollback down to this tag
  • --cherry-pick <tag> <tag> β€” rollback specific tags
  • --prune β€” skip no-op deltas

schemer post [options]

Default behaviour: Applies all post deltas for all recorded up deltas.

Options:

  • --from <tag> / --to <tag> β€” limit range
  • --cherry-pick <tag> <tag> β€” apply specific posts
  • --force β€” apply untracked post deltas

πŸ§ͺ Examples

schemer init
schemer create create_users --post
schemer up
schemer down --from 003
schemer post --cherry-pick 003 --force

πŸ“„ .env File

In a dev environment Schemer reads the connection string from .env:

DATABASE_URL=postgres://user:pass@localhost:5432/mydb?sslmode=disable

πŸ“Š Schemer Table

A schemer table tracks:

  • Applied delta tags
  • Post delta status

It's created during init or the first migration.

Directories ΒΆ

Path Synopsis
cmd
internal

Jump to

Keyboard shortcuts

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