Squill manages Postgresql database migrations.
There's no shortage of tools for running migrations, but this one embodies my particular opinions:
It's the common name for a subfamily of plants that are actually pretty cool looking.
But more importantly, it's a word that has the letters "s", "q", and "l" in that order, is easy to type and pronounce, and not already someone else's crate name 😉
To install Squill as a command, use cargo install
:
bash
cargo install squill
To use Squill as a library, add this to your Cargo.toml
:
bash
squill = "0.4.2"
Run squill --help
to get usage information from each subcommand.
Write the configuration file (squill.toml
) or set the equivalent environment
variables. The environment variables take precedence over the file.
The environment variables are uppercase versions of the ones in the file with
SQUILL_
prefixes. For example, database_url
is SQUILL_DATABASE_URL
.
```toml
#
#
database_url = ""
#
migrations_dir = "migrations"
#
templates_dir = ".squill/templates" ```
Then, generate the first migration that sets up Squill's requirements:
bash
squill init
That should have written 0-init/{up,down}.sql
to your migrations directory.
Read through those files and make any changes you want.
Finally, run the up migration:
bash
squill migrate
Create a new empty migration file:
bash
squill new --name 'create_users_table'
(You can override the automatic ID generation with --id 123
).
Write your migration in the file. Then run it:
bash
squill migrate
For a migration that has already been run in production (or some other shared environment), the best option is to write a new migration to undo the old one.
In a development environment, undo the most recently run migration (by application order, not by ID):
bash
squill undo
Edit the up migration, and then use squill migrate
as normal to run it.
To make this easier, squill redo
will run down.sql
and then up.sql
for the
most recently run migration.
You may have a mix of migrations with different ID lengths, which can make it
awkward to sort the directories. Use the renumber
subcommand to zero-pad
shorter IDs:
bash
squill renumber
That command is just a preview by default. Add --write
to actually execute
the renaming.
You can customize the files generated by squill new
by setting the
templates_dir
path. Squill will use the new.up.sql
and new.down.sql
files
in that directory as [Tera] templates to generate the respective up and down
migration files.
The Tera context will be something like this:
id: &i64
name: &str
Licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
I welcome contributions from anyone who finds a way to make this better.
In particular, I appreciate these things: - Pull requests with clear motivation (tests are nice too!) - Bug reports with reproducible setup instructions - Ideas about things that work but can be improved - Comments in issues and PRs to help me write better words and code
This is is hobby project, so I'll only work on it as much as I find it fun to do so. That said, I find software maintenance techniques interesting, so feel free to start a conversation about a stable v1 if you start relying on this for something important.