Skip to main content

No project description provided

Project description

Flyway-Python

License Language version

📋 Requirements

  • Python 3.11+

🚀 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.2.0.tar.gz (12.0 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.2.0-py3-none-any.whl (10.8 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for flyway-0.2.0.tar.gz
Algorithm Hash digest
SHA256 d53ac17a8fdc0ba586e12430d7adcd78ed7f257c99d2fc73d7f4eeaaefc49a73
MD5 e3a5baf945066246cc10d11347ddf352
BLAKE2b-256 136785bd05fa6a0cdbb1dbc8feac3c29f89a801b1b3bb8ff5c9c2be533bbed69

See more details on using hashes here.

File details

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

File metadata

  • Download URL: flyway-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 10.8 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.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 477da4bfad26a4cdc4d329a87f0df4eaa663818dc80cc509a2e4d0281addde98
MD5 7cde2f8338727e5dbf6b0315a77d0a0d
BLAKE2b-256 1bd247ef866974ffd26c1415b34426a7046321f3ddd6e1cdaf730c65686000c4

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