Waypoint
Lightweight, Flyway-compatible PostgreSQL migration tool built in Rust.
- Fast — single static binary, ~30MB Docker image
- Flyway-compatible — same migration naming, CRC32 checksums, JDBC URL support
- Production-ready — TLS via rustls, advisory locking, structured logging, retry with backoff
- Drop-in Docker replacement — same env vars as Flyway containers
Install
CLI from crates.io
CLI from source
Library
[]
= "0.1"
= { = "1", = ["rt-multi-thread", "macros"] }
Docker
Quick Start
# Apply migrations
# Show migration status
# Validate applied migrations
Migration Files
Place SQL files in your migrations directory:
db/migrations/
V1__Create_users.sql
V1.1__Add_email_column.sql
V2__Create_orders.sql
R__Create_user_view.sql
- Versioned —
V{version}__{description}.sql— applied once, in order - Repeatable —
R__{description}.sql— re-applied when checksum changes
Commands
| Command | Description |
|---|---|
migrate |
Apply pending migrations |
info |
Show migration status |
validate |
Verify applied migrations match local files |
repair |
Remove failed entries, update checksums |
baseline |
Mark an existing database at a version |
clean |
Drop all objects in managed schemas (requires --allow-clean) |
Configuration
Config is resolved in priority order (highest wins):
- CLI arguments
- Environment variables (
WAYPOINT_DATABASE_URL, etc.) waypoint.toml(override path with-c)- Built-in defaults
waypoint.toml
[]
= "postgres://user:pass@localhost:5432/mydb"
= 5
= "prefer" # disable | prefer | require
= 30 # seconds
= 0 # seconds, 0 = no limit
[]
= ["db/migrations"]
= "public"
= "waypoint_schema_history"
= false
= true
= "1"
[]
= "production"
= "myapp"
Environment Variables
| Variable | Description |
|---|---|
WAYPOINT_DATABASE_URL |
Database connection URL |
WAYPOINT_SSL_MODE |
TLS mode: disable, prefer, require |
WAYPOINT_CONNECT_TIMEOUT |
Connection timeout in seconds |
WAYPOINT_STATEMENT_TIMEOUT |
Statement timeout in seconds |
WAYPOINT_MIGRATIONS_LOCATIONS |
Comma-separated migration paths |
WAYPOINT_MIGRATIONS_SCHEMA |
Target schema |
WAYPOINT_MIGRATIONS_TABLE |
History table name |
WAYPOINT_PLACEHOLDER_{KEY} |
Set placeholder value |
CLI Flags
waypoint [OPTIONS] <COMMAND>
Options:
-c, --config <PATH> Config file path
--url <URL> Database URL
--schema <SCHEMA> Target schema
--table <TABLE> History table name
--locations <PATHS> Migration locations (comma-separated)
--connect-retries <N> Connection retry attempts
--ssl-mode <MODE> TLS mode: disable, prefer, require
--connect-timeout <SECS> Connection timeout (default: 30)
--statement-timeout <SECS> Statement timeout (default: 0)
--out-of-order Allow out-of-order migrations
--json Output as JSON
--dry-run Preview without applying changes
-q, --quiet Suppress non-essential output
-v, --verbose Enable debug output
Docker
Drop-in replacement for Flyway containers. Same environment variables work:
Docker Compose
services:
db:
image: postgres:16
environment:
POSTGRES_USER: app
POSTGRES_PASSWORD: secret
POSTGRES_DB: myapp
healthcheck:
test:
interval: 5s
timeout: 5s
retries: 5
migrate:
image: mantissaman/waypoint:latest
depends_on:
db:
condition: service_healthy
volumes:
- ./db/migrations:/waypoint/sql
environment:
DB_HOST: db
DB_NAME: myapp
DB_USERNAME: app
DB_PASSWORD: secret
Migrating from Flyway
# Before
FROM flyway/flyway
COPY migrations /flyway/sql
# After
FROM mantissaman/waypoint
COPY migrations /waypoint/sql
See DOCKER.md for full Docker documentation.
Placeholders
Use ${key} syntax in SQL files:
${schema}.users (
id SERIAL PRIMARY KEY,
env VARCHAR(20) DEFAULT '${env}'
);
Set values via config, env vars (WAYPOINT_PLACEHOLDER_ENV=production), or CLI.
Hooks
SQL callback hooks run before/after migrations (Flyway-compatible):
db/migrations/
beforeMigrate.sql
afterMigrate.sql
beforeEachMigrate.sql
afterEachMigrate__Refresh_views.sql
V1__Create_users.sql
Or configure in waypoint.toml:
[]
= ["hooks/before.sql"]
= ["hooks/after.sql"]
Exit Codes
| Code | Meaning |
|---|---|
| 0 | Success |
| 1 | General error |
| 2 | Configuration error |
| 3 | Validation failed |
| 4 | Database error |
| 5 | Migration or hook failed |
| 6 | Lock error |
| 7 | Clean disabled |
Using as a Library
Add waypoint-core to embed migrations in your Rust application:
use WaypointConfig;
use Waypoint;
async
Build config programmatically
use PathBuf;
use ;
use Waypoint;
async
Use with an existing connection
use WaypointConfig;
use db;
use Waypoint;
async
Available methods
| Method | Returns | Description |
|---|---|---|
Waypoint::new(config) |
Waypoint |
Connect and create instance |
Waypoint::with_client(config, client) |
Waypoint |
Use existing connection |
wp.migrate(target) |
MigrateReport |
Apply pending migrations |
wp.info() |
Vec<MigrationInfo> |
Get migration status |
wp.validate() |
ValidateReport |
Validate applied migrations |
wp.repair() |
RepairReport |
Fix history table |
wp.baseline(version, desc) |
() |
Baseline existing database |
wp.clean(allow) |
Vec<String> |
Drop all managed objects |
Development
Prerequisites
- Rust (latest stable)
- PostgreSQL (for integration tests)
Build & Test
Integration Tests
# Start PostgreSQL, then:
Project Structure
waypoint/
waypoint-core/ # Library crate — migration logic
src/
commands/ # migrate, info, validate, repair, baseline, clean
config.rs # Config loading (TOML + env + CLI)
db.rs # Connection, TLS, advisory locks
history.rs # Schema history table
migration.rs # File parsing, scanning
checksum.rs # CRC32 checksums (Flyway-compatible)
placeholder.rs # ${key} replacement
hooks.rs # SQL callback hooks
error.rs # Error types
lib.rs # Public API (Waypoint struct)
tests/
integration_test.rs
waypoint-cli/ # Binary crate — CLI
src/
main.rs # clap CLI, exit codes, JSON output
output.rs # Table formatting
build.rs # Git hash + build timestamp
License
MIT License
Copyright (c) 2025 mantissaman
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.