Skip to content

Conversation

@84em
Copy link
Member

@84em 84em commented Nov 5, 2025

Summary

This PR implements the foundational database infrastructure for the priority monitoring feature, including database schema, repository layer, and comprehensive test coverage.

What's Included

Database Schema

  • Priority Rules Table (eightyfourem_integrity_priority_rules)

    • 6 pattern matching types: exact, prefix, suffix, contains, glob, regex
    • Three-tier priority levels: critical, high, normal
    • Maintenance window support
    • Notification throttling
    • WordPress version-specific rules
    • Rule execution ordering
    • Priority inheritance capability
  • Velocity Log Table (eightyfourem_integrity_velocity_log)

    • Change frequency tracking per file and rule
    • Time-windowed velocity detection
    • Foreign key constraints to priority rules
  • Extended Existing Tables

    • Added priority_level column to file_records table
    • Added priority_stats, critical_files_changed, high_priority_files_changed to scan_results table

Repository Layer

  • PriorityRulesRepository (src/Database/PriorityRulesRepository.php)

    • Full CRUD operations
    • Pattern matching against file paths (6 match types)
    • Active rules retrieval with ordering
    • Priority level determination for paths
    • Maintenance window checking
    • Bulk operations (activate/deactivate/delete)
  • VelocityLogRepository (src/Database/VelocityLogRepository.php)

    • Change logging with timestamps
    • Change count retrieval within time windows
    • Velocity threshold detection
    • Statistics aggregation (total changes, unique files)
    • Top changed files reporting
    • Velocity alert generation
    • Cleanup utilities

Testing

  • 38 PHPUnit tests with 99 assertions
  • PriorityRulesRepositoryTest (20 tests, 69 assertions)
    • CRUD operations
    • Pattern matching validation (all 6 types)
    • Glob pattern matching edge cases
    • Priority determination
    • Maintenance window logic
    • Bulk operations
  • VelocityLogRepositoryTest (18 tests, 30 assertions)
    • Change logging
    • Velocity counting
    • Threshold detection
    • Statistics and reporting
    • Alert generation with multiple rules

Integration

  • Migration integrated into DatabaseManager
  • Automatic execution on plugin activation/upgrade
  • Proper indexes for query performance
  • Foreign key constraints for data integrity

Testing Performed

vendor/bin/phpunit tests/Unit/Database/

Result: All 38 tests passing with 99 assertions

Database Migration

  • Migration version: 1.0.0
  • Tables created with proper indexes and foreign keys
  • Existing tables extended with new columns
  • Rollback capability included (commented for safety)

Documentation

  • README updated with Priority Monitoring section
  • CHANGELOG updated with detailed changes
  • Inline documentation for all methods
  • Type declarations throughout (PHP 8.0+)

Next Steps (Future PRs)

  • PR2: Service layer + basic matching logic
  • PR3: UI and management interface
  • PR4: Notifications and WP-CLI commands

Files Changed

  • src/Database/DatabaseManager.php - Integrated migration
  • src/Database/Migrations/PriorityMonitoringMigration.php - New migration
  • src/Database/PriorityRulesRepository.php - New repository
  • src/Database/VelocityLogRepository.php - New repository
  • tests/Unit/Database/PriorityRulesRepositoryTest.php - New tests
  • tests/Unit/Database/VelocityLogRepositoryTest.php - New tests
  • tests/bootstrap.php - Added WordPress function mocks
  • README.md - Documented new feature
  • CHANGELOG.md - Added unreleased section

Review Checklist

  • Database schema follows WordPress naming conventions
  • Repository methods have type declarations
  • All public methods documented
  • Comprehensive test coverage (38 tests, 99 assertions)
  • Migration integrated into DatabaseManager
  • Foreign key constraints added
  • Proper indexes for query performance
  • Documentation updated (README + CHANGELOG)
  • Follows WordPress coding standards
  • No breaking changes to existing functionality

Add database schema, repositories, and tests for priority monitoring system. This foundation enables three-tier file priority classification with velocity tracking and maintenance window support.

Database Schema:
- Priority rules table with 6 pattern matching types
- Velocity log table for change frequency tracking
- Extended file records with priority level column
- Extended scan results with priority statistics

Repositories:
- PriorityRulesRepository with full CRUD operations
- VelocityLogRepository for tracking and analytics
- Pattern matching: exact, prefix, suffix, contains, glob, regex
- Maintenance window and throttling support

Tests:
- 38 PHPUnit tests with 99 assertions
- Full coverage of repository methods
- Pattern matching validation
- Velocity threshold detection

Integration:
- Migration integrated into DatabaseManager
- Automatic execution on plugin activation
- Proper foreign key constraints and indexes

Part of PR1 for priority monitoring feature implementation.
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.

2 participants