Skip to content

Conversation

@darshdinger
Copy link
Contributor

@darshdinger darshdinger commented Sep 10, 2025

Description of the changes

This PR implements audit trail functionality for the MonitoredVariable model by adding created and updated timestamp fields. This addresses the need for better troubleshooting capabilities by tracking when monitored variables are created and last modified.

Changes Made

Django Model Updates

  • Added timestamp fields to MonitoredVariable model:
    • created field with auto_now_add=True - automatically set when record is created
    • updated field with auto_now=True - automatically updated whenever record is saved
  • Enhanced admin interface to display the new timestamp fields and make them read-only
  • Created database migration to add the new fields with proper defaults for existing records

Database Schema Updates

  • Updated stored procedure setInstrumentPVs to include the new created and updated fields when inserting MonitoredVariable records
  • Fixed SQL consistency by standardizing all timestamp functions to use CURRENT_TIMESTAMP instead of mixed NOW()/CURRENT_TIMESTAMP usage

Testing & Compatibility

  • Added comprehensive unit tests for the new timestamp field functionality
  • Fixed systemtests compatibility by updating test schemas to match current database structure
  • Validated all changes maintain backward compatibility

Check all that apply:

  • updated documentation
  • Source added/refactored
  • Added unit tests
  • Added integration tests
  • (If applicable) Verified that manual tests requiring the /SNS and /HFIR filesystems pass without fail

References:

  • Links to IBM EWM items: EWM11630
  • Links to related issues or pull requests: N/A

Manual test for the reviewer

  1. Test the migration:
    python manage.py migrate pvmon
  2. Test admin interface:
    • Create a new MonitoredVariable in Django admin
    • Verify created and updated fields are automatically populated and read-only
    • Update an existing MonitoredVariable and confirm updated field changes
  3. Test stored procedures:
    # Test that stored procedure includes timestamp fields
    SELECT setInstrumentPVs('test_instrument', ARRAY['pv1', 'pv2']);
    # Verify MonitoredVariable records have proper created/updated timestamps
    SELECT * FROM pvmon_monitoredvariable WHERE instrument_id = (SELECT id FROM report_instrument WHERE name = 'test_instrument');
  4. Verify audit trail:*
    • Check the created timestamps don't change after updates
    • Check that updated timestamps change when records are modified

Check list for the reviewer

  • best software practices
    • clearly named variables (better to be verbose in variable names)
    • code comments explained the intent of code blocks
  • All the tests are passing
  • The documentation is up to date
  • code comments added when explaining intent

@codecov-commenter
Copy link

codecov-commenter commented Sep 10, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.67%. Comparing base (2c94fe8) to head (b06350f).

Additional details and impacted files
@@            Coverage Diff             @@
##             next     #269      +/-   ##
==========================================
+ Coverage   82.64%   82.67%   +0.03%     
==========================================
  Files          59       60       +1     
  Lines        4426     4434       +8     
==========================================
+ Hits         3658     3666       +8     
  Misses        768      768              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@darshdinger darshdinger merged commit 6bcc18e into next Sep 22, 2025
4 checks passed
@darshdinger darshdinger deleted the ewm11630-add-new-fields-to-MonitoredVariables branch September 22, 2025 18:47
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.

4 participants