Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save flozano/5d560689c8373e3e50ff5fb421d63ff4 to your computer and use it in GitHub Desktop.
Save flozano/5d560689c8373e3e50ff5fb421d63ff4 to your computer and use it in GitHub Desktop.
[Defer all foreign keys and validations in RoR after dumping seed]
# Assuming 'base.rb' contains a seed dump (https://github.com/rroblak/seed_dump)
# Disable validations
ApplicationRecord.class_eval do
def valid?(a=1)
true
end
end
# Not sure if the transactional code is needed...
ActiveRecord::Base.transaction do
ActiveRecord::Base.connection.execute('set session_replication_role = replica')
load "#{Rails.root}/db/seeds/base.rb"
ActiveRecord::Base.connection.execute('set session_replication_role = default')
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment