| Name | PostgreSQL-Audit JSON |
| Version |
0.17.0
JSON |
| download |
| home_page | |
| Summary | Versioning and auditing extension for PostgreSQL and SQLAlchemy. |
| upload_time | 2023-11-04 13:00:34 |
| maintainer | |
| docs_url | None |
| author | |
| requires_python | >=3.8 |
| license | |
| keywords |
|
| VCS |
 |
| bugtrack_url |
|
| requirements |
No requirements were recorded.
|
| Travis-CI |
No Travis.
|
| coveralls test coverage |
No coveralls.
|
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?
.. _Audit Trigger by 2nd Quadrant: https://github.com/2ndQuadrant/audit-trigger
.. _Papertrail: https://github.com/airblade/paper_trail
.. _SQLAlchemy-Continuum: https://github.com/kvesteri/SQLAlchemy-Continuum
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
---------------
.. code-block:: python
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.
.. code-block:: python
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'}
.. code-block:: python
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'}
.. code-block:: python
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
.. |Build Status| image:: https://github.com/kvesteri/postgresql-audit/actions/workflows/test.yml/badge.svg?branch=master
.. |Version Status| image:: https://img.shields.io/pypi/v/PostgreSQL-Audit.svg
:target: https://pypi.python.org/pypi/PostgreSQL-Audit/
.. |Downloads| image:: https://img.shields.io/pypi/dm/PostgreSQL-Audit.svg
:target: https://pypi.python.org/pypi/PostgreSQL-Audit/
Raw data
{
"_id": null,
"home_page": "",
"name": "PostgreSQL-Audit",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": "",
"keywords": "",
"author": "",
"author_email": "Konsta Vesterinen <konsta@fastmonkeys.com>",
"download_url": "https://files.pythonhosted.org/packages/fb/c8/6e34269443e0333b0b7ce2f220b04452f3bef586270f0b3165b3d47ae064/postgresql_audit-0.17.0.tar.gz",
"platform": null,
"description": "PostgreSQL-Audit\n================\n\n|Build Status| |Version Status| |Downloads|\n\nAuditing 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`_.\n\nCompared to existing solutions PostgreSQL-Audit has the following charasteristics:\n\n- Stores all versions into single table called 'activity'\n- Uses minimalistic trigger based approach to keep INSERTs, UPDATEs and DELETEs as fast as possible\n- Tracks actor IDs to be able to answer these questions quickly:\n - Who modified record x on day x?\n - What did person x do between y and z?\n - Can you show me the activity history of record x?\n\n\n.. _Audit Trigger by 2nd Quadrant: https://github.com/2ndQuadrant/audit-trigger\n\n.. _Papertrail: https://github.com/airblade/paper_trail\n\n.. _SQLAlchemy-Continuum: https://github.com/kvesteri/SQLAlchemy-Continuum\n\n\nInstallation\n------------\n\n::\n\n pip install PostgreSQL-Audit\n\n\nRunning the tests\n-----------------\n\n::\n\n git clone https://github.com/kvesteri/postgresql-audit.git\n cd postgresql-audit\n pip install tox\n createdb postgresql_audit_test\n tox\n\n\nFlask extension\n---------------\n\n.. code-block:: python\n\n\n from postgresql_audit.flask import versioning_manager\n\n from my_app.extensions import db\n\n\n versioning_manager.init(db.Model)\n\n\n class Article(db.Model):\n __tablename__ = 'article'\n __versioned__ = {} # <- IMPORTANT!\n id = db.Column(db.Integer, primary_key=True)\n name = db.Column(db.String)\n\n\n article = Article(name='Some article')\n db.session.add(article)\n db.session.commit()\n\n\n\nNow we can check the newly created activity.\n\n.. code-block:: python\n\n Activity = versioning_manager.activity_cls\n\n activity = Activity.query.first()\n activity.id # 1\n activity.table_name # 'article'\n activity.verb # 'insert'\n activity.old_data # None\n activity.changed_data # {'id': '1', 'name': 'Some article'}\n\n\n.. code-block:: python\n\n article.name = 'Some other article'\n db.session.commit()\n\n activity = Activity.query.order_by(db.desc(Activity.id)).first()\n activity.id # 2\n activity.table_name # 'article'\n activity.verb # 'update'\n activity.object_id # 1\n activity.old_data # {'id': '1', 'name': 'Some article'}\n activity.changed_data # {'name': 'Some other article'}\n\n\n.. code-block:: python\n\n db.session.delete(article)\n db.session.commit()\n\n activity = Activity.query.order_by(db.desc(Activity.id)).first()\n activity.id # 3\n activity.table_name # 'article'\n activity.verb # 'delete'\n activity.object_id # 1\n activity.old_data # {'id': '1', 'name': 'Some other article'}\n activity.changed_data # None\n\n\n.. |Build Status| image:: https://github.com/kvesteri/postgresql-audit/actions/workflows/test.yml/badge.svg?branch=master\n.. |Version Status| image:: https://img.shields.io/pypi/v/PostgreSQL-Audit.svg\n :target: https://pypi.python.org/pypi/PostgreSQL-Audit/\n.. |Downloads| image:: https://img.shields.io/pypi/dm/PostgreSQL-Audit.svg\n :target: https://pypi.python.org/pypi/PostgreSQL-Audit/\n",
"bugtrack_url": null,
"license": "",
"summary": "Versioning and auditing extension for PostgreSQL and SQLAlchemy.",
"version": "0.17.0",
"project_urls": {
"Homepage": "https://github.com/kvesteri/postgresql-audit"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "1e0f9a05b0edf858c3476ee7debdecf95ff3b9506a702beed1d07a14724e1f6c",
"md5": "2709caeefc0cc9b60a64e0c0238ce58c",
"sha256": "3933ccc2a6395b5b6fb2485404ef56166590dc79be0631798023449619626075"
},
"downloads": -1,
"filename": "postgresql_audit-0.17.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "2709caeefc0cc9b60a64e0c0238ce58c",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 15639,
"upload_time": "2023-11-04T13:00:31",
"upload_time_iso_8601": "2023-11-04T13:00:31.645938Z",
"url": "https://files.pythonhosted.org/packages/1e/0f/9a05b0edf858c3476ee7debdecf95ff3b9506a702beed1d07a14724e1f6c/postgresql_audit-0.17.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "fbc86e34269443e0333b0b7ce2f220b04452f3bef586270f0b3165b3d47ae064",
"md5": "7da495afc6e53d5e1f5984abbcc157a8",
"sha256": "f2e999df30ec04afecfb13ab25e4895f9a6bd6cf690da9a5ab4a4fdbdee1c638"
},
"downloads": -1,
"filename": "postgresql_audit-0.17.0.tar.gz",
"has_sig": false,
"md5_digest": "7da495afc6e53d5e1f5984abbcc157a8",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 28431,
"upload_time": "2023-11-04T13:00:34",
"upload_time_iso_8601": "2023-11-04T13:00:34.626950Z",
"url": "https://files.pythonhosted.org/packages/fb/c8/6e34269443e0333b0b7ce2f220b04452f3bef586270f0b3165b3d47ae064/postgresql_audit-0.17.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-11-04 13:00:34",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "kvesteri",
"github_project": "postgresql-audit",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"tox": true,
"lcname": "postgresql-audit"
}