Skip to main content
SQLift

GitHub License Tests Codecov PyPI - Python Version PyPI - Version Code style: black Linting: Ruff SQLite PostgreSQL Pytest

SQLift is a simple CLI migration tool for SQL databases. It is designed to be easy to use and now supports SQLite and PostgreSQL databases.

Installation

You can install SQLift using pip:

pip install SQLift

By default, SQLift uses SQLite as the database. If you want to use PostgreSQL, you need to install the appropriate database driver. You can do this using the following command:

pip install SQLift[postgres]

Usage

First you need to create a 'migrations' directory where you will store your migration files. Migrations are simple SQL files that contain the SQL commands to be executed for up and down migrations like below. This file needs two sections, one for the up migration and one for the down migration, separated by --DOWN.

Example migration file

migrations/001_create_table.sql 
--UP
CREATE TABLE IF NOT EXISTS test (
    id INTEGER PRIMARY KEY
);

--DOWN
DROP TABLE IF EXISTS test;

You can find more examples of migration files in the migrations directory of this repository.

After you have created your migration files, you can run the following command to apply the migrations to your database. (It is recommended to start the migration files with a number to keep them in order)

sqlift up

This will apply all the migrations that have not been applied yet. If you want migrate to a specific version, you can pass the version as an argument.

sqlift up 001_create_table

To rollback all migrations, you can run the following command.

sqlift down

To rollback to a specific version, you can pass the version

sqlift down 001_create_table

You can also select specific path for migrations directory

sqlift up --path /path/to/migrations

Configuration

SQLift uses environment variables to configure the database connection. You can set the following environment variables to configure the database connection.

DB_URL=postgresql://user:password@localhost:5432/database # PostgreSQL
DB_URL=sqlite:///path/to/database.db                      # SQLite

If you don't set the DB_URL environment variable, SQLift will default to using SQLite with a database file named db.sqlite in the current directory.

Contributing

Contributions are welcome! Feel free to open an issue or submit a pull request. I would like to keep the library to be safe as possible, so i would appreciate if you cover any new feature with tests to maintain 100% coverage.

Install in a development environment

  1. First, clone the repository:

    git clone git@github.com:SpaceShaman/SQLift.git
    
  2. Install poetry if you don't have, here you can find the instructions

  3. Create a virtual environment and install the dependencies:

    cd SQLift
    poetry install --no-root
    
  4. Activate the virtual environment:

    poetry shell
    

Run tests

First, you need to run databases and you can do it simply with docker-compose:

docker compose up -d

Then you can run the tests with pytest:

pytest

You can also run the tests with coverage:

pytest --cov=sqlift

Database clients

If you want to add support for a new database, you need to create a new client class that is consistent with the Client protocol class from sqlift.clients and implement the execute method. Look at the SQLiteClient and PostgreSQLClient classes for reference.

Metadata

Release files for SQLift 0.2.3

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

Source distribution (sdist)

Source distribution for SQLift 0.2.3
File Size Uploaded Provenance
sqlift-0.2.3.tar.gz 5.1 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for SQLift 0.2.3
File Interpreter ABI Platform
sqlift-0.2.3-py3-none-any.whl Python 3 none any Details

Total release size: 11.4 kB

Release files / sqlift-0.2.3.tar.gz

Download URL sqlift-0.2.3.tar.gz
Size 5.1 kB
Tags Source
SHA-256 checksum
How to use checksums
75d21cb32e071a196bd4ae696bfd8d6d0d961f7e9ca271158d9578a7cd51fd32
BLAKE2b-256 checksum
How to use checksums
7f3d80c1006922f679e0ad94ac57151cc25c4fce9f731b9cd61d003d7628e5cb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.1.3 CPython/3.12.11 Linux/6.8.0-1031-azure

Release files / sqlift-0.2.3-py3-none-any.whl

Download URL sqlift-0.2.3-py3-none-any.whl
Size 6.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
52bc0d7abb82091a20b4c1611ea769105a6876d26ef8758e31360e8571dfeb09
BLAKE2b-256 checksum
How to use checksums
76e111352ed6b51d25804b6be135404253bd4b6ae6c8c7f5f1ad31e246ea3968
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.1.3 CPython/3.12.11 Linux/6.8.0-1031-azure

Security for SQLift 0.2.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

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