Skip to content

Instantly share code, notes, and snippets.

@MaherSaif
Forked from skatkov/test.rb
Created February 24, 2023 12:56
Show Gist options
  • Save MaherSaif/2f051169406f7b33cb15ccd5550af217 to your computer and use it in GitHub Desktop.
Save MaherSaif/2f051169406f7b33cb15ccd5550af217 to your computer and use it in GitHub Desktop.
speed up testsuit by using unlogged tables in PG
# config/environments/test.rb
ActiveSupport.on_load(:active_record_postgresqladapter) do
# For this optimization to work, you need to recreate your test database
self.create_unlogged_tables = true
end
# Run `RAILS_ENV=test rails c`
puts ActiveRecord::Base.connection.execute("SELECT relpersistence FROM pg_class WHERE relname = 'users'").first
# In case table is unlogged following will be returned:
# {"relpersistence"=>"u"}
# In case table is regular, following will be returned:
#{"relpersistence"=>"p"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment