mirror of
https://github.com/Freika/dawarich.git
synced 2026-01-10 17:21:38 -05:00
Move points migration to points rake task
This commit is contained in:
parent
dbd9b7f31f
commit
a018e7c981
3 changed files with 23 additions and 18 deletions
|
|
@ -13,8 +13,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
|
|||
|
||||
## Added
|
||||
|
||||
- `rake data:cleanup:remove_duplicate_points` task added to remove duplicate points from the database and export them to a CSV file.
|
||||
- `rake data:cleanup:update_points_to_use_lonlat` task added for convenient manual migration of points to the new `lonlat` column.
|
||||
- `rake data_cleanup:remove_duplicate_points` task added to remove duplicate points from the database and export them to a CSV file.
|
||||
- `rake points:migrate_to_lonlat` task added for convenient manual migration of points to the new `lonlat` column.
|
||||
- `rake users:activate` task added to activate all users.
|
||||
|
||||
## Changed
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'csv'
|
||||
|
||||
namespace :data_cleanup do
|
||||
|
|
@ -100,20 +102,4 @@ namespace :data_cleanup do
|
|||
puts 'No duplicate points to remove'
|
||||
end
|
||||
end
|
||||
|
||||
desc 'Update points to use lonlat field from latitude and longitude'
|
||||
task update_points_to_use_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
|
||||
|
||||
puts "Successfully updated #{result.cmd_tuples} points with lonlat values"
|
||||
end
|
||||
end
|
||||
|
|
|
|||
19
lib/tasks/points.rake.ra
Normal file
19
lib/tasks/points.rake.ra
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
namespace :points do
|
||||
desc 'Update points to use lonlat field from latitude and longitude'
|
||||
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
|
||||
|
||||
puts "Successfully updated #{result.cmd_tuples} points with lonlat values"
|
||||
end
|
||||
end
|
||||
Loading…
Reference in a new issue