| Crates.io | sgv-migrate |
| lib.rs | sgv-migrate |
| version | 0.1.0 |
| created_at | 2025-06-24 07:23:29.259829+00 |
| updated_at | 2025-06-24 07:23:29.259829+00 |
| description | A simple PostgreSQL migration CLI tool |
| homepage | |
| repository | https://github.com/watcharapong09/sgv-migrate |
| max_upload_size | |
| id | 1723940 |
| size | 39,987 |
A simple CLI tool for managing PostgreSQL migrations. Inspired by tools like sqlx migrate, but designed for projects that want a straightforward and dependency-light solution.
up)down)list).env, .env.production, .env.test)MIGRATION_SCHEMA env)cargo install sgv-migrate
Create a .env file (or .env.production, .env.test) in your project with the following:
MIGRATION_DATABASE_URL=postgres://user:password@localhost:5432/yourdb
MIGRATION_SCHEMA=public # Optional, defaults to "public"
Put your migration files in a folder called migrations/.
Each .sql file should contain two sections separated by comments:
-- up
CREATE TABLE users (
id SERIAL PRIMARY KEY,
name TEXT NOT NULL
);
-- down
DROP TABLE users;
Name your files in lexicographical order so they apply in the right sequence:
migrations/
├── 0001_create_users.sql
├── 0002_add_roles.sql
✅ Migrations with names lexically less than the latest applied (e.g., 0000_...) will be skipped.
sgv-migrate up # Apply all pending migrations
sgv-migrate down # Revert the last migration
sgv-migrate down --step=2 # Revert the last 2 migrations
sgv-migrate down --step=-1 # Revert all applied migrations
sgv-migrate list # Show pending migrations
MIT © 2025 Watcharapong Essaranuwatanakul