mysql_framework 2.1.4 → 2.1.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 87c4479177595f0b81fd81122c23473b63416ecf3a6427620c3cef4ba25d3e58
4
- data.tar.gz: c668c3276dfe1120f7be7f8d30238bd1b8123c5559221ec175a1d3d844cc8e80
3
+ metadata.gz: d7cfae16762fc02981eed438b941a6eddbf69df7f24d7d7a6c390604064518da
4
+ data.tar.gz: aba1911d97941727399a9bd815df8453b276761c736ced329298f8c18b65f69e
5
5
  SHA512:
6
- metadata.gz: fc44ac34b35b2c615ce87b8a1a627edc5d9f97c50f14ba3da1cae08e4089b0dcea405c495e48efbba95c852f2418334b3e1c32d029ae3fc4ec09f5d4028cf68d
7
- data.tar.gz: 2eba7935da06a55d525b96126655f6a30415a62cf31225f184a0a305571f4e2f83a292a7214c446b63c01cbdd005b652bf30a2796bcb2e24f8644e8a8182830c
6
+ metadata.gz: ee9ad256b44ed8ec1db8b9039a72324d3045d5e5b2063c88d64605f63c3bf089d4da383cb1ebece12027dea5a20a7d98734e90192874ce2340244286cea2a0fc
7
+ data.tar.gz: 5d867a1db81ccb22887246584ee8020a934e88f11bc5f434ff07e5a1100c89601d13e151406b9c924073a46c72ca3d26b82a4965a1bb02c846cd3239bfc66ebc
@@ -44,10 +44,25 @@ module MysqlFramework
44
44
 
45
45
  def index_exists?(client, table_name, index_name)
46
46
  result = client.query(<<~SQL)
47
- SHOW INDEX FROM #{table_name} WHERE Key_name="#{index_name}" LIMIT 1;
47
+ SHOW INDEX FROM #{table_name} WHERE Key_name="#{index_name}";
48
48
  SQL
49
49
 
50
- result.count == 1
50
+ result.count >= 1
51
+ end
52
+
53
+ def index_up_to_date?(client, table_name, index_name, columns)
54
+ result = client.query(<<~SQL)
55
+ SHOW INDEX FROM #{table_name} WHERE Key_name="#{index_name}";
56
+ SQL
57
+
58
+ return false if result.size != columns.size
59
+
60
+ index_columns = result.sort_by { |column| column[:Seq_in_index] }
61
+ index_columns.each_with_index do |column, i|
62
+ return false if column[:Column_name] != columns[i]
63
+ end
64
+
65
+ true
51
66
  end
52
67
 
53
68
  protected
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MysqlFramework
4
- VERSION = '2.1.4'
4
+ VERSION = '2.1.7'
5
5
  end
@@ -86,4 +86,28 @@ describe MysqlFramework::Scripts::Base do
86
86
  expect(subject.index_exists?(client,'foo','bar')).to eq(false)
87
87
  end
88
88
  end
89
+
90
+ describe '#index_up_to_date?' do
91
+ before do
92
+ expect(client).to receive(:query).and_return(
93
+ [{ Column_name: 'b', Seq_in_index: 2 }, { Column_name: 'a', Seq_in_index: 1 }]
94
+ )
95
+ end
96
+
97
+ it 'returns true when index is up to date' do
98
+ expect(subject.index_up_to_date?(client, 'foo', 'bar', ['a', 'b'])).to eq(true)
99
+ end
100
+
101
+ it 'returns false when index is missing a column' do
102
+ expect(subject.index_up_to_date?(client, 'foo', 'bar', ['a', 'b', 'c'])).to eq(false)
103
+ end
104
+
105
+ it 'returns false when index is having too many columns' do
106
+ expect(subject.index_up_to_date?(client, 'foo', 'bar', ['a'])).to eq(false)
107
+ end
108
+
109
+ it 'returns false when index has columns in wrong order' do
110
+ expect(subject.index_up_to_date?(client, 'foo', 'bar', ['b', 'a'])).to eq(false)
111
+ end
112
+ end
89
113
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mysql_framework
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.4
4
+ version: 2.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sage
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-03-12 00:00:00.000000000 Z
11
+ date: 2023-08-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -137,7 +137,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
137
137
  - !ruby/object:Gem::Version
138
138
  version: '0'
139
139
  requirements: []
140
- rubygems_version: 3.0.8
140
+ rubygems_version: 3.3.5
141
141
  signing_key:
142
142
  specification_version: 4
143
143
  summary: A lightweight framework to provide managers for working with MySQL.