Skip to content

feat: add db:benchmark, db:validate, and QueryCounter helper#733

Open
aaronlippold wants to merge 1 commit into
masterfrom
feat/db-migration-benchmarks
Open

feat: add db:benchmark, db:validate, and QueryCounter helper#733
aaronlippold wants to merge 1 commit into
masterfrom
feat/db-migration-benchmarks

Conversation

@aaronlippold
Copy link
Copy Markdown
Member

  • db:benchmark — captures timing + query counts for key endpoints, saves JSON baseline, auto-compares with previous run
  • db:validate — checks FK integrity, orphaned records, NULLs, duplicates, counter cache consistency post-migration
  • QueryCounter — RSpec helper for assert_query_count_at_most in request and model specs

Authored by: Aaron Lippoldlippold@gmail.com

- db:benchmark — captures timing + query counts for key endpoints,
  saves JSON baseline, auto-compares with previous run
- db:validate — checks FK integrity, orphaned records, NULLs,
  duplicates, counter cache consistency post-migration
- QueryCounter — RSpec helper for assert_query_count_at_most
  in request and model specs

Authored by: Aaron Lippold<lippold@gmail.com>
@sonarqubecloud
Copy link
Copy Markdown

@aaronlippold aaronlippold temporarily deployed to vulcan-feat-db-migratio-liiqui May 21, 2026 03:36 Inactive
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds developer tooling to measure and validate database behavior in the Rails app: a reusable RSpec query-counting helper plus two new db:* rake tasks for performance baselining and post-migration integrity checks.

Changes:

  • Introduces QueryCounter RSpec helper (assert_query_count_at_most) for request/model specs.
  • Adds db:validate rake task to check for orphans, unexpected NULLs, duplicates, and counter-cache drift.
  • Adds db:benchmark rake task to time key operations and record/compare query counts and timings to JSON baselines.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
spec/support/query_counter.rb Adds a query counting + assertion helper, included into request/model specs.
lib/tasks/db_validate.rake Implements integrity validation checks across core tables/relations.
lib/tasks/db_benchmark.rake Implements a benchmarking task that measures timings and query counts and saves JSON baselines.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

].each do |table|
next unless conn.table_exists?(table)

count = conn.execute("SELECT COUNT(*) AS c FROM #{conn.quote_table_name(table)}").first['c']
Comment on lines +80 to +90
if component.rules.exists?(locked: false)
component.rules.update_all(locked: true) # rubocop:disable Rails/SkipsModelValidations
component.update_column(:released, true) # rubocop:disable Rails/SkipsModelValidations
end
results['component_duplicate_ms'] = (Benchmark.measure do
dup = component.duplicate(
new_name: 'Benchmark Dup', new_version: 99,
new_release: 99, new_title: 'Benchmark', new_description: 'perf test'
)
dup&.destroy
end.real * 1000).round(1)
ActiveSupport::Notifications.subscribed(counter, 'sql.active_record') do
component.reload
component.rules.includes(
:reviews, :disa_rule_descriptions, :checks
count = 0
counter = lambda do |_name, _start, _finish, _id, payload|
sql = payload[:sql].to_s
next if payload[:name] == 'SCHEMA'
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