2025-01-20 11:59:13 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
|
|
class AddUniqueIndexToPoints < ActiveRecord::Migration[8.0]
|
|
|
|
|
disable_ddl_transaction!
|
|
|
|
|
|
|
|
|
|
def up
|
2025-01-21 08:28:00 -05:00
|
|
|
return if index_exists?(
|
|
|
|
|
:points, %i[latitude longitude timestamp user_id],
|
|
|
|
|
name: 'unique_points_lat_long_timestamp_user_id_index'
|
|
|
|
|
)
|
|
|
|
|
|
2025-01-20 11:59:13 -05:00
|
|
|
add_index :points, %i[latitude longitude timestamp user_id],
|
|
|
|
|
unique: true,
|
2025-01-21 07:33:46 -05:00
|
|
|
name: 'unique_points_lat_long_timestamp_user_id_index',
|
2025-01-20 11:59:13 -05:00
|
|
|
algorithm: :concurrently
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def down
|
2025-01-21 08:28:00 -05:00
|
|
|
return unless index_exists?(
|
|
|
|
|
:points, %i[latitude longitude timestamp user_id],
|
|
|
|
|
name: 'unique_points_lat_long_timestamp_user_id_index'
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
remove_index :points, %i[latitude longitude timestamp user_id],
|
|
|
|
|
name: 'unique_points_lat_long_timestamp_user_id_index'
|
2025-01-20 11:59:13 -05:00
|
|
|
end
|
|
|
|
|
end
|