Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
initial commit for audit logs #160
initial commit for audit logs #160
Changes from 1 commit
1196928
de5a5f3
7757c01
96173db
e62027b
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd be tempted to make these lower case.
I looked at the Python docs, and all of the examples are uppercase, which I found surprising:
https://docs.python.org/3/library/enum.html
However, in Piccolo they're always been lowercase, and I think it's a bit more convenient to type if lowercase.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok. I will change that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think one really nice thing would be recording which changes were made. There could be a JSON field which would have something like
{'name': 'bob'}
if the name field was changed to 'bob'.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great idea. I will try to implement it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be omitted - it should default to
now
if you don't pass in a value.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be better if this said which row was created.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd consider naming these methods slightly differently. I know what you mean by them, and they are correct. But having
post_patch
could be confusing - someone might misread it as being about posts and not patches.Instead of
post_
, how about justrecord_
? So it would berecord_patch_action
?We will never have a
pre_
version, so no need to distinguish withpost_
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right. I will change that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd be tempted to get rid of the change message all together.
One option is just storing everything in JSON.
For delete, the json can be:
Likewise, for the save, it could be:
Or we have a field called
effected_rows
which is an integer or array of integers.It's just about making it easy to query - imagine you wanted to know who deleted row 42. You would have to something like:
It's quite imprecise, ad would be better to just do:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similarly, table name should probably be a column too, to make it easier to filter out the changes on a certain table. I'd be tempted to add
table_name
andtable_class
- again, just to make it easy to filter. What do you think?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But all actions are for endpoints that work with a single record. We don't have the
bulk_delete
option yet (PR here) and we don't havebulk_creation
at all. Audit logs would be primarily used in Piccolo Admin and there we delete multiple records by looping through the delete_single endpoint.That would be possible if we have only
primary_key
typeSerial
. But we also haveprimary_key
typestring
andUUID
, and we can't useInteger
column for that (which will be great for precise filtering). We need to useVarchar
and query would be very similar foreffected_row
andchange_message
usinglike
.Here is screenshot with new columns.
I don't think we should remove the
change_message
column because it nicely describes the action the user has taken. Filtering is maybe imprecise, but we can't use the Integer column foreffected_row
.I added
table_name
, but I don't understand what thetable_class
column would be for and what it should go into that column?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good points.
You're right, there's no bulk action endpoints at the moment. But I was just thinking about the future. Imagine someone deletes 1000 rows - we would then have to insert 1000 rows into the audit table.
Good point - the primary key might not be an integer. Storing them all as strings is OK.
Maybe
change_message
could be achieved usingget_readable
instead.I was just thinking that if there's a table class called
MyTable
, and it refers to the database tablemy_table
, maybe we would want to store them both. But it's not that important. Just need to decide which one is best to store -my_table
orMyTable
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, but we don’t currently have the classic bulk delete in Piccolo Admin (we loop through
delete_single
endpoint) and audit logs would primarily be used in Piccolo Admin (page size limit is 100 per page, which is not so bad).Once we have the proper
bulk_delete
, we can change the delete action for the audit logs to something like thisBut for now we don't have that option because we're looping through the
delete_single
endpoint and we can't store multiple IDs in a row like thisWe should stick to what we have at the moment, and later we can always change (when we have
bulk_delete
we will have to make changes also in Piccolo Admin).I think
table_name
is a better option because it'sVarchar
and we can use the filter sidebar to search and filter records.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it should all be optional. So
PiccoloCRUD
should have a new argument which isaudit_log_table: t.Optional[t.Type[AuditLog]] = None
. And then this line would be:Otherwise when we release this it will be a breaking change - anyone without the
AuditLog
table installed will have their code break. Also, it allows people to disable this functionality if they don't want to track changes.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right. I will change that.