Last active
November 14, 2022 11:17
-
-
Save CodyFitzpatrick/d74d24f36f67b8a42fe6ee7cc6a58c55 to your computer and use it in GitHub Desktop.
Ruby on Rails - Import Data via SQL in seeds.rb
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
# Creation of other records in Ruby above ... | |
connection = ActiveRecord::Base.connection | |
sql = File.read('db/import.sql') # Change path and filename as necessary | |
statements = sql.split(/;$/) | |
statements.pop | |
ActiveRecord::Base.transaction do | |
statements.each do |statement| | |
connection.execute(statement) | |
end | |
end | |
# Creation of other records in Ruby below ... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment