• Stars
    star
    554
  • Rank 77,475 (Top 2 %)
  • Language
    Python
  • License
    BSD 3-Clause "New...
  • Created almost 11 years ago
  • Updated about 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Versioning extension for SQLAlchemy.

SQLAlchemy-Continuum

Build Status Version Status Downloads

Versioning and auditing extension for SQLAlchemy.

Features

  • Creates versions for inserts, deletes and updates
  • Does not store updates which don't change anything
  • Supports alembic migrations
  • Can revert objects data as well as all object relations at given transaction even if the object was deleted
  • Transactions can be queried afterwards using SQLAlchemy query syntax
  • Query for changed records at given transaction
  • Temporal relationship reflection. Version object's relationship show the parent objects relationships as they where in that point in time.
  • Supports native versioning for PostgreSQL database (trigger based versioning)

QuickStart

pip install SQLAlchemy-Continuum

In order to make your models versioned you need two things:

  1. Call make_versioned() before your models are defined.
  2. Add __versioned__ to all models you wish to add versioning to
from sqlalchemy_continuum import make_versioned


make_versioned(user_cls=None)


class Article(Base):
    __versioned__ = {}
    __tablename__ = 'article'

    id = sa.Column(sa.Integer, primary_key=True, autoincrement=True)
    name = sa.Column(sa.Unicode(255))
    content = sa.Column(sa.UnicodeText)


article = Article(name='Some article', content='Some content')
session.add(article)
session.commit()

# article has now one version stored in database
article.versions[0].name
# 'Some article'

article.name = 'Updated name'
session.commit()

article.versions[1].name
# 'Updated name'


# lets revert back to first version
article.versions[0].revert()

article.name
# 'Some article'

For completeness, below is a working example.

from sqlalchemy_continuum import make_versioned
from sqlalchemy import Column, Integer, Unicode, UnicodeText, create_engine
from sqlalchemy.orm import create_session, configure_mappers, declarative_base

make_versioned(user_cls=None)

Base = declarative_base()
class Article(Base):
    __versioned__ = {}
    __tablename__ = 'article'
    id = Column(Integer, primary_key=True, autoincrement=True)
    name = Column(Unicode(255))
    content = Column(UnicodeText)

configure_mappers()
engine = create_engine('sqlite://')
Base.metadata.create_all(engine)
session = create_session(bind=engine, autocommit=False)

article = Article(name=u'Some article', content=u'Some content')
session.add(article)
session.commit()
article.versions[0].name
article.name = u'Updated name'
session.commit()
article.versions[1].name
article.versions[0].revert()
article.name

Resources

http://i.imgur.com/UFaRx.gif

More information

More Repositories

1

sqlalchemy-utils

Various utility functions and datatypes for SQLAlchemy.
Python
1,206
star
2

validators

Python Data Validation for Humansâ„¢.
Python
582
star
3

wtforms-alchemy

Tools for creating wtforms from sqlalchemy models
Python
241
star
4

wtforms-json

Adds smart json support for WTForms. Useful for when using WTForms with RESTful APIs.
Python
138
star
5

postgresql-audit

Audit trigger for PostgreSQL
Python
124
star
6

intervals

Python tools for handling intervals (ranges of comparable objects).
Python
106
star
7

wtforms-components

Additional fields, validators and widgets for WTForms.
Python
68
star
8

sqlalchemy-i18n

Internationalization extension for SQLAlchemy models
Python
49
star
9

sqlalchemy-json-api

Fast SQLAlchemy query builder for returning JSON API responses
Python
45
star
10

flask-storage

Various file storage backends for Flask applications.
Python
20
star
11

infinity

All-in-one infinity value for Python. Can be compared to any object.
Python
20
star
12

sqlalchemy-defaults

Smart SQLAlchemy defaults for lazy guys, like me.
Python
16
star
13

sqlalchemy-fixtures

Functional fixtures for SQLAlchemy
Python
11
star
14

flask-jinjahelpers

Various helpers for Jinja2 templates
Python
10
star
15

sqlalchemy-sluggable

SQLAlchemy-Sluggable
Python
8
star
16

python-poker

Python poker library
Python
6
star
17

flask-test

Various unit test helpers for Flask applications
Python
6
star
18

flask-activity-stream

4
star
19

total-ordering

functools.total_ordering backport for Python 2.6
Python
4
star
20

colander-alchemy

Generates colander schemas from SQLAlchemy models
Python
4
star
21

wtforms-test

Various unit test helpers for WTForms forms
Python
4
star
22

flask-generic-views

Generic pluggable views for flask
Python
4
star
23

serializer

Easy object serialization. Mimics RoR ActiveRecord serializer.
Python
4
star
24

primitives

Data types you've always missed in Python
Python
3
star
25

postgresql-snippets

Various snippets for PostgreSQL
2
star
26

bourne

Easy object json serialization. Mimics RoR ActiveRecord json serializer
Python
2
star
27

schemas

Python data structures for Humansâ„¢.
Python
2
star
28

flask-alchemy

Various SQLAlchemy helpers for Flask, built on top of Flask-SQLAlchemy
Python
1
star
29

dotfiles

Shell
1
star
30

wtforms-errors

Better error messages for wtforms
1
star
31

sqlalchemy-test

Various unit test helpers for SQLAlchemy models
Python
1
star