Ruby on Rails - Seeding big data (over 2.7M) record to production database

Viewed 688

In my application I have a City model. I have a sql file that contains all the cities in the world (its over 2.7M) & I need to seed all of them to my production server.

I know usually I could do this in seeds.rb:

cities = City.create([

{id: 1, name: 'Bombuflat',  state_id: 1},
{id: 2, name: 'Garacharma',  state_id: 1},
{id: 3, name: 'Port Blair',  state_id: 1},
// Other cities
])

But since this is a big data to seed, it will take really long time to add id, name, state_id on each line.

Right now my cities.sql has a array of cities like:

//id, state_id, name
(1, 1, 'Aixàs'),
(2, 1, 'Aixirivali'),
(3, 1, 'Aixirivall')

What is the best way to do this so I don't need to add id, name, state_id to each line and maybe use the array I already have.

2 Answers
Related