Skip to main content

sqlturk

Overview

This tool helps you to keep track and evolve your database schema (SQL).

It works like this. Whenever you make changes to the database schema you put them into a “migration” - simply an .sql file with a sequence of SQL statements. Sqlturk keeps track of which migrations have been applied and runs them in a guaranteed order.

Design

There are plenty of tools to approach the problem of database schema migration. Here is how sqlturk is different:

  • one-way migrations. There is no way to “rollback” a migration. In my experience, “downgrade” scripts are almost never used yet writing them adds considerable burden onto the developer. Their presense may add a false sense of security – since they used so rarely there is a big chance they will not work properly anyway.

  • Python-agnostic. Sqlturk operates in terms of SQL DDL. It does not work in terms of SQLAlchemy ORM models or Django’s and thus it can be used in a much wider context. Plain SQL also means that a competent DBA who knows nothing about Python can author these scripts. Or they could be generated automatically by another tool.

  • no magic. I wanted a tool that works in an obvious, easy-to-understand way. Changing database schema can have big consequences so it is important to be able to see what’s going on.

Not convinced? A couple of more sophisticated tools: Django South and sqlalchemy-migrate.

API usage

Short example:

>>> from sqlturk.migration import MigrationTool
>>> tool = MigrationTool('sqlite:///:memory:', migration_dir='testmigrations')
>>> tool.install() # create a database table to track schema changes
>>> tool.find_migrations()
['1_foobar', '2_foobar_data', '10_foobar_delete']
>>> tool.run_migrations()
>>> tool.find_migrations() # check that all migrations have been applied
[]

Example migration scripts can be found in the sqlturk’ source. Sqlturk uses SQLAlchemy syntax to specify database connection string, see its documentation for details.

Metadata

Release files for sqlmigrate 1.0.0

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

Source distribution (sdist)

Source distribution for sqlmigrate 1.0.0
File Size Uploaded
sqlmigrate-1.0.0.zip 8.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for sqlmigrate 1.0.0
File Interpreter ABI Platform
sqlmigrate-1.0.0.win32.exe Details

Total release size: 213.8 kB

Release files / sqlmigrate-1.0.0.zip

Download URL sqlmigrate-1.0.0.zip
Size 8.7 kB
Tags Source
SHA-256 checksum
How to use checksums
1dcd7c605d35cee21f8ed0bd58a356ef375e3a55a8475d6698332fc3e2f4e710
BLAKE2b-256 checksum
How to use checksums
27f8f1918e278a27db7dfe0d273ac6e52a0b849c96d246af1cf0c4d1e0669f23
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / sqlmigrate-1.0.0.win32.exe

Download URL sqlmigrate-1.0.0.win32.exe
Size 205.1 kB
Tags Source
SHA-256 checksum
How to use checksums
dd66edd28411faa0a8647465322478558d0b0a5cb9f9d05aef3e73b21cd9940f
BLAKE2b-256 checksum
How to use checksums
31e778f6aa4eaa6d767d4c6976db6b4059c45348559c720fd6a0cfc2557427a1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

1.0.0 This release

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