Last active
January 3, 2024 18:20
-
-
Save skatkov/e482617b2a1f9635738a0b66ec0cb327 to your computer and use it in GitHub Desktop.
speed up testsuit by using unlogged tables in PG
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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
More details about this peace of a code could be found hon my twitter:
https://twitter.com/5katkov/status/1628331293967810561