openstreetmap-website/db/migrate/20180204153242_tile_users.rb
Andy Allan 6ebb21b660 Avoid using live models in old migrations
Instead, we define models in the migrations themselves. This ensures that
column names etc match the state of the database during the migration,
not the current live version of the model.
2019-07-17 11:52:02 +02:00

20 lines
560 B
Ruby

class TileUsers < ActiveRecord::Migration[5.1]
class User < ActiveRecord::Base
end
def up
add_column :users, :home_tile, :bigint
add_index :users, [:home_tile], :name => "users_home_idx"
if ENV["USE_DB_FUNCTIONS"]
User.update_all("home_tile = tile_for_point(cast(round(home_lat * #{GeoRecord::SCALE}) as integer), cast(round(home_lon * #{GeoRecord::SCALE}) as integer))")
else
User.all.each(&:save!)
end
end
def down
remove_index :users, :name => "users_home_idx"
remove_column :users, :home_tile
end
end