schema_cntl
A Python library created by Makpar Innovation Lab for versioning database schemas. Currently compatible with PostgreSQL. schema_cntl uses AWS QLDB to maintain a revision history of a schema.json. This file defines the schema at a single point in time. As schema.json changes are committed, the revision history expands. This library generates SQL statements that allow the user to transform the schema from one revision to another.
Setup
PyPi Package
This is a command line utility. To use it, you must install the latest distribution from PyPi,
pip install schema_cntl
QLDB
This library uses innoldb, another package supported by the Makpar Innovation Lab, to persist the schema.json to an AWS Quantum Ledger Database. As such, in order to use this package, you will need to create a QLDB ledger and an IAM account with permissions to access that ledger. For more detailed instructions on setting the necesssary resources on AWS, refer to the innoldb documentation
Environment Variables
You will need to point the LEDGER environment variable to the name of the QLDB ledger and the TABLE environment variable to the name of the table you intend to use. The ledger must exist, but if the table does not exist, schema_cntl will create a new one.
export LEDGER="<ledger-name>"
export TABLE="<table>"
Schema JSON
A database schema is specified through a JSON configuration file formatted as follows,
{
"schema": {
"name": "<schema-name>",
"engine": "<postgres | ... >",
"tables": [
{
"name": "<table-name>",
"columns": [
{
"name": "<name>",
"type": "<bool | varchar | float8 | int | decimal | date> : ignored if primary key == true",
"limit": "<limit> : optional, defaults to None",
"primary_key": "<true | false> : optional, defaults to false",
"foreign_key_references" : "<fk> : optional, defaults to None",
"not_null": "<true | false> : optional, defaults to false"
}
]
}
]
}
}
For example, the following schema creates a table named test_table with three fields: a primary key field unique_id, an integer field sample_int and a text field sample_text.
{
"schema": {
"engine": "postgres",
"name": "test_schema",
"tables": [
{
"name": "test_table",
"columns": [
{
"name": "unique_id",
"primary_key": true
},
{
"name": "sample_int",
"type": "int"
},
{
"name": "sample_text",
"type": "text"
}
]
}
]
}
}
Workflow
- Commit Revision
- List Revision History
- Generate Schema
- Generate Differences
Commit
schema_cntl commit <path-to-schema.json>
List Revision History
schema_cntl history <path-to-schema.json> --limit <revision_limit>
Generate Schema
schema_cntl schema <path-to-schema.json> <revision>
Generate Differences
schema_cntl diff <path-to-schema.json> <start_revision> <end_revision>
Code Quality
Metadata
Release files for schema-cntl 1.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| schema_cntl-1.0.1.tar.gz | 21.7 kB | Without provenance | Details for schema_cntl-1.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| schema_cntl-1.0.1-py3-none-any.whl | Python 3 | none | any | Details for schema_cntl-1.0.1-py3-none-any.whl |
Total release size: 43.1 kB
Release files / schema_cntl-1.0.1.tar.gz
| Download URL | schema_cntl-1.0.1.tar.gz |
|---|---|
| Size | 21.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
30221d615a1266ed3fda8361a61323fc4a53822c1b1535fa5ee207ad68a308f8
|
|
BLAKE2b-256 checksum How to use checksums |
ec7e64df6a0921a1ca3c2dfeafd92898b327fc57d54c4cf90bd06fbc1298f1d7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.10
|
Release files / schema_cntl-1.0.1-py3-none-any.whl
| Download URL | schema_cntl-1.0.1-py3-none-any.whl |
|---|---|
| Size | 21.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d9efec312e0a3234cfc4a4dfbebc02d19017f603cfe64d7c41d54aeb1ef6fca3
|
|
BLAKE2b-256 checksum How to use checksums |
08cc5f071d348e04eaa08edefaeb0655fc2bad5af29fd81d1c5bd4af0e3dd997
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.10
|
Security for schema-cntl 1.0.1
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.
To learn more about protecting yourself from malicious actors, visit our package security documentation.