qop - A simple database migration tool
qop is a command-line tool for managing database migrations. It's designed to be simple, straightforward, and easy to use.
Features
- Backend-agnostic design (currently supports PostgreSQL)
- Simple migration file format (
up.sql,down.sql) - Timestamp-based migration IDs
- Command-line interface for managing migrations
Installation
Getting Started
-
Initialize a new project:
This will create a
qop.tomlfile in your current directory. -
Create your first migration:
This will create a new directory with
up.sqlanddown.sqlfiles. -
Apply the migration:
Configuration
qop is configured using a qop.toml file. Here is an example for PostgreSQL:
[]
= "postgres"
= "localhost"
= 5432
= "postgres"
= "password"
= "postgres"
= "public"
= "migrations"
The migration files are expected to be in a directory relative to the qop.toml file.
Usage
qop provides several commands to manage your database migrations.
init
Initializes a new qop project by creating a qop.toml file in the current directory.
Arguments:
-p, --path <PATH>: Path to theqop.tomlconfiguration file. (default:qop.toml)
migration
The core set of commands for managing migrations.
qop migration init
Initializes the migration table in your database. This table is used to track which migrations have been applied.
Arguments:
-p, --path <PATH>: Path to theqop.tomlconfiguration file. (default:qop.toml)
qop migration new
Creates a new migration directory with up.sql and down.sql files. The directory name is a timestamp-based ID.
This will create a directory structure like:
migrations/
└── id=1678886400000/
├── up.sql
└── down.sql
Arguments:
-p, --path <PATH>: Path to theqop.tomlconfiguration file. (default:qop.toml)
qop migration up
Applies pending migrations. By default, it applies all pending migrations.
Arguments:
-p, --path <PATH>: Path to theqop.tomlconfiguration file. (default:qop.toml)-c, --count <COUNT>: The number of migrations to apply. If not specified, all pending migrations are applied.-t, --timeout <TIMEOUT>: Statement timeout in seconds.
qop migration down
Reverts applied migrations. By default, it reverts the last applied migration.
Arguments:
-p, --path <PATH>: Path to theqop.tomlconfiguration file. (default:qop.toml)-c, --count <COUNT>: The number of migrations to revert. (default: 1)-t, --timeout <TIMEOUT>: Statement timeout in seconds.-r, --remote: Use thedown.sqlfrom the database instead of the local file.
qop migration list
Lists all migrations, showing their status (applied or not) and when they were applied.
Arguments:
-p, --path <PATH>: Path to theqop.tomlconfiguration file. (default:qop.toml)
qop migration sync
Upserts all remote migrations locally. This is useful for syncing migrations across multiple developers.
Arguments:
-p, --path <PATH>: Path to theqop.tomlconfiguration file. (default:qop.toml)
qop migration fix
Shuffles all non-run local migrations to the end of the chain. This is useful when you have created migrations out of order.
Arguments:
-p, --path <PATH>: Path to theqop.tomlconfiguration file. (default:qop.toml)
manual
Generates documentation for qop.
qop manual
Arguments:
-p, --path <PATH>: Path to write documentation to. (default:docs/manual)--format <FORMAT>: Format for the documentation. Can bemanpagesormarkdown. (default:manpages)
autocomplete
Generates shell completion scripts.
qop autocomplete
Arguments:
-p, --path <PATH>: Path to write completion script to. (default:completions)--shell <SHELL>: The shell to generate completions for (e.g.,zsh,bash,fish,powershell,elvish). (default:zsh)