Skip to main content

Handle database migrations with ease managing your database changes with simple SQL files.

Project description

##########################################
 __  __ _                 _       ___ _
|  \/  (_) __ _ _ __ __ _| |_ ___|_ _| |_
| |\/| | |/ _` | '__/ _` | __/ _ \| || __|
| |  | | | (_| | | | (_| | ||  __/| || |_
|_|  |_|_|\__, |_|  \__,_|\__\___|___|\__|
          |___/
##########################################

Handle database migrations with ease managing your database changes with simple SQL files. Make the migration process easier, more manageable and repeteable.

How does this work

Installation

pip install migrateit

Configuration

Configurations can be changed as environment variables.

# basic configuration
MIGRATEIT_MIGRATIONS_TABLE=MIGRATEIT_CHANGELOG
MIGRATEIT_MIGRATIONS_DIR=migrateit

# change the database connection variables
VARNAME_DB_URL=DB_URL
VARNAME_DB_HOST=DB_HOST
VARNAME_DB_PORT=DB_PORT
VARNAME_DB_USER=DB_USER
VARNAME_DB_PASS=DB_PASS
VARNAME_DB_NAME=DB_NAME


# database configuration
DB_URL=postgresql://postgres:postgres@localhost:5432/postgres
# -------- or ----------
DB_HOST=localhost
DB_PORT=5432
DB_NAME=postgres
DB_USER=postgres
DB_PASS=postgres

Usage

# initialize MigrateIt to create:
# - 'migrations' directory inside the MIGRATIONS_DIR
# - 'changelog.json' file inside the MIGRATIONS_DIR
# - first migration file with the migrateit table creation and rollback
migrateit init postgres

# create a new migration file
migrateit new first_migration

# add your sql commands to the migration file
echo "CREATE TABLE test (id SERIAL PRIMARY KEY, name VARCHAR(50));" > migrateit/migrations/0000_first_migration.sql

# show pending migrations
migrateit show
migrateit show -l

# run the migrations
migrateit migrate

# or run a given migration
migrateit migrate 0000

# rollback a migration
migrateit rollback 0000

Example

-- Migration 0000_user.sql
-- Created on 2025-05-15T19:55:18.711752

CREATE TABLE IF NOT EXISTS users (
	id SERIAL PRIMARY KEY,
	email TEXT NOT NULL UNIQUE,
	given_name TEXT,
	family_name TEXT,
	picture TEXT,
	created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

-- Rollback migration

DROP TABLE IF EXISTS users;

Help

usage: migrateit new [-h] [-d [DEPENDECIES ...]] [--no-edit] [name]

positional arguments:
  name                  Name of the new migration

options:
  -h, --help            show this help message and exit
  -d, --dependecies [DEPENDECIES ...]
                        List of migration names that this migration depends on.
  --no-edit             Avoid opening the migration file in an editor after creation.
usage: migrateit migrate [-h] [--fake] [--update-hash] [name]

positional arguments:
  name           Name of the migration to run

options:
  -h, --help     show this help message and exit
  --fake         Fakes the migration marking it as ran.
  --update-hash  Update the hash of the migration.
usage: migrateit show [-h] [-l] [--validate-sql]

options:
  -h, --help      show this help message and exit
  -l, --list      Display migrations in a list format.
  --validate-sql  Validate SQL migration sintax.
usage: migrateit squash [-h] [-n NAME] start_migration [end_migration]

positional arguments:
  start_migration  Name of the first migration to squash from (inclusive).
  end_migration    Name of the last migration to squash to (inclusive). If not provided, the last migration is used.

options:
  -h, --help       show this help message and exit
  -n, --name NAME  Name of the new squashed migration file. If not provided, a default name will be generated.

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

migrateit-0.6.2.tar.gz (19.6 kB view details)

Uploaded Source

Built Distribution

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

migrateit-0.6.2-py3-none-any.whl (23.2 kB view details)

Uploaded Python 3

File details

Details for the file migrateit-0.6.2.tar.gz.

File metadata

  • Download URL: migrateit-0.6.2.tar.gz
  • Upload date:
  • Size: 19.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for migrateit-0.6.2.tar.gz
Algorithm Hash digest
SHA256 8367a908c38599672dcecc1afdef80dfcacd8cb003c15a148cfeb7031c13d75f
MD5 3f9edb20ca617c2a2145220a166e7a9c
BLAKE2b-256 1273b6f74257d557fd8995af37ae3b17b05f9f5cd97376ba11b0cce6a6dba7cb

See more details on using hashes here.

File details

Details for the file migrateit-0.6.2-py3-none-any.whl.

File metadata

  • Download URL: migrateit-0.6.2-py3-none-any.whl
  • Upload date:
  • Size: 23.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for migrateit-0.6.2-py3-none-any.whl
Algorithm Hash digest
SHA256 f377ee25e878f5d1e7e9ae111a40aef27fc1a75d5cb7ab701af2ed4054f1045a
MD5 0e21a3bde2bfc5d58b05f7211b81a4f6
BLAKE2b-256 0df6093fd1dd3a39389ca8f9871cea30790b811d866e8ec8c17cd265fbcda4a1

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