Skip to main content

This project is a database migration tool that helps manage and apply database schema changes. It uses a JSON file to define the changes and applies them to a MySQL database.

Project description

Tern🐧 - MySQL Versioning for Python

This project is a database migration tool that helps manage and apply database schema changes. It uses a JSON file to define the changes and applies them to a MySQL database. It is named after a bird called Arctic Tern which can migrate the longest distance. Yearly migration can range from 44,000 miles to 59,000 miles.

Files

  • changes.json: Contains the list of database changes to be applied.
  • connection.py: Manages the database connection pool.
  • main.py: Entry point for running the migration scripts.
  • Makefile: Contains commands to run the project.
  • migration.py: Contains functions to process migrations, calculate checksums, and insert data into the database.
  • requirement.txt: Lists the Python dependencies for the project.
  • venv/: Virtual environment directory.

Setup

  1. Create a Virtual Environment:

    python -m venv venv
    
  2. Activate the Virtual Environment:

    • On Windows:
      .\venv\Scripts\activate
      
    • On macOS/Linux:
      source venv/bin/activate
      
  3. Install Dependencies:

    pip install -r requirement.txt
    

Usage

Running Migrations

To run the migrations, use the main.py script with the appropriate arguments.

  • Migrate Up:

    python main.py --migrate up
    
  • Migrate Down:

    python main.py --migrate down
    

Makefile

You can also use the Makefile to run the project:

  • Run the Project:
    make run
    

Code Overview

connection.py

migration.py

main.py

  • Entry point for the migration tool.
  • Parses command-line arguments to determine whether to migrate up or down.
  • Calls the appropriate functions from migration.py to process the migrations.

Example changes.json

{
    "changeSet": [
        {
            "id": "1",
            "author": "John Doe",
            "description": "Initial version",
            "date": "2019-01-01",
            "comment": "Initial version",
            "migrateUp": "CREATE TABLE my_table (id INT PRIMARY KEY, name VARCHAR(255));",
            "migrateDown": "DROP TABLE my_table;"
        },
        {
            "id": "2",
            "author": "John Doe",
            "description": "Add column",
            "date": "2019-01-02",
            "comment": "Add column",
            "migrateUp": "ALTER TABLE my_table ADD COLUMN age INT;",
            "migrateDown": "ALTER TABLE my_table DROP COLUMN age;"
        }
    ]
}

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

qwik_tern-0.0.5.3.tar.gz (20.1 kB view details)

Uploaded Source

Built Distribution

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

qwik_tern-0.0.5.3-py3-none-any.whl (18.8 kB view details)

Uploaded Python 3

File details

Details for the file qwik_tern-0.0.5.3.tar.gz.

File metadata

  • Download URL: qwik_tern-0.0.5.3.tar.gz
  • Upload date:
  • Size: 20.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.20

File hashes

Hashes for qwik_tern-0.0.5.3.tar.gz
Algorithm Hash digest
SHA256 99ae93cb6ecd70f3724f636fd337d952530bc52468d3504686e7e88a8fb25440
MD5 19314a0ff02d83f15d852292b137f713
BLAKE2b-256 0c409e8d55b0351db5d6d2c8d5808d7d7d40660ce7db4916351d0c98762359b7

See more details on using hashes here.

File details

Details for the file qwik_tern-0.0.5.3-py3-none-any.whl.

File metadata

  • Download URL: qwik_tern-0.0.5.3-py3-none-any.whl
  • Upload date:
  • Size: 18.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.20

File hashes

Hashes for qwik_tern-0.0.5.3-py3-none-any.whl
Algorithm Hash digest
SHA256 ea4d134b4392cf20cfdd0e785420cdac8a0855783a8f50120de9de91ef06d96f
MD5 195a2b7ef491b6f26422c7afd91984a0
BLAKE2b-256 0b2ca092dbce316c948a60141500bfdd33b07d4da10f7b56bc1ddf8ae3ae2c81

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