diff --git a/CHANGELOG.md b/CHANGELOG.md index 10f5c357..9e20159c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## Fixed - Moving points on the map now works correctly. #957 +- `rake points:migrate_to_lonlat` task now also reindexes the points table. # 0.25.3 - 2025-03-22 diff --git a/app/views/home/index.html.erb b/app/views/home/index.html.erb index 606d4c0d..9b223f40 100644 --- a/app/views/home/index.html.erb +++ b/app/views/home/index.html.erb @@ -1,6 +1,6 @@
-
+

diff --git a/lib/tasks/points.rake b/lib/tasks/points.rake index 1dc141c6..64c73ecd 100644 --- a/lib/tasks/points.rake +++ b/lib/tasks/points.rake @@ -5,15 +5,25 @@ namespace :points do task migrate_to_lonlat: :environment do puts 'Updating points to use lonlat...' - # Use PostGIS functions to properly create geography type - result = ActiveRecord::Base.connection.execute(<<~SQL) - UPDATE points - SET lonlat = ST_SetSRID(ST_MakePoint(longitude, latitude), 4326)::geography - WHERE lonlat IS NULL - AND longitude IS NOT NULL - AND latitude IS NOT NULL; - SQL + ActiveRecord::Base.connection.execute('REINDEX TABLE points;') - puts "Successfully updated #{result.cmd_tuples} points with lonlat values" + ActiveRecord::Base.transaction do + ActiveRecord::Base.connection.execute('ALTER TABLE points DISABLE TRIGGER ALL;') + + # Update the data + result = ActiveRecord::Base.connection.execute(<<~SQL) + UPDATE points + SET lonlat = ST_SetSRID(ST_MakePoint(longitude, latitude), 4326)::geography + WHERE lonlat IS NULL + AND longitude IS NOT NULL + AND latitude IS NOT NULL; + SQL + + ActiveRecord::Base.connection.execute('ALTER TABLE points ENABLE TRIGGER ALL;') + + puts "Successfully updated #{result.cmd_tuples} points with lonlat values" + end + + ActiveRecord::Base.connection.execute('ANALYZE points;') end end