0.02
No release in over 3 years
Low commit activity in last 3 years
Check your footprint file into source control
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.7
>= 0
~> 10.0
>= 0
~> 0.37.0

Runtime

 Project Readme

SqlFootprint Build Status

This gem allows you to keep a "footprint" of the sql queries that your application runs. It's like logging all the sql you're executing except that we remove all the value parameters and dedupe similar queries. This footprint should be valuable in determining if changes you've made will significantly change the way you're querying the database.

Installation

Add this line to your application's Gemfile:

gem 'sql_footprint', group: [:development, :test]

And then execute:

$ bundle

Usage

Typically, you would want to run this while you're running your specs. For example w/ RSpec:

RSpec.configure do |config|
  config.before(:suite) { SqlFootprint.start }
  config.after(:suite) { SqlFootprint.stop }
end

Minitest (in test_helper.rb) add the following:

SqlFootprint.start
Minitest.after_run { SqlFootprint.stop }

You can also add a Custom rule to SqlAnonymizer before running start:

RSpec.configure do |config|
  SqlFootprint::SqlAnonymizer.add_rule(/SELECT (.+) AS (.+)/, 'SELECT [redacted] AS [redacted]')
  config.before(:suite) { SqlFootprint.start }
  config.after(:suite) { SqlFootprint.stop }
end

Outputs

After running your specs you'll find a 'footprint.*.sql' file in your project. Footprints are per-database. For example, if you're using DB1 AND DB2 in your app, you would end up with two footprint files. (footprint.db1.sql, footprint.db2.sql)

If you're using an in-memory database, you'll end up with footprint.:memory:.sql.

Excluding Setup Code

If you want to exclude queries that your tests generate for fixture data, you can use the .exclude method. For example:

before do
  SqlFootprint.exclude do
    Model.create!(args*) # this query will not be included in your footprint
  end
end

Or if you're using FactoryBot you could do something like this:

RSpec.configure do |config|
  module FactoryKid
    def create(*args)
      SqlFootprint.exclude { FactoryBot.create(*args) }
    end
  end
  config.include FactoryKid
end

Compatibility

  • For Rails < 6.0 compatibility, please use v2.0.1.
  • For Rails >= 6.0 compatibility, please use v3.0.0.
  • For Rails >= 7.0, please use v3.0.1

DO NOT run SqlFootprint in production!