Skip to content

Commit

Permalink
Add migration
Browse files Browse the repository at this point in the history
  • Loading branch information
JoonasAapro committed Feb 5, 2024
1 parent 9819e97 commit 3e5a8d4
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
1 change: 0 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ PATH
specs:
decidim-locations (0.27.4)
decidim-core (~> 0.27.4)
rgeo-geojson (~> 2.1, >= 2.1.1)

GEM
remote: https://rubygems.org/
Expand Down
25 changes: 25 additions & 0 deletions db/migrate/20240202133245_transfer_existing_locations.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# frozen_string_literal: true

class TransferExistingLocations < ActiveRecord::Migration[6.1]
def up
coord_columns = %w(latitude longitude)

tables_with_columns = ActiveRecord::Base.connection.tables.select do |table|
coord_columns.all? { |column| ActiveRecord::Base.connection.column_exists?(table, column) }
end

tables_with_columns.delete("decidim_locations_locations")

tables_with_columns.each do |table|
execute <<-SQL.squish
SELECT id, latitude, longitude from #{table}
SQL
end

execute <<-SQL.squish
INSERT INTO decidim_locations_locations (address, latitude, longitude, shape, geojson, decidim_locations_locatable_type, decidim_locations_locatable_id)
VALUES
()
SQL
end
end
2 changes: 0 additions & 2 deletions decidim-tags.gemspec → decidim-locations.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,5 @@ Gem::Specification.new do |spec|

spec.add_development_dependency "decidim-dev", Decidim::Locations::DECIDIM_VERSION

spec.add_dependency "rgeo-geojson", "~> 2.1", ">= 2.1.1"

spec.metadata["rubygems_mfa_required"] = "true"
end

0 comments on commit 3e5a8d4

Please sign in to comment.