This repository was archived by the owner on Sep 3, 2025. It is now read-only.
feat(db): add audit log for database changes #5703
Closed
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.
This pull request introduces an audit log table to track changes within the database. Note: as part of this implementation, we have refactored the
Baseclass by moving it fromdatabase.coreto a new file,database.base, to resolve a circular import issue with theAuditclass.Details:
Audit Log Implementation:
track_changesfunction and the use of SQLAlchemy's event system.track_changesfunction is registered as an event listener for SQLAlchemy's "before_flush" event, ensuring that changes are logged before they are committed to the database.Refactoring:
Baseclass has been moved todatabase.baseto eliminate a circular import issue caused by theAuditclass, which subclassesBase.Code Requirements:
views.pyfile must include the addition of the.userattribute to thedb_session. This is necessary to associate changes with the current user. For example:current_user, the parameter list in eachviews.pyfunction must be updated to include this line before any database processing:CurrentUsertracked_classeslist insrc/dispatch/database/core.pyImpact:
Baseclass should not affect existing functionality but will improve the code's modularity and maintainability.Testing:
track_changesmechanism.