Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

auditing changes to tables with hstore columns is not working #29

Open
zam6ak opened this issue Jun 14, 2017 · 1 comment
Open

auditing changes to tables with hstore columns is not working #29

zam6ak opened this issue Jun 14, 2017 · 1 comment

Comments

@zam6ak
Copy link

zam6ak commented Jun 14, 2017

If a table you wish to audit has an hstore column the changes recorded in changed_fields is not tracking properly.

consider a table with hstore column hprops with these initial values

-- add some data
INSERT INTO audit_test VALUES (default, 'apples', 'red', true, 123456789, 2.99, inet_client_addr(), hstore('"x"=>"30", "y"=>"c"'), json_object('{a, 1, b, "def", c, 3.5}'), jsonb_object('{zz, 2, xx, "geh", yy, 99.5}'));

Consider following 3 scenarios

-- case 1) update hstore column (works!)
-- "changed_fields":   ""hprops"=>"\"x\"=>\"30\", \"y\"=>\"fred\"""    -- Works if entire column changed 
UPDATE audit_test SET hprops = hstore('"x"=>"30", "y"=>"fred"')  WHERE id = 1   

-- case 2) add a key or update existing key in hstore column (does not work)
-- "changed_fields":   ""hprops"=>"\"x\"=>\"30\", \"y\"=>\"bob\"""
UPDATE audit_test SET hprops = hprops || hstore('"y"=>"bob"')  WHERE id = 1     

-- case 3) delete a key in hstore  (does not work)
-- "changed_fields":   ""hprops"=>"\"x\"=>\"30\"""
UPDATE audit_test SET hprops = delete(hprops, 'y')  WHERE id = 1  
  • In scenario 2, changed_fields should not contain 'x' key as it has not changed
  • In scenario 3, changed key should be 'y'
@zam6ak
Copy link
Author

zam6ak commented Jun 14, 2017

Now that I had more time to think about this, this is probably not an issue...
The mechanics of how hstore (and json(b) perhaps?) column is updated affects the "whole" colum.
The fact that some key in hstore was added/changed/deleted would still result in entire column being updated.
If this is correct, then this issue can be closed...
Can anyone confirm this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant