Skip to main content

MySQL Database versioning toolset

Project description

AlphaDB

GitHub releases PyPI release NPM release License: GPL v3 Tests

AlphaDB

A toolset for MySQL database versioning.

Still in alpha stage

AlphaDB is currently in beta stage. Breaking changes should be expected.

Table of Contents
  1. Documentation
  2. Installation
  3. Usage
  4. Exceptions
  5. License

Documentation

Visit the official documentation

Installation

Install using PIP

pip install alphadb

Note that pip refers to the Python 3 package manager. In an environment where Python 2 is also present the correct command may be pip3.

Usage

Import AlphaDB

from alphadb import AlphaDB

Connect to a database.

db = AlphaDB()
db.connect(
    host="localhost",
    user="user",
    password="password",
    database="database"
)

Make sure the database is empty, back it up if necessary. If the database is not empty, you can use the vacate method. Note that this function will erase ALL data in the database and there is no way to get it back. For extra safety the argument confirm=True is required for the function to run.

db.vacate(confirm=True)

The database is now ready to be initialized. The init method will create the adb_conf table. This holds configuration data for the database.

db.init()

Now we update the database. For this we need to give it a structure. The database version information is a JSON structure formatted as such:

database_version_source = {
    "name": "mydb", ## Database name, does not have to, but is advised to match the actual database name
    "version": [ ## List containing database versions
        {
            "_id": "0.1.0", ## Database version
            "createtable": { ## Object containing tables to be created,
                "customers": { ## Object key will be used as table name
                    "primary_key": "id",
                    "name": { ## Object key will be used as column name
                        "type": "VARCHAR", ## Data type
                        "length": 100, ## Date max length,
                    },
                    "id": {
                        "type": "INT",
                        "a_i": True
                    }
                },
            }
        },
        {
            "_id": "1.0.0",
            "createtable": {
                "orders": {
                    "primary_key": "id",
                    "id": {
                        "type": "INT",
                        "a_i": True
                    },
                    "date": {
                        "type": "DATETIME",
                    },
                    "note": {
                        "type": "TEXT",
                        "null": True
                    }
                }
            }
        }
    ]
}

Then call the update method.

db.update(version_source=database_version_source)

Exceptions

NoConnection

The NoConnection exception is thrown when a method is called while no database connection is active.

DBNotInitialized

The DBNotInitialized exception is thrown when the database is not yet initialized.

Database.init() ## Will initialize the database and thus resolve the error

DBTemplateNoMatch

The DBTemplateNoMatch exception is thrown when de database was previously updated using another version source. On initialization, a table adb_conf is created. In this table the column template is used to save the version source template name. Make sure it matches.

License

GPL-3.0 LICENSE

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

alphadb-1.0.0b12.tar.gz (34.7 kB view details)

Uploaded Source

Built Distribution

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

alphadb-1.0.0b12-py3-none-any.whl (50.2 kB view details)

Uploaded Python 3

File details

Details for the file alphadb-1.0.0b12.tar.gz.

File metadata

  • Download URL: alphadb-1.0.0b12.tar.gz
  • Upload date:
  • Size: 34.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.7

File hashes

Hashes for alphadb-1.0.0b12.tar.gz
Algorithm Hash digest
SHA256 8a10ba914a46a9a7b33979944ccbeca5269ae6ca035ce527ca894d2b66b08119
MD5 d75eed76cb851196ce5b9a8f1c9c15b3
BLAKE2b-256 79f68797a7035da6af90c931dc4d562180065077243e7f33d9dbdbae07e37d42

See more details on using hashes here.

File details

Details for the file alphadb-1.0.0b12-py3-none-any.whl.

File metadata

  • Download URL: alphadb-1.0.0b12-py3-none-any.whl
  • Upload date:
  • Size: 50.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.7

File hashes

Hashes for alphadb-1.0.0b12-py3-none-any.whl
Algorithm Hash digest
SHA256 3c04255b925dda935fff835ad4200e5c97963c5481a19b5dd48cbeaeb370e7b4
MD5 2a241a8ffa4050cdcb847e37f3b6d5ca
BLAKE2b-256 fb2c48a50f01c1a15d11f4712bae5bf2ecb4fdb4f1a5233cf1aa2e1f132b8e7f

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