forked from akiratosetiawan/realcount
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b00fefe
commit 6e343bf
Showing
2 changed files
with
43 additions
and
14 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# This file should contain all the record creation needed to seed the database with its default values. | ||
# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup). | ||
# | ||
# Examples: | ||
# | ||
# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }]) | ||
# Mayor.create(name: 'Emanuel', city: cities.first) | ||
|
||
|
||
inserts = [] | ||
|
||
File.open("db/data", "r").each_line do |line| | ||
desa = line[27..52].strip.gsub("'", "''") | ||
kelurahan_id = line[53..59].strip | ||
tps_id = line[60..63].strip | ||
inserts.push("('#{desa}', '#{kelurahan_id}' , '#{tps_id}')") | ||
end | ||
|
||
CONN = ActiveRecord::Base.connection | ||
|
||
puts "Inserting TPS data" | ||
slices = inserts.each_slice(100).to_a | ||
slices.each do |slice| | ||
sql = "INSERT INTO tps(desa, kelurahan_id, tps_id) VALUES #{slice.join(',')}" | ||
CONN.execute(sql) | ||
end | ||
puts "Inserted TPS data" |
This file contains 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