How to create raw sql seed migration

I created a city model and I have all the cities that I need to store in the city table in a .sql file. This sql file has all the required insertion instructions.

So, I would like to create a semester file to add all the cities from the sql file. How can I seed the database using sql commands?

Thank!

+3


source to share


1 answer


By using the following code you will achieve what you want

connection = ActiveRecord::Base.connection();
connection.execute("SQL COMMANDS")

      



This will be needed in the seed.rb file

Then you need to execute rake db:seed

+4


source







All Articles