Skip to main content

No project description provided

Project description

Flyway-Python

License Language version

📋 Requirements

  • Python 3.9+

🚀 Install

pip install flyway

NOTICE

If you are using MySQL and need to execute multiple SQL statements, make sure to add client_flag=CLIENT.MULTI_STATEMENTS in pymysql param. This is required to allow the execution of multiple SQL statements in a single query.

📖 Usage

Basic Example

import sqlite3
from flyway import Migrator, MigratorConfig, DbType

# Create database connection
conn = sqlite3.connect("example.db")

# Configure migrator
config = MigratorConfig(
    db_type=DbType.SQLITE,
    user="admin"
)

# Create migrator instance
migrator = Migrator(conn, config)

# Run migrations from db/migration folder
migrator.migrate()

MySQL Example

import pymysql
from pymysql.constants import CLIENT
from flyway import Migrator, MigratorConfig, DbType

# Create MySQL connection
# Note: Add client_flag=CLIENT.MULTI_STATEMENTS if your migration files contain multiple SQL statements
conn = pymysql.connect(
    host="localhost",
    user="root",
    password="password",
    database="mydb",
    client_flag=CLIENT.MULTI_STATEMENTS
)

# Configure migrator
config = MigratorConfig(
    db_type=DbType.MYSQL,
    user="root"
)

# Create migrator instance
migrator = Migrator(conn, config)

# Run migrations from custom path
migrator.migrate_from_path("/path/to/migrations")

Migration File Naming

Migration files should follow the naming convention:

V<version>__<description>.sql

Examples:

  • V1_0__Create_users_table.sql
  • V1_1__Add_email_column.sql
  • V2_0__Create_posts_table.sql

The version format uses underscores (e.g., 1_0 for version 1.0).

Migration Directory Structure

By default, migrations are loaded from db/migration/ directory:

project/
├── db/
│   └── migration/
│       ├── V1_0__Create_users_table.sql
│       ├── V1_1__Add_email_column.sql
│       └── V2_0__Create_posts_table.sql
└── main.py

You can also specify a custom path using migrate_from_path() method.

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

flyway-0.1.0.tar.gz (10.4 kB view details)

Uploaded Source

Built Distribution

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

flyway-0.1.0-py3-none-any.whl (10.6 kB view details)

Uploaded Python 3

File details

Details for the file flyway-0.1.0.tar.gz.

File metadata

  • Download URL: flyway-0.1.0.tar.gz
  • Upload date:
  • Size: 10.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.4

File hashes

Hashes for flyway-0.1.0.tar.gz
Algorithm Hash digest
SHA256 cc703a73aa39a873779509bd9857706ba8b344ae70c5a3b4c54d920a9f2587e2
MD5 3fd73b109a2a7f81c99030c0f30d344f
BLAKE2b-256 ca58c1b8a2edda66542830eccf8cdd0282121dbc0996c176afb5a06b8a7ed43c

See more details on using hashes here.

File details

Details for the file flyway-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: flyway-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 10.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.4

File hashes

Hashes for flyway-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f09bc78f536e70f70271149c068708db33e25d2d09231220a54d474b161a8811
MD5 ae478f62925ccd9f7552da3a8df7e230
BLAKE2b-256 ced322db2b6361f0c1bf4bef77609ef7a78ce8873e0567500f73473feb769361

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