Skip to main content

A simple migrator with no bs.

Project description

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.

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

simple_migrator-0.1.9.tar.gz (37.6 kB view details)

Uploaded Source

Built Distribution

simple_migrator-0.1.9-py3-none-any.whl (14.0 kB view details)

Uploaded Python 3

File details

Details for the file simple_migrator-0.1.9.tar.gz.

File metadata

  • Download URL: simple_migrator-0.1.9.tar.gz
  • Upload date:
  • Size: 37.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.11.7 Linux/6.2.0-1018-azure

File hashes

Hashes for simple_migrator-0.1.9.tar.gz
Algorithm Hash digest
SHA256 fbac3a43b55a039a2708c07a7d7b44d89b7ef5d351820f69143f4089c72d3af9
MD5 07e4314884464bdcb24c0b33d20bf9bf
BLAKE2b-256 643b5b6eb16b88f9f2126b8eba56245188226707c3f39a3dffdfded9c59c7b69

See more details on using hashes here.

File details

Details for the file simple_migrator-0.1.9-py3-none-any.whl.

File metadata

  • Download URL: simple_migrator-0.1.9-py3-none-any.whl
  • Upload date:
  • Size: 14.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.11.7 Linux/6.2.0-1018-azure

File hashes

Hashes for simple_migrator-0.1.9-py3-none-any.whl
Algorithm Hash digest
SHA256 0a2966f60c057af0f124a9dc2ede2960c7b289f0d24b1218e299547f2b6e2ce4
MD5 c7644ceb176ee5213d7259dd8656d181
BLAKE2b-256 ee03ea456d98f5d5fce0c633ca0130bffa4de22cace5d58434b18aa6406fd85c

See more details on using hashes here.

Supported by

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