From 4c6baad5d4ac5e85f5a12c599731a924ef3352ec Mon Sep 17 00:00:00 2001 From: Eugene Burmakin Date: Tue, 21 Jan 2025 13:33:46 +0100 Subject: [PATCH 1/2] Rename unique index on points to `unique_points_lat_long_timestamp_user_id_index` --- .app_version | 2 +- CHANGELOG.md | 6 ++++++ db/migrate/20250120154555_add_unique_index_to_points.rb | 4 ++-- db/schema.rb | 2 +- 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/.app_version b/.app_version index ca222b7c..610e2872 100644 --- a/.app_version +++ b/.app_version @@ -1 +1 @@ -0.23.0 +0.23.1 diff --git a/CHANGELOG.md b/CHANGELOG.md index 2f4efd0e..c4c12037 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.1 - 2025-01-21 + +### Fixed + +- Renamed unique index on points to `unique_points_lat_long_timestamp_user_id_index` to fix naming conflict with `unique_points_index`. + # 0.23.0 - 2025-01-20 ## ⚠️ IMPORTANT ⚠️ diff --git a/db/migrate/20250120154555_add_unique_index_to_points.rb b/db/migrate/20250120154555_add_unique_index_to_points.rb index fc224ab0..2062c977 100644 --- a/db/migrate/20250120154555_add_unique_index_to_points.rb +++ b/db/migrate/20250120154555_add_unique_index_to_points.rb @@ -6,11 +6,11 @@ class AddUniqueIndexToPoints < ActiveRecord::Migration[8.0] def up add_index :points, %i[latitude longitude timestamp user_id], unique: true, - name: 'unique_points_index', + name: 'unique_points_lat_long_timestamp_user_id_index', algorithm: :concurrently end def down - remove_index :points, name: 'unique_points_index' + remove_index :points, name: 'unique_points_lat_long_timestamp_user_id_index' end end diff --git a/db/schema.rb b/db/schema.rb index 8fc8554c..c4529687 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -168,7 +168,7 @@ ActiveRecord::Schema[8.0].define(version: 2025_01_20_154555) do t.index ["external_track_id"], name: "index_points_on_external_track_id" t.index ["geodata"], name: "index_points_on_geodata", using: :gin t.index ["import_id"], name: "index_points_on_import_id" - t.index ["latitude", "longitude", "timestamp", "user_id"], name: "unique_points_index", unique: true + t.index ["latitude", "longitude", "timestamp", "user_id"], name: "unique_points_lat_long_timestamp_user_id_index", unique: true t.index ["latitude", "longitude"], name: "index_points_on_latitude_and_longitude" t.index ["reverse_geocoded_at"], name: "index_points_on_reverse_geocoded_at" t.index ["timestamp"], name: "index_points_on_timestamp" From 52335d6a64225b64363a6403806f5845a9b3b68a Mon Sep 17 00:00:00 2001 From: Eugene Burmakin Date: Tue, 21 Jan 2025 14:28:00 +0100 Subject: [PATCH 2/2] 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 @@ 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