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-aware — rows are transformed and inserted in batches of BATCH_SIZE (default 500) so the process never holds a full ActiveRecord insert payload 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.
44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/pilipinas/loader.rb', line 44 def run column_indexes, records = full_location_table ActiveRecord::Base.transaction do FULL_DATA_SEEDS.each do |model_name, type, attributes| model = Db.const_get(model_name) delete_stale_compact_rows(model) seed_full_data(model, records, column_indexes, type, attributes) end end end |