Add index only if it doesn't exist.

This commit is contained in:
Eugene Burmakin 2025-01-21 14:28:00 +01:00
parent 4c6baad5d4
commit 52335d6a64
3 changed files with 19 additions and 2 deletions

View file

@ -1 +1 @@
0.23.1
0.23.2

View file

@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).
# 0.23.2 - 2025-01-21
### Fixed
- Add index only if it doesn't exist.
# 0.23.1 - 2025-01-21
### Fixed

View file

@ -4,6 +4,11 @@ class AddUniqueIndexToPoints < ActiveRecord::Migration[8.0]
disable_ddl_transaction!
def up
return if index_exists?(
:points, %i[latitude longitude timestamp user_id],
name: 'unique_points_lat_long_timestamp_user_id_index'
)
add_index :points, %i[latitude longitude timestamp user_id],
unique: true,
name: 'unique_points_lat_long_timestamp_user_id_index',
@ -11,6 +16,12 @@ class AddUniqueIndexToPoints < ActiveRecord::Migration[8.0]
end
def down
remove_index :points, name: 'unique_points_lat_long_timestamp_user_id_index'
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'
end
end