pilipinas 1.1.2 → 1.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +17 -0
- data/Gemfile.lock +4 -4
- data/README.md +1 -1
- data/lib/generators/pilipinas/code_indexes_generator.rb +4 -4
- data/lib/generators/templates/add_pilipinas_code_indexes.rb +5 -5
- data/lib/pilipinas/loader.rb +31 -12
- data/lib/pilipinas/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: '069c53de29b6607d4f19d961e085870e474ee3f53e5a9950d5564211d05b7286'
|
|
4
|
+
data.tar.gz: fbaa56417882627d836b445625b65fab4cd2077fc4f901019dc2c841b38f6c4f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 9bf493ab7a8d154f11c17b992d93abb8695e3c92b9286a8be3c14d0aad1d95568f2abb5467cbb86416a082cfda21eda542103cffd0e039aae32bbe34d9b3575f
|
|
7
|
+
data.tar.gz: a11da75e206b70b6c1fb8cee5f0e3f132ddaa74b10beb3a51e946271f415367511cddce3f6a9c307ba8eb46ba7fcd64f8094c5ca2fbf5604de3c5c86ee4cc395
|
data/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,23 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
---
|
|
9
9
|
|
|
10
|
+
## [1.1.3] - 2026-06-13
|
|
11
|
+
|
|
12
|
+
### Fixed
|
|
13
|
+
|
|
14
|
+
- `rake pilipinas:load` now upserts ActiveRecord seed rows by `location_id` instead of `code`, matching the stable identifier from `lib/data/pilipinas_data.yml`.
|
|
15
|
+
- `rails generate pilipinas:code_indexes` now generates a migration that adds unique `location_id` indexes to all four `pilipinas_*` tables, matching the loader's upsert conflict target.
|
|
16
|
+
|
|
17
|
+
### Changed
|
|
18
|
+
|
|
19
|
+
- Updated loader upgrade guidance and README wording to reference the required `location_id` unique indexes.
|
|
20
|
+
|
|
21
|
+
### Tests
|
|
22
|
+
|
|
23
|
+
- Added regression coverage that asserts `Loader.bulk_insert` uses `location_id` as the `upsert_all` unique key and reports the matching missing-index guidance.
|
|
24
|
+
|
|
25
|
+
---
|
|
26
|
+
|
|
10
27
|
## [1.1.2] - 2026-06-12
|
|
11
28
|
|
|
12
29
|
### Fixed
|
data/Gemfile.lock
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
pilipinas (1.1.
|
|
4
|
+
pilipinas (1.1.3)
|
|
5
5
|
|
|
6
6
|
GEM
|
|
7
7
|
remote: https://rubygems.org/
|
|
@@ -76,7 +76,7 @@ GEM
|
|
|
76
76
|
prism (>= 1.3.0)
|
|
77
77
|
rdoc (>= 4.0.0)
|
|
78
78
|
reline (>= 0.4.2)
|
|
79
|
-
json (2.19.
|
|
79
|
+
json (2.19.9)
|
|
80
80
|
language_server-protocol (3.17.0.5)
|
|
81
81
|
lint_roller (1.1.0)
|
|
82
82
|
logger (1.7.0)
|
|
@@ -280,7 +280,7 @@ CHECKSUMS
|
|
|
280
280
|
i18n (1.14.8) sha256=285778639134865c5e0f6269e0b818256017e8cde89993fdfcbfb64d088824a5
|
|
281
281
|
io-console (0.8.2) sha256=d6e3ae7a7cc7574f4b8893b4fca2162e57a825b223a177b7afa236c5ef9814cc
|
|
282
282
|
irb (1.18.0) sha256=de9454a0703a54704b9811a5ef31a60c86949fbf4013fcf244fabc7c775248e3
|
|
283
|
-
json (2.19.
|
|
283
|
+
json (2.19.9) sha256=9b9025b7cdddafa38d316eca0b2358488e42d417045c1b90d216a9fefe46b79a
|
|
284
284
|
language_server-protocol (3.17.0.5) sha256=fd1e39a51a28bf3eec959379985a72e296e9f9acfce46f6a79d31ca8760803cc
|
|
285
285
|
lint_roller (1.1.0) sha256=2c0c845b632a7d172cb849cc90c1bce937a28c5c8ccccb50dfd46a485003cc87
|
|
286
286
|
logger (1.7.0) sha256=196edec7cc44b66cfb40f9755ce11b392f21f7967696af15d274dde7edff0203
|
|
@@ -296,7 +296,7 @@ CHECKSUMS
|
|
|
296
296
|
nokogiri (1.19.3-x86_64-linux-musl) sha256=248c906d2166eca5efb56d52fdee5f9a1f51d69a72e2b64fdac647b4ce39ea3f
|
|
297
297
|
parallel (2.1.0) sha256=b35258865c2e31134c5ecb708beaaf6772adf9d5efae28e93e99260877b09356
|
|
298
298
|
parser (3.3.11.1) sha256=d17ace7aabe3e72c3cc94043714be27cc6f852f104d81aa284c2281aecc65d54
|
|
299
|
-
pilipinas (1.1.
|
|
299
|
+
pilipinas (1.1.3)
|
|
300
300
|
pp (0.6.3) sha256=2951d514450b93ccfeb1df7d021cae0da16e0a7f95ee1e2273719669d0ab9df6
|
|
301
301
|
prettyprint (0.2.0) sha256=2bc9e15581a94742064a3cc8b0fb9d45aae3d03a1baa6ef80922627a0766f193
|
|
302
302
|
prism (1.9.0) sha256=7b530c6a9f92c24300014919c9dcbc055bf4cdf51ec30aed099b06cd6674ef85
|
data/README.md
CHANGED
|
@@ -177,7 +177,7 @@ rake pilipinas:load
|
|
|
177
177
|
> **Upgrading from an older version?**
|
|
178
178
|
>
|
|
179
179
|
> If `rake pilipinas:load` raises
|
|
180
|
-
> `Pilipinas::Error: pilipinas:load requires a unique index on the
|
|
180
|
+
> `Pilipinas::Error: pilipinas:load requires a unique index on the location_id column`,
|
|
181
181
|
> your database was created with an earlier migration that did not include those
|
|
182
182
|
> indexes. Add them with the dedicated generator:
|
|
183
183
|
>
|
|
@@ -4,13 +4,13 @@ require 'rails/generators/base'
|
|
|
4
4
|
require 'rails/generators/active_record'
|
|
5
5
|
|
|
6
6
|
module Pilipinas
|
|
7
|
-
# Rails generator that adds unique indexes on the +
|
|
8
|
-
# pilipinas_* tables.
|
|
7
|
+
# Rails generator that adds unique indexes on the +location_id+ column to all
|
|
8
|
+
# four pilipinas_* tables.
|
|
9
9
|
#
|
|
10
10
|
# Run this if your database was created with an older version of the gem
|
|
11
11
|
# that did not include these indexes, and +rake pilipinas:load+ raises:
|
|
12
12
|
#
|
|
13
|
-
# ArgumentError: No unique index found for
|
|
13
|
+
# ArgumentError: No unique index found for location_id
|
|
14
14
|
#
|
|
15
15
|
# @example
|
|
16
16
|
# rails generate pilipinas:code_indexes
|
|
@@ -23,7 +23,7 @@ module Pilipinas
|
|
|
23
23
|
|
|
24
24
|
def generate_migration
|
|
25
25
|
migration_template 'templates/add_pilipinas_code_indexes.rb',
|
|
26
|
-
'db/migrate/
|
|
26
|
+
'db/migrate/add_pilipinas_location_id_indexes.rb'
|
|
27
27
|
end
|
|
28
28
|
|
|
29
29
|
# @param _dir [String] unused (required by the interface)
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
class
|
|
1
|
+
class AddPilipinasLocationIdIndexes < ActiveRecord::Migration<%= migration_version %>
|
|
2
2
|
def change
|
|
3
|
-
add_index :pilipinas_regions, :
|
|
4
|
-
add_index :pilipinas_provinces, :
|
|
5
|
-
add_index :pilipinas_cities, :
|
|
6
|
-
add_index :pilipinas_barangays, :
|
|
3
|
+
add_index :pilipinas_regions, :location_id, unique: true, if_not_exists: true
|
|
4
|
+
add_index :pilipinas_provinces, :location_id, unique: true, if_not_exists: true
|
|
5
|
+
add_index :pilipinas_cities, :location_id, unique: true, if_not_exists: true
|
|
6
|
+
add_index :pilipinas_barangays, :location_id, unique: true, if_not_exists: true
|
|
7
7
|
end
|
|
8
8
|
end
|
data/lib/pilipinas/loader.rb
CHANGED
|
@@ -42,15 +42,21 @@ module Pilipinas
|
|
|
42
42
|
#
|
|
43
43
|
# @return [void]
|
|
44
44
|
def run
|
|
45
|
+
records = nil
|
|
45
46
|
column_indexes, records = full_location_table
|
|
46
47
|
|
|
47
|
-
ActiveRecord::Base.
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
48
|
+
ActiveRecord::Base.uncached do
|
|
49
|
+
ActiveRecord::Base.transaction do
|
|
50
|
+
FULL_DATA_SEEDS.each do |model_name, type, attributes|
|
|
51
|
+
model = Db.const_get(model_name)
|
|
52
|
+
delete_stale_compact_rows(model)
|
|
53
|
+
seed_full_data(model, records, column_indexes, type, attributes)
|
|
54
|
+
end
|
|
52
55
|
end
|
|
53
56
|
end
|
|
57
|
+
ensure
|
|
58
|
+
records&.clear
|
|
59
|
+
clear_query_cache
|
|
54
60
|
end
|
|
55
61
|
|
|
56
62
|
private
|
|
@@ -92,10 +98,11 @@ module Pilipinas
|
|
|
92
98
|
next if batch.size < BATCH_SIZE
|
|
93
99
|
|
|
94
100
|
bulk_insert(model, batch)
|
|
95
|
-
batch
|
|
101
|
+
batch.clear
|
|
96
102
|
end
|
|
97
103
|
|
|
98
104
|
bulk_insert(model, batch) unless batch.empty?
|
|
105
|
+
batch.clear
|
|
99
106
|
end
|
|
100
107
|
|
|
101
108
|
# @param record [Array] full location dump row
|
|
@@ -135,16 +142,17 @@ module Pilipinas
|
|
|
135
142
|
records.each_slice(BATCH_SIZE) do |slice|
|
|
136
143
|
batch = slice.map { |r| r.transform_keys(&:to_s).merge('created_at' => now, 'updated_at' => now) }
|
|
137
144
|
bulk_insert(model, batch)
|
|
145
|
+
batch.clear
|
|
138
146
|
end
|
|
139
147
|
end
|
|
140
148
|
|
|
141
149
|
# Perform the most capable bulk-insert available for this AR version.
|
|
142
150
|
#
|
|
143
151
|
# +upsert_all+ (Rails 6.1+) is idempotent — it updates existing rows
|
|
144
|
-
# matched by the unique index on +
|
|
145
|
-
#
|
|
146
|
-
#
|
|
147
|
-
#
|
|
152
|
+
# matched by the unique index on +location_id+, the stable identifier in
|
|
153
|
+
# the full location dump. Compact rows from older loader versions have a
|
|
154
|
+
# NULL +location_id+ and are deleted before the canonical full-data rows
|
|
155
|
+
# are inserted.
|
|
148
156
|
#
|
|
149
157
|
# +insert_all+ (Rails 6.0) silently skips conflicts.
|
|
150
158
|
# Legacy path: individual +create!+ calls (raises on conflict).
|
|
@@ -155,10 +163,10 @@ module Pilipinas
|
|
|
155
163
|
def bulk_insert(model, batch)
|
|
156
164
|
if model.respond_to?(:upsert_all)
|
|
157
165
|
begin
|
|
158
|
-
model.upsert_all(batch, unique_by: :
|
|
166
|
+
model.upsert_all(batch, unique_by: :location_id)
|
|
159
167
|
rescue ArgumentError
|
|
160
168
|
raise Pilipinas::Error,
|
|
161
|
-
'pilipinas:load requires a unique index on the `
|
|
169
|
+
'pilipinas:load requires a unique index on the `location_id` column, ' \
|
|
162
170
|
"which is missing from #{model.table_name}. " \
|
|
163
171
|
'Your database was likely created with an older version of the gem. ' \
|
|
164
172
|
"Run the following to add the missing indexes and retry:\n\n " \
|
|
@@ -170,6 +178,17 @@ module Pilipinas
|
|
|
170
178
|
else
|
|
171
179
|
batch.each { |attrs| model.unscoped.create!(attrs) }
|
|
172
180
|
end
|
|
181
|
+
ensure
|
|
182
|
+
clear_query_cache
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
# Clear any per-connection query-cache state so a long-running Rails
|
|
186
|
+
# process does not retain loader queries or bind values between batches.
|
|
187
|
+
#
|
|
188
|
+
# @return [void]
|
|
189
|
+
def clear_query_cache
|
|
190
|
+
connection = ActiveRecord::Base.connection
|
|
191
|
+
connection.clear_query_cache if connection.respond_to?(:clear_query_cache)
|
|
173
192
|
end
|
|
174
193
|
|
|
175
194
|
# @return [Time] current UTC time, compatible with or without ActiveSupport
|
data/lib/pilipinas/version.rb
CHANGED