online_migrations 0.19.2 → 0.19.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: aefd589066f5ee8e4d42964683576a6407782d5a065dae55c42336c4b50af8c6
4
- data.tar.gz: 1723e4fd7388be89ac5b30095a4431a5829729b90b984054752ba1645c318b68
3
+ metadata.gz: 4d8223e51d4016b3752a738ecbc04cc200c94ee44dd3d91a1be2aefbc74060a9
4
+ data.tar.gz: bbaa8a04c4b730ac33e1503c59782658f6810f9782b4f882ab2b19bd0e0402d2
5
5
  SHA512:
6
- metadata.gz: c964e25e31eed2fab19c6c205c7c0355ca8fbb1eced99898d17a0385b8f5f8411a8cf1822df3973efe5e69a5fbe7620ee8150e97f167996f55347732b9bcb8c4
7
- data.tar.gz: c90709c6369c7a3f5d8c36a92f1a4e98099a538957ac7f282ea04b594df1ffb814d1ef5f5a803a4692c377984ae74ef0b4ddd77ec0e32c91c201087d9d0eafe5
6
+ metadata.gz: 878031d1e81e5a069500e4c9c8f0d2bb9b9b60320e07ce101a7ae8680556a6a8114de4d0f6bf092340ec3651f9bbbb74fdc6e6453db39be3c22f6846b5a2ad94
7
+ data.tar.gz: 143a618f2d46a8a452c9f32ca87f44e47dffe5268bae00dcff008f54865cf272e20bb6aa4af7243cf642a195e64e9aed8269660f1658ebb3440bff12eeed37df
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  ## master (unreleased)
2
2
 
3
+ ## 0.19.3 (2024-08-09)
4
+
5
+ - Fix idempotency for `add_index`/`remove_index` for expression indexes
6
+
3
7
  ## 0.19.2 (2024-07-09)
4
8
 
5
9
  - Fix `add_reference_concurrently` to be idempotent when adding a foreign key
@@ -684,9 +684,17 @@ module OnlineMigrations
684
684
  def add_index(table_name, column_name, **options)
685
685
  __ensure_not_in_transaction! if options[:algorithm] == :concurrently
686
686
 
687
- # Rewrite this with `IndexDefinition#defined_for?` when Active Record >= 7.1 is supported.
688
- # See https://github.com/rails/rails/pull/45160.
689
- index = indexes(table_name).find { |i| __index_defined_for?(i, column_name, **options) }
687
+ index =
688
+ if column_name.is_a?(String) && column_name.match?(/\W/)
689
+ # Use only name to check if index exists, because it does not work for complex expressions.
690
+ index_name = (options[:name] || index_name(table_name, column_name)).to_s
691
+ indexes(table_name).find { |i| i.name == index_name }
692
+ else
693
+ # Rewrite this with `IndexDefinition#defined_for?` when Active Record >= 7.1 is supported.
694
+ # See https://github.com/rails/rails/pull/45160.
695
+ indexes(table_name).find { |i| __index_defined_for?(i, column_name, **options) }
696
+ end
697
+
690
698
  if index
691
699
  schema = __schema_for_table(table_name)
692
700
 
@@ -729,7 +737,17 @@ module OnlineMigrations
729
737
 
730
738
  __ensure_not_in_transaction! if options[:algorithm] == :concurrently
731
739
 
732
- if index_exists?(table_name, column_name, **options)
740
+ column = column_name || options[:column]
741
+ index_exists =
742
+ if column.is_a?(String) && column.match?(/\W/)
743
+ # Use only name to check if index exists, because it does not work for complex expressions.
744
+ index_name = options[:name] || index_name(table_name, column)
745
+ index_name_exists?(table_name, index_name)
746
+ else
747
+ index_exists?(table_name, column_name, **options)
748
+ end
749
+
750
+ if index_exists
733
751
  if OnlineMigrations.config.statement_timeout
734
752
  # "DROP INDEX CONCURRENTLY" requires a "SHARE UPDATE EXCLUSIVE" lock.
735
753
  # It only conflicts with constraint validations, other creating/removing indexes,
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module OnlineMigrations
4
- VERSION = "0.19.2"
4
+ VERSION = "0.19.3"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: online_migrations
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.19.2
4
+ version: 0.19.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - fatkodima
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-07-09 00:00:00.000000000 Z
11
+ date: 2024-08-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord