Module: Pilipinas::Loader
- Defined in:
- lib/pilipinas/loader.rb
Overview
Seeds the application database with Philippine geographic data.
Reads directly from the gem’s bundled YAML files and writes to the four pilipinas_* tables via ActiveRecord. The loader is designed to be:
-
Idempotent — uses
upsert_all(Rails 6.1+) so re-running the Rake task is safe. Falls back toinsert_all(Rails 6.0) or individualcreate!calls on older versions. -
Memory-efficient — rows are inserted in batches of BATCH_SIZE (default 500) so the process never holds a 42 k-row Array in memory.
-
Atomic — all four tables are seeded inside a single transaction; a failure rolls back everything, leaving no partial data.
Constant Summary collapse
- BATCH_SIZE =
Number of rows inserted per SQL statement. 500 balances SQL statement size against the number of round-trips.
500
Class Method Summary collapse
-
.run ⇒ void
Seed all four geographic tables inside a single transaction.
Class Method Details
.run ⇒ void
This method returns an undefined value.
Seed all four geographic tables inside a single transaction.
29 30 31 32 33 34 35 36 |
# File 'lib/pilipinas/loader.rb', line 29 def run ActiveRecord::Base.transaction do seed(Db::Region, 'regions.yml') seed(Db::Province, 'provinces.yml') seed(Db::City, 'cities.yml') seed(Db::Barangay, 'barangays.yml') end end |