• Stars
    star
    124
  • Rank 278,689 (Top 6 %)
  • Language
    Python
  • License
    BSD 2-Clause "Sim...
  • Created over 9 years ago
  • Updated 4 months ago

Reviews

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

Repository Details

Audit trigger for PostgreSQL

PostgreSQL-Audit

Build Status Version Status Downloads

Auditing extension for PostgreSQL. Provides additional extensions for SQLAlchemy and Flask. PostgreSQL-Audit tries to combine the best of breed from existing solutions such as SQLAlchemy-Continuum, Papertrail and especially Audit Trigger by 2nd Quadrant.

Compared to existing solutions PostgreSQL-Audit has the following charasteristics:

  • Stores all versions into single table called 'activity'
  • Uses minimalistic trigger based approach to keep INSERTs, UPDATEs and DELETEs as fast as possible
  • Tracks actor IDs to be able to answer these questions quickly:
    • Who modified record x on day x?
    • What did person x do between y and z?
    • Can you show me the activity history of record x?

Installation

pip install PostgreSQL-Audit

Running the tests

git clone https://github.com/kvesteri/postgresql-audit.git
cd postgresql-audit
pip install tox
createdb postgresql_audit_test
tox

Flask extension

from postgresql_audit.flask import versioning_manager

from my_app.extensions import db


versioning_manager.init(db.Model)


class Article(db.Model):
    __tablename__ = 'article'
    __versioned__ = {}  # <- IMPORTANT!
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String)


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

Now we can check the newly created activity.

Activity = versioning_manager.activity_cls

activity = Activity.query.first()
activity.id             # 1
activity.table_name     # 'article'
activity.verb           # 'insert'
activity.old_data       # None
activity.changed_data   # {'id': '1', 'name': 'Some article'}
article.name = 'Some other article'
db.session.commit()

activity = Activity.query.order_by(db.desc(Activity.id)).first()
activity.id             # 2
activity.table_name     # 'article'
activity.verb           # 'update'
activity.object_id      # 1
activity.old_data       # {'id': '1', 'name': 'Some article'}
activity.changed_data   # {'name': 'Some other article'}
db.session.delete(article)
db.session.commit()

activity = Activity.query.order_by(db.desc(Activity.id)).first()
activity.id             # 3
activity.table_name     # 'article'
activity.verb           # 'delete'
activity.object_id      # 1
activity.old_data       # {'id': '1', 'name': 'Some other article'}
activity.changed_data   # None

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

sqlalchemy-continuum

Versioning extension for SQLAlchemy.
Python
554
star
4

wtforms-alchemy

Tools for creating wtforms from sqlalchemy models
Python
241
star
5

wtforms-json

Adds smart json support for WTForms. Useful for when using WTForms with RESTful APIs.
Python
138
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