From 52335d6a64225b64363a6403806f5845a9b3b68a Mon Sep 17 00:00:00 2001 From: Eugene Burmakin Date: Tue, 21 Jan 2025 14:28:00 +0100 Subject: [PATCH] Add index only if it doesn't exist. --- .app_version | 2 +- CHANGELOG.md | 6 ++++++ .../20250120154555_add_unique_index_to_points.rb | 13 ++++++++++++- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/.app_version b/.app_version index 610e2872..fda96dcf 100644 --- a/.app_version +++ b/.app_version @@ -1 +1 @@ -0.23.1 +0.23.2 diff --git a/CHANGELOG.md b/CHANGELOG.md index c4c12037..04da2e91 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/db/migrate/20250120154555_add_unique_index_to_points.rb b/db/migrate/20250120154555_add_unique_index_to_points.rb index 2062c977..0a408cf7 100644 --- a/db/migrate/20250120154555_add_unique_index_to_points.rb +++ b/db/migrate/20250120154555_add_unique_index_to_points.rb @@ -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 @@ def up 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