Skip to content

Instantly share code, notes, and snippets.

@skatkov
Last active January 3, 2024 18:20
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save skatkov/e482617b2a1f9635738a0b66ec0cb327 to your computer and use it in GitHub Desktop.
Save skatkov/e482617b2a1f9635738a0b66ec0cb327 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"}
@skatkov
Copy link
Author

skatkov commented Feb 23, 2023

More details about this peace of a code could be found hon my twitter:
https://twitter.com/5katkov/status/1628331293967810561

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment