-
Notifications
You must be signed in to change notification settings - Fork 79
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
Add create and last_update columns to models #1032
Conversation
...sight/migrations/versions/2023-08-21-0300_a35aa1a114fa_add_create_and_last_update_columns.py
Outdated
Show resolved
Hide resolved
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.
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!
645c8cd
to
7431f24
Compare
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.
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", |
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.
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'm addressing all of the previous migrations in this PR: #1036
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 callout! I've updated the foreign key names
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() |
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 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()
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've replaced this with the change in populate_obj
which will update the last_updated_by
and last_updated_at
when editing objects
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() |
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.
The created_by and last_updated_by for new objects are updated here
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() |
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'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", |
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 callout! I've updated the foreign key names
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.
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.
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.
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.
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
develop
branch.pytest
passes on my local development environment.pre-commit
passes on my local development environment.