Skip to main content

A library built on top of the SQLAlchemy ORM for versioning row changes to relational SQL tables.

Authors: Ryan Kirkman and Akshay Nanavati

Build Status

https://travis-ci.org/NerdWalletOSS/versionalchemy.svg?branch=master Documentation Status

Getting Started

$ pip install versionalchemy

Sample Usage

import sqlalchemy as sa
from sqlalchemy import create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.schema import UniqueConstraint

import versionalchemy as va
from versionalchemy.models import VAModelMixin, VALogMixin

MY_SQL_URL = '<insert mysql url here>'
engine = create_engine(MY_SQL_URL)
Base = declarative_base(bind=engine)

class Example(Base, VAModelMixin):
    __tablename__ = 'example'
    va_version_columns = ['id']
    id = sa.Column(sa.Integer, primary_key=True)
    value = sa.Column(sa.String(128))


class ExampleArchive(Base, VALogMixin):
    __tablename__ = 'example_archive'
    __table_args__ = (
        UniqueConstraint('id', 'va_version'),
    )
    id = sa.Column(sa.Integer)
    user_id = sa.Column(sa.Integer)

va.init()  # Only call this once
Example.register(ExampleArchive, engine)  # Call this once per engine, AFTER va.init

Latency

We used benchmark.py to benchmark the performance of versionalchemy. It times the performance of the SQLAlchemy core, ORM without VersionAclehmy and ORM with VersionAlchemy for n inserts (where n was variable). Some results are below.

n

Core Time

ORM Time

VA Time

10000

9.81 s

16.04 s

36.13

100000

98.78 s

158.87 s

350.84 s

VersionAlchemy performs roughly 2 times as bad as the ORM, which makes sense as we are doing roughly one additional insert per orm insert into the archive table.

Contributing

  • Make sure you have pip and virtualenv on your dev machine

  • Fork the repository and make the desired changes

  • Run make install to install all required dependencies

  • Run make lint tests to ensure the code is pep8 compliant and all tests pass. Note that the tests require 100% branch coverage to be considered passing

  • Open a pull request with a detailed explaination of the bug or feature

  • Respond to any comments. The PR will be merged if the travis CI build passes and the code changes are deemed sufficient by the admin

Style

  • Follow PEP8 with a line length of 100 characters

  • Prefer parenthesis to \ for line breaks

License

MIT License

Release files for versionalchemy 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 versionalchemy 1.0.0
File Size Uploaded
versionalchemy-1.0.0.tar.gz 14.0 kB Details

Release files / versionalchemy-1.0.0.tar.gz

Download URL versionalchemy-1.0.0.tar.gz
Size 14.0 kB
Tags Source
SHA-256 checksum
How to use checksums
78d64cf5587eb9a55c8ec1b7efd0e1a9e8ca5aca6ff2f1301a5d8c142522096d
BLAKE2b-256 checksum
How to use checksums
5b5c47abbfcfc485f35878c649ab7d6767a5fdd852e96eb6b0965f3ef857e655
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.1

Release history Release notifications | RSS feed

This release

1.0.0 This release

1 release file

0.1.3

1 release file

0.1.2

1 release file

0.1.1

1 release file

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