Skip to main content

A simple PostgreSQL migrations manager

Reason this release was yanked:

No changes

Project description

Petite

A simple PostgreSQL migrations manager. Perfect for small to medium size projects that just need a small and simple tool.

Installation

There are two main options when installing petite. You could install it as a system wide tool or you could install on a per project basis. If installing as a system wide tool I recommend using pipx. If installing on a per project basis I recommend installing within a virtual environment.

pipx

  pipx install petite-cli

pip

  pip install petite-cli

Usage

Commands:

  • setup: Initializes the migration system by setting up the necessary directory and database table.
  • new: Creates a new migration file in the migrations directory.
  • apply: Runs outstanding migrations.

Note: If a .env file exists in the current directory when a command is run it will be loaded automatically when a command is ran.

setup

Initializes the migration system by setting up the necessary directories and database table.

Should be run once per project before running any other commands.

Options:

  • --postgres-uri TEXT: URI of the PostgreSQL database to connect to. [env var: POSTGRES_URI; required]
  • --migrations-directory PATH: Path to location where the migration files will be stored. If the destination directory does not exist it will be created assuming the parent directory exits. [env var: MIGRATIONS_DIRECTORY; required]

Example

  petite setup --postgres-uri postgresql://... --migrations-directory /.../migrations

new

Creates a new migration file in the migrations directory.

Should be ran after setup. When created the file name will follow the format: YYMMDDHHMMSS_migration_name.sql. This ensures that the migrations are applied in the correct order. For this reason this command should be used to create all migration files.

Arguments:

  • MIGRATION_NAME: Name of the new migration file. [required]

Options:

  • --migrations-directory PATH: Path to location where the new migration file will be created. [env var: MIGRATIONS_DIRECTORY; required]

Example

  petite new --migrations-directory /.../migrations new_migration 

apply

Runs outstanding migrations.

Should be run after setup and once new migrations have been created with new. Will find new migrations then apply specified number to the database in order of oldest unapplied to newest. If an error occurs while applying a migration, none of the migrations will be applied.

Arguments:

  • COUNT: Number of new migrations to apply. [default: (All)]

Options:

  • --postgres-uri TEXT: URI of the PostgreSQL database to connect to. [env var: POSTGRES_URI; required]
  • --migrations-directory PATH: Path to location where the migration files are stored. [env var: MIGRATIONS_DIRECTORY; required]
  • --no-transaction: Apply migrations without wrapping them in a transaction. Danger: Running migrations without a transaction is risky. If a migration fails, the failing statement and all subsequent statements in the file will be skipped, and they will not be retried later. This can leave your database in an inconsistent state. Use this flag only if your migrations cannot run in a transaction.
  • --help: Show this message and exit.

Example

  petite apply --postgres-uri postgresql://... --migrations-directory /.../migrations 2

Contributing

Contributions are always welcome! Just make a pull request before you start working on anything so I can let you know if its something I want to add.

Running Tests

To run unit tests, run the following command:

  poetry run pytest

To run integration tests first ensure you have docker installed as its used to bring up a PostgreSQL instance. You might also need to add your current user to the docker group see here for more information. Once this is complete run the following command:

  poetry run pytest tests/integration

Build Locally

This project uses poetry so I would recommend you use it as well. It would make building the project much easier and all the examples below will be making use of it.

Clone the project

  git clone https://github.com/ky-42/petite

Go to the project directory

  cd petite

Install dependencies

  poetry install

Build the sdist and wheel files

  poetry build

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

petite_cli-0.1.3.tar.gz (7.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

petite_cli-0.1.3-py3-none-any.whl (9.7 kB view details)

Uploaded Python 3

File details

Details for the file petite_cli-0.1.3.tar.gz.

File metadata

  • Download URL: petite_cli-0.1.3.tar.gz
  • Upload date:
  • Size: 7.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.4 CPython/3.10.12 Linux/6.16.3-76061603-generic

File hashes

Hashes for petite_cli-0.1.3.tar.gz
Algorithm Hash digest
SHA256 3b3a493b9ee9de546c582cc277a28bda748babb2aaede27b832eabcf319e988d
MD5 e967232df524280d2d9dfc7bb429e10f
BLAKE2b-256 4a9d8474036eb0ec0bb7b544142c9cc9ae1e5c599211719516c8dd48106b41d5

See more details on using hashes here.

File details

Details for the file petite_cli-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: petite_cli-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 9.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.4 CPython/3.10.12 Linux/6.16.3-76061603-generic

File hashes

Hashes for petite_cli-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 269797da1ef93ca3e9455e90d1d0d4ac8b1a9accac52216af0fb2d96b8ae8d9b
MD5 e6db7f012fb01c2f216222b60f3741d4
BLAKE2b-256 aab652a53aa7e8803b96a1e11810ca551174e3e46dfcf5d2d9a794f0a76affd7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page