Skip to main content

Simple Migrator

A simple tool written in python to run simple migrations.

Basic Usage

0. Installation

On Macos Install

brew install --cask mysql-connector-python
pip install simple_migrator

1. Setup

simple_migrator setup {DATABASE_URL}

Result:-

File_path migrations/.config
Checking if migration table exists
Migration table not exists
Creating Table __migrations_table__

2. Create

simple_migrator create {MIGRATION_NAME} 

Result:-

Migration 1704095392331687000_migration_uoi.sql created at migrations/1704095392331687000_migration_uoi.sql

3. Apply

i. There are two ways to apply the migration. One way is to apply all the latest pending migrations.

simple_migrator up  

Result:-

Going to run the following migrations:
 1704096783004737000_migration_3.sql
Migraiton 1704096783004737000_migration_3.sql: COMPLETED
The following migration runned Successfully: ['1704096783004737000_migration_3.sql']

ii. Another way to do this is to give the files name to the up command.

Note that this method will rerun the given migrations file.

simple_migrator up --f 1703509439.048595_temp

Result:-

Going to run the following migrations:
 1704097419937590000_migration_0.sql
Migraiton 1704097419937590000_migration_0.sql: COMPLETED
The following migration runned Successfully: ['1704097419937590000_migration_0.sql']

3. Rollback

i. Similar to "up" migration there are two ways to do this

simple_migrator down 

Result:-

Going to run the following migrations:
 ['1704097461646876000_migration_1.sql']
Rollback Migraiton 1704097461646876000_migration_1.sql completed
All migration rollback successfully.

ii. Another way to do this is to give the files name to the up command.

Note that this method will rollback every migration no matter if they were applied or not.

simple_migrator down --files 1703509439.048595_temp

Result:-

Going to run the following migrations:
 ['1704097419937590000_migration_0.sql']
Rollback Migraiton 1704097419937590000_migration_0.sql completed
All migration rollback successfully.

4. List

i. List All

This will list all the migrations present.

simple_migrator list all

Result:-

Name Status Applied At
1704097419937590000_migration_0.sql MigrationStatus.PENDING 2024-01-01 14:03:14.225402
1704097461646876000_migration_1.sql MigrationStatus.APPLIED 2024-01-01 14:00:21.011784

ii. List All Applied

This will list all the migrations present.

simple_migrator list applied 
Name Status Applied At
1704097461646876000_migration_1.sql MigrationStatus.APPLIED 2024-01-01 14:00:21.011784

iii. List All Applied

This will list the last applied migrations.

simple_migrator list last-applied 
Name Status Applied At
1704097461646876000_migration_1.sql MigrationStatus.APPLIED 2024-01-01 14:00:21.011784

iv. List Pending

This will list the all the pending migrations.

simple_migrator list pending 
Name Status Applied At
1704097419937590000_migration_0.sql MigrationStatus.PENDING 2024-01-01 14:03:14.225402

5. Update

This command is used when you want to update the migration status of certain migrations. You can set different migrations status with --files file_name_1 --files file_name_2 and --status can be set to pending|applied|failed

Result:-

Going to update the following migrations:['1704097461646876000_migration_1.sql'] to status pending
Migrations:['1704097461646876000_migration_1.sql'] updated to status pending

6. Scync

When the database and the migration files are not in scynced. Use this command to scync it.

poetry run python simple_migrator/migrator.py scync --status applied

Result:-

1704097461646876000_migration_1.sql
Scyncing completed

Visit:

  1. Github
  2. PyPi
  3. Website

TDOD:

  • Make it so that the project does not reset when the setup is called twice.(There must be a better way).
  • Add tests to ensure that it works.
  • Add tests with other databases to ensure that it works.
  • Add a decorator so that we can check if setup is correctly done and exists gracefully.
  • Make sql errors more visible.
  • Exist gracefully when database name is suppied properly.

Metadata

Release files for simple_migrator 0.1.9

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for simple_migrator 0.1.9
File Size Uploaded
simple_migrator-0.1.9.tar.gz 37.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for simple_migrator 0.1.9
File Interpreter ABI Platform
simple_migrator-0.1.9-py3-none-any.whl Python 3 none any Details

Total release size: 51.6 kB

Release files / simple_migrator-0.1.9.tar.gz

Download URL simple_migrator-0.1.9.tar.gz
Size 37.6 kB
Tags Source
SHA-256 checksum
How to use checksums
fbac3a43b55a039a2708c07a7d7b44d89b7ef5d351820f69143f4089c72d3af9
BLAKE2b-256 checksum
How to use checksums
643b5b6eb16b88f9f2126b8eba56245188226707c3f39a3dffdfded9c59c7b69
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.7.1 CPython/3.11.7 Linux/6.2.0-1018-azure

Release files / simple_migrator-0.1.9-py3-none-any.whl

Download URL simple_migrator-0.1.9-py3-none-any.whl
Size 14.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0a2966f60c057af0f124a9dc2ede2960c7b289f0d24b1218e299547f2b6e2ce4
BLAKE2b-256 checksum
How to use checksums
ee03ea456d98f5d5fce0c633ca0130bffa4de22cace5d58434b18aa6406fd85c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.7.1 CPython/3.11.7 Linux/6.2.0-1018-azure

Release history Release notifications | RSS feed

This release

0.1.9 This release

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page