Casecommons / pg_audit_log

Create a trigger-based audit log for PostgreSQL
MIT License
3 stars 2 forks source link

Don't load columns from tables in other schemas #15

Open pjungwir opened 8 years ago

pjungwir commented 8 years ago

By default Rails puts its tables in the public schema. But sometimes other schemas are used, for instance for history, reporting, multiple tenants, etc. It is common for these other schemas to have tables with the same name as the table from the public schema (see links above). Currently when pg_audit_log queries information_schema.columns, it gets all columns from all schemas, which causes errors when it tries to record the changes that happened. This change makes pg_audit_log look only in the public schema, so it doesn't break if other schemas are used.

amarshall commented 8 years ago

Is it possible to specify the schema in the database.yml? If so this should use the value specified in the connection config instead of a hard-coded default.

On Mon, Jun 6, 2016 at 19:42 Paul A Jungwirth notifications@github.com wrote:

By default Rails puts its tables in the public schema. But sometimes other schemas are used, for instance for history https://www.youtube.com/watch?v=TRgni5q0YM8, reporting, multiple tenants https://github.com/influitive/apartment, etc. It is common for these other schemas to have tables with the same name as the table from the public schema (see links above). Currently when pg_audit_log queries information_schema.columns, it gets all columns from all schemas, which causes errors when it tries to record the changes that happened. This change makes pg_audit_log look only in the public schema, so it doesn't

break if other schemas are used.

You can view, comment on, or merge this pull request online at:

https://github.com/Casecommons/pg_audit_log/pull/15 Commit Summary

  • Don't load columns from tables in other schemas

File Changes

Patch Links:

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/Casecommons/pg_audit_log/pull/15, or mute the thread https://github.com/notifications/unsubscribe/AAJWV7pLUcy7tbZzpTiA1lpGOo-gAsrWks5qJLBwgaJpZM4IvbB4 .

pjungwir commented 8 years ago

The best you can do from database.yml is schema_search_path, which seems not quite right. I changed the PR so that the old behavior is unchanged by default, but you can restrict pg_audit_log to just one schema by passing a param to the install function or setting an envvar when you run the rake task.