SQLift


NameSQLift JSON
Version 0.1.3 PyPI version JSON
download
home_pagehttps://github.com/SpaceShaman/SQLift
SummarySimple CLI migration tool for SQL databases
upload_time2024-12-05 16:33:04
maintainerNone
docs_urlNone
authorSpaceShaman
requires_python<4,>=3.10
licenseMIT
keywords cli postgres sql database sqlite postgresql migration sqlite3
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # SQLift

[![GitHub License](https://img.shields.io/github/license/SpaceShaman/SQLift)](https://github.com/SpaceShaman/SQLift?tab=MIT-1-ov-file)
![Tests](https://img.shields.io/github/actions/workflow/status/SpaceShaman/SQLift/release.yml?label=tests)
![Codecov](https://img.shields.io/codecov/c/github/SpaceShaman/SQLift)
![PyPI - Python Version](https://img.shields.io/pypi/pyversions/SQLift)
[![PyPI - Version](https://img.shields.io/pypi/v/SQLift)](https://pypi.org/project/SQLift)
[![Code style: black](https://img.shields.io/badge/code%20style-black-black)](https://github.com/psf/black)
[![Linting: Ruff](https://img.shields.io/badge/linting-Ruff-black?logo=ruff&logoColor=black)](https://github.com/astral-sh/ruff)
[![SQLite](https://img.shields.io/badge/technology-SQLite-blue?logo=sqlite&logoColor=blue)](https://www.sqlite.org)
[![PostgreSQL](https://img.shields.io/badge/technology-PostgreSQL-blue?logo=postgresql&logoColor=blue)](https://www.postgresql.org)
[![Pytest](https://img.shields.io/badge/testing-Pytest-red?logo=pytest&logoColor=red)](https://docs.pytest.org/)

SQLift is a simple CLI migration tool for SQL databases. It is designed to be easy to use and now supports [SQLite](https://www.sqlite.org) and [PostgreSQL](https://www.postgresql.org) databases.

## Installation

```bash
pip install SQLift
```

## 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

```sql
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](https://github.com/SpaceShaman/SQLift/tree/master/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)

```bash
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.

```bash
sqlift up 001_create_table
```

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

```bash
sqlift down
```

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

```bash
sqlift down 001_create_table
```

## Configuration

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

```env
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:

    ```bash
    git clone git@github.com:SpaceShaman/SQLift.git
    ```

2. Install poetry if you don't have, here you can find the [instructions](https://python-poetry.org/docs/#installing-with-the-official-installer)

3. Create a virtual environment and install the dependencies:

    ```bash
    cd SQLift
    poetry install --no-root
    ```

4. Activate the virtual environment:

    ```bash
    poetry shell
    ```

### Run tests

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

```bash
docker-compose up -d
```

Then you can run the tests with pytest:

```bash
pytest
```

You can also run the tests with coverage:

```bash
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 protocol `Client` class from `sqlift.clients` and implement the `execute` method. Look at the `SQLiteClient` and `PostgreSQLClient` classes for reference.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/SpaceShaman/SQLift",
    "name": "SQLift",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4,>=3.10",
    "maintainer_email": null,
    "keywords": "cli, postgres, sql, database, sqlite, postgresql, migration, sqlite3",
    "author": "SpaceShaman",
    "author_email": "spaceshaman@tuta.io",
    "download_url": "https://files.pythonhosted.org/packages/fa/25/9958412b192de8afc2f50b72a661413110f19ba364f5136e9e8ffbb7ee0a/sqlift-0.1.3.tar.gz",
    "platform": null,
    "description": "# SQLift\n\n[![GitHub License](https://img.shields.io/github/license/SpaceShaman/SQLift)](https://github.com/SpaceShaman/SQLift?tab=MIT-1-ov-file)\n![Tests](https://img.shields.io/github/actions/workflow/status/SpaceShaman/SQLift/release.yml?label=tests)\n![Codecov](https://img.shields.io/codecov/c/github/SpaceShaman/SQLift)\n![PyPI - Python Version](https://img.shields.io/pypi/pyversions/SQLift)\n[![PyPI - Version](https://img.shields.io/pypi/v/SQLift)](https://pypi.org/project/SQLift)\n[![Code style: black](https://img.shields.io/badge/code%20style-black-black)](https://github.com/psf/black)\n[![Linting: Ruff](https://img.shields.io/badge/linting-Ruff-black?logo=ruff&logoColor=black)](https://github.com/astral-sh/ruff)\n[![SQLite](https://img.shields.io/badge/technology-SQLite-blue?logo=sqlite&logoColor=blue)](https://www.sqlite.org)\n[![PostgreSQL](https://img.shields.io/badge/technology-PostgreSQL-blue?logo=postgresql&logoColor=blue)](https://www.postgresql.org)\n[![Pytest](https://img.shields.io/badge/testing-Pytest-red?logo=pytest&logoColor=red)](https://docs.pytest.org/)\n\nSQLift is a simple CLI migration tool for SQL databases. It is designed to be easy to use and now supports [SQLite](https://www.sqlite.org) and [PostgreSQL](https://www.postgresql.org) databases.\n\n## Installation\n\n```bash\npip install SQLift\n```\n\n## Usage\n\nFirst you need to create a 'migrations' directory where you will store your migration files.\nMigrations are simple SQL files that contain the SQL commands to be executed for `up` and `down` migrations like below.\nThis file needs two sections, one for the `up` migration and one for the `down` migration, separated by `--DOWN`.\n\n### Example migration file\n\n```sql\nmigrations/001_create_table.sql \n--UP\nCREATE TABLE IF NOT EXISTS test (\n    id INTEGER PRIMARY KEY\n);\n\n--DOWN\nDROP TABLE IF EXISTS test;\n```\n\nYou can find more examples of migration files in the [migrations](https://github.com/SpaceShaman/SQLift/tree/master/migrations) directory of this repository.\n\nAfter 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)\n\n```bash\nsqlift up\n```\n\nThis 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.\n\n```bash\nsqlift up 001_create_table\n```\n\nTo rollback all migrations, you can run the following command.\n\n```bash\nsqlift down\n```\n\nTo rollback to a specific version, you can pass the version\n\n```bash\nsqlift down 001_create_table\n```\n\n## Configuration\n\nSQLift uses environment variables to configure the database connection. You can set the following environment variables to configure the database connection.\n\n```env\nDB_URL=postgresql://user:password@localhost:5432/database # PostgreSQL\nDB_URL=sqlite:///path/to/database.db                      # SQLite\n```\n\nIf 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.\n\n## Contributing\n\nContributions are welcome! Feel free to open an issue or submit a pull request.\nI 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.\n\n### Install in a development environment\n\n1. First, clone the repository:\n\n    ```bash\n    git clone git@github.com:SpaceShaman/SQLift.git\n    ```\n\n2. Install poetry if you don't have, here you can find the [instructions](https://python-poetry.org/docs/#installing-with-the-official-installer)\n\n3. Create a virtual environment and install the dependencies:\n\n    ```bash\n    cd SQLift\n    poetry install --no-root\n    ```\n\n4. Activate the virtual environment:\n\n    ```bash\n    poetry shell\n    ```\n\n### Run tests\n\nFirst, you need to run databases and you can do it simply with docker-compose:\n\n```bash\ndocker-compose up -d\n```\n\nThen you can run the tests with pytest:\n\n```bash\npytest\n```\n\nYou can also run the tests with coverage:\n\n```bash\npytest --cov=sqlift\n```\n\n### Database clients\n\nIf you want to add support for a new database, you need to create a new client class that is consistent with the protocol `Client` class from `sqlift.clients` and implement the `execute` method. Look at the `SQLiteClient` and `PostgreSQLClient` classes for reference.\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Simple CLI migration tool for SQL databases",
    "version": "0.1.3",
    "project_urls": {
        "Documentation": "https://github.com/SpaceShaman/SQLift",
        "Homepage": "https://github.com/SpaceShaman/SQLift",
        "Repository": "https://github.com/SpaceShaman/SQLift"
    },
    "split_keywords": [
        "cli",
        " postgres",
        " sql",
        " database",
        " sqlite",
        " postgresql",
        " migration",
        " sqlite3"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "250faf98d3268dea48473b314c25a06bd187fd75e15244841c685b8ffbecd57f",
                "md5": "115a6918b5ab7fd5141e37ca44e73a4f",
                "sha256": "7f8b2a96e4cc4be77e3a6a302cc8bcacbb50712f232790d4fff6fd4e22dd9abf"
            },
            "downloads": -1,
            "filename": "sqlift-0.1.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "115a6918b5ab7fd5141e37ca44e73a4f",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4,>=3.10",
            "size": 5887,
            "upload_time": "2024-12-05T16:33:02",
            "upload_time_iso_8601": "2024-12-05T16:33:02.572815Z",
            "url": "https://files.pythonhosted.org/packages/25/0f/af98d3268dea48473b314c25a06bd187fd75e15244841c685b8ffbecd57f/sqlift-0.1.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "fa259958412b192de8afc2f50b72a661413110f19ba364f5136e9e8ffbb7ee0a",
                "md5": "2ea3ea3c0b2274b20730bee5109a7ec1",
                "sha256": "751bbc6422dc32c8b244dd1139da631bb9d42fd8293f0577830b4b8d5713214d"
            },
            "downloads": -1,
            "filename": "sqlift-0.1.3.tar.gz",
            "has_sig": false,
            "md5_digest": "2ea3ea3c0b2274b20730bee5109a7ec1",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4,>=3.10",
            "size": 4823,
            "upload_time": "2024-12-05T16:33:04",
            "upload_time_iso_8601": "2024-12-05T16:33:04.449937Z",
            "url": "https://files.pythonhosted.org/packages/fa/25/9958412b192de8afc2f50b72a661413110f19ba364f5136e9e8ffbb7ee0a/sqlift-0.1.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-12-05 16:33:04",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "SpaceShaman",
    "github_project": "SQLift",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "tox": true,
    "lcname": "sqlift"
}
        
Elapsed time: 0.38273s