kvesteri / postgresql-audit

Audit trigger for PostgreSQL
BSD 2-Clause "Simplified" License
126 stars 28 forks source link

Temporarily disable inserts to the activity table #8

Closed jacobsvante closed 8 years ago

jacobsvante commented 8 years ago

There are cases where you might not want to track changes to your data, such as when doing big changes to a table. In those cases you can use the VersioningManager.disable context manager.

Usage:

with versioning_manager.disable(session):
    for i in range(1, 10000):
        db.session.add(db.Product(name='Product %s' % i))
    db.session.commit()

Note that this PR includes changes from #4. https://github.com/kvesteri/postgresql-audit/commit/607f06e38161a8c2c6a0ef1e9065dc06894fa898 contains the changes that touch this feature.

Inspiration found @ http://blog.endpoint.com/2015/07/selectively-firing-postgres-triggers.html

jacobsvante commented 8 years ago

It should also be noted that this change requires an update of each audit_trigger_row trigger as the feature works by making use of a WHEN clause like this:

WHEN (current_setting('session_replication_role') <> 'local')
jacobsvante commented 8 years ago

I've rebased all three pull requests that I've made now to only include the relevant code.

I'd suggest that they be merged in the following order:

  1. 9

  2. 8

  3. 4

Note that these changes will be have to be reapplied after #4 has been merged:

  1. Changes to postgresql_audit/audit_table.sql in this PR will have to be re-applied in postgresql_audit/templates/audit_table_func.sql
  2. Use versioning_manager fixture for this test: https://github.com/kvesteri/postgresql-audit/pull/8/files#diff-e8c010939a36969e585128cd96af94f3R141

Also: As you can see I've included two new db_user and db_name fixtures in all of my PRs, as I've been unable to test with the postgres user on my install.

Edit: I have merged all three here: https://github.com/jmagnusson/postgresql-audit/tree/jmagnusson. Just give me a shout if you run into any issues.

kvesteri commented 8 years ago

Thanks for the PR! :steam_locomotive: