Skip to content

Commit

Permalink
Add index only if it doesn't exist.
Browse files Browse the repository at this point in the history
  • Loading branch information
Freika committed Jan 21, 2025
1 parent 4c6baad commit 52335d6
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .app_version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.23.1
0.23.2
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 12 additions & 1 deletion db/migrate/20250120154555_add_unique_index_to_points.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,24 @@ 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',
algorithm: :concurrently
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

0 comments on commit 52335d6

Please sign in to comment.