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

Add create and last_update columns to models #1032

Merged

Conversation

sea-kelp
Copy link
Collaborator

Fixes issue

#1008

Description of Changes

Add creation and last update columns to track when and by whom models were updated.

Notes for Deployment

Run alembic migration

Screenshots (if appropriate)

N/A

Tests and linting

  • This branch is up-to-date with the develop branch.
  • pytest passes on my local development environment.
  • pre-commit passes on my local development environment.

Copy link
Collaborator

@michplunkett michplunkett left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some questions are asks, but at the very least I'd like to see last_updated_at be defaulted the same as created_by and the comments removed from the alembic file. Overall though, this is fantastic!

@sea-kelp sea-kelp force-pushed the 1008/add-create-last-update-columns branch from 645c8cd to 7431f24 Compare August 22, 2023 06:12
@sea-kelp sea-kelp marked this pull request as ready for review August 22, 2023 09:01
Copy link
Collaborator

@michplunkett michplunkett left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one or two more questions! Feel free to reach out on Signal if that's easier.

)
batch_op.add_column(sa.Column("last_updated_by", sa.Integer(), nullable=True))
batch_op.create_foreign_key(
"fk_assignments_last_updated_by_users",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LAST THING! We have a lot of scenarios where there weren't names used for FKs and they are being input as [table]_[column_name]_fkey. Could you update the foreign key names to that motif?
Screenshot 2023-08-22 at 3 31 50 PM

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm addressing all of the previous migrations in this PR: #1036

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good callout! I've updated the foreign key names

Comment on lines -131 to -133
if hasattr(obj, "last_updated_by") and hasattr(form, "last_updated_by"):
form.last_updated_by.data = current_user.get_id()
form.last_updated_at.data = datetime.datetime.now()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would make sense to keep this here. That way we are updating the two columns for every edit.

if hasattr(obj, "last_updated_by"):
    form.last_updated_by.data = current_user.get_id()
    form.last_updated_at.data = datetime.datetime.now()

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've replaced this with the change in populate_obj which will update the last_updated_by and last_updated_at when editing objects

@michplunkett michplunkett linked an issue Aug 22, 2023 that may be closed by this pull request
Comment on lines +83 to +86
if hasattr(new_obj, "created_by"):
new_obj.created_by = current_user.get_id()
if hasattr(new_obj, "last_updated_by"):
new_obj.last_updated_by = current_user.get_id()
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The created_by and last_updated_by for new objects are updated here

Comment on lines -131 to -133
if hasattr(obj, "last_updated_by") and hasattr(form, "last_updated_by"):
form.last_updated_by.data = current_user.get_id()
form.last_updated_at.data = datetime.datetime.now()
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've replaced this with the change in populate_obj which will update the last_updated_by and last_updated_at when editing objects

)
batch_op.add_column(sa.Column("last_updated_by", sa.Integer(), nullable=True))
batch_op.create_foreign_key(
"fk_assignments_last_updated_by_users",
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good callout! I've updated the foreign key names

@michplunkett michplunkett merged commit de93328 into lucyparsons:develop Aug 22, 2023
2 checks passed
@michplunkett michplunkett deleted the 1008/add-create-last-update-columns branch August 22, 2023 21:24
sea-kelp added a commit to OrcaCollective/OpenOversight that referenced this pull request Sep 25, 2023
Add creation and last update columns to track when and by whom models
were updated.

Run alembic migration

N/A

 - [x] This branch is up-to-date with the `develop` branch.
 - [x] `pytest` passes on my local development environment.
 - [x] `pre-commit` passes on my local development environment.
sea-kelp added a commit to OrcaCollective/OpenOversight that referenced this pull request Sep 25, 2023
Add creation and last update columns to track when and by whom models
were updated.

Run alembic migration

N/A

 - [x] This branch is up-to-date with the `develop` branch.
 - [x] `pytest` passes on my local development environment.
 - [x] `pre-commit` passes on my local development environment.
sea-kelp added a commit to OrcaCollective/OpenOversight that referenced this pull request Oct 9, 2023
Add creation and last update columns to track when and by whom models
were updated.

Run alembic migration

N/A

 - [x] This branch is up-to-date with the `develop` branch.
 - [x] `pytest` passes on my local development environment.
 - [x] `pre-commit` passes on my local development environment.
AetherUnbound pushed a commit to OrcaCollective/OpenOversight that referenced this pull request Nov 11, 2023
Add creation and last update columns to track when and by whom models
were updated.

Run alembic migration

N/A

 - [x] This branch is up-to-date with the `develop` branch.
 - [x] `pytest` passes on my local development environment.
 - [x] `pre-commit` passes on my local development environment.
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

Successfully merging this pull request may close these issues.

Finish auditing fields for non-users tables
2 participants