shiba 0.9.3 → 0.9.4

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
- SHA256:
3
- metadata.gz: '0035975f2585607e2aa44f84064fa8ae1bcec4cfbfbf78831595d9de8c690779'
4
- data.tar.gz: 3e7bc106fc1c90d3551837411d34f282814f3e8334e215b59dbb67485ff30461
2
+ SHA1:
3
+ metadata.gz: b605c4306ab0ccc32f881973a7cea994b50db84a
4
+ data.tar.gz: c19790bf5c25d35b80973395e13cee7b644fdba3
5
5
  SHA512:
6
- metadata.gz: c4dff81f128bfc76958f7fc71f26861e5e1594d64c79ec32ea8da8d2421d0a30574e24ad8c2255d38d45f5f0bf6ad30ec2248864b159ab30b6ebcba2c0cb352f
7
- data.tar.gz: 4d1f746c8c7d5eedfe9708f4fea54b154c17e79c7c6bdbd91fa41994b6f4f32c1227a4511f9ad04d5a8d56747281835f9a47125a8c5b974366d27dd0ee62f4ce
6
+ metadata.gz: abad67fe6c72f8dbce81a10ccacdcd024ec6d9c3d1a9c55f463ecf6825b7a48ad77578a12ced06df67770675ff785f9b861d8444880c67789a980fa49e102393
7
+ data.tar.gz: fb92c8fbb81b39a925bcdc5a85f37a974fd938c000956d1c02a44bfd4c7730b306a32d57e12b1d95f1717e70095a3d1a14339938c919d1b698221370b2ebe5f3
@@ -12,6 +12,11 @@ env:
12
12
  - SHIBA_TEST_ENV=test_postgres
13
13
  - SHIBA_TEST_ENV=test_mysql
14
14
 
15
+ before_install:
16
+ - gem update --system
17
+ - gem install bundler
18
+
19
+
15
20
  before_script:
16
21
  - cp .travis/my.cnf ~/.my.cnf
17
22
 
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- shiba (0.9.3)
4
+ shiba (0.9.4)
5
5
  activesupport
6
6
 
7
7
  GEM
@@ -33,6 +33,14 @@ module Shiba
33
33
 
34
34
  if Shiba.connection.mysql?
35
35
  @rows = Shiba::Explain::MysqlExplain.new.transform_json(@explain_json['query_block'])
36
+
37
+ # For simple queries, use original table name rather than the alias
38
+ if @select_fields.keys.size == 1
39
+ table = @select_fields.keys.first
40
+ if @rows.first['table'] != table
41
+ @rows.first['table'] = table
42
+ end
43
+ end
36
44
  else
37
45
  @rows = Shiba::Explain::PostgresExplain.new(@explain_json).transform
38
46
  end
@@ -13,6 +13,15 @@ module Shiba
13
13
  @tables.any?
14
14
  end
15
15
 
16
+ # case insenstive table match
17
+ def find_table(name)
18
+ table = @tables[name]
19
+ return table if table
20
+
21
+ _, table = @tables.detect { |k,_| k.casecmp(name).zero? }
22
+ return table
23
+ end
24
+
16
25
  Table = Struct.new(:name, :count, :indexes) do
17
26
  def encode_with(coder)
18
27
  if self.count.nil?
@@ -138,11 +147,11 @@ module Shiba
138
147
  attr_reader :tables
139
148
 
140
149
  def table_count(table)
141
- return @tables[table].count if @tables[table]
150
+ return find_table(table).count if find_table(table)
142
151
  end
143
152
 
144
153
  def fetch_index(table, name)
145
- tbl = @tables[table]
154
+ tbl = find_table(table)
146
155
  return nil unless tbl
147
156
 
148
157
  tbl.indexes[name]
@@ -158,7 +167,7 @@ module Shiba
158
167
  end
159
168
 
160
169
  def get_column_size(table_name, column)
161
- table = @tables[table_name]
170
+ table = find_table(table_name)
162
171
  return nil unless table
163
172
 
164
173
  table.column_sizes[column]
@@ -2,6 +2,7 @@ require 'shiba/parsers/shiba_string_scanner'
2
2
 
3
3
  module Shiba
4
4
  module Parsers
5
+ # Extracts table name and columns from queries formatted by 'show warnings'.
5
6
  class MysqlSelectFields
6
7
  def initialize(sql)
7
8
  @sql = sql
@@ -66,6 +67,18 @@ module Shiba
66
67
 
67
68
  sc.scan(/,/)
68
69
  end
70
+
71
+ # resolve table aliases
72
+ if sc.scan(/ `.*?`\.`(.*?)` `(.*?)`/)
73
+ table = sc[1]
74
+ table_alias = sc[2]
75
+
76
+ if tables[table_alias]
77
+ tables[table] = tables[table_alias]
78
+ tables.delete(table_alias)
79
+ end
80
+ end
81
+
69
82
  tables
70
83
  end
71
84
  end
@@ -1,3 +1,3 @@
1
1
  module Shiba
2
- VERSION = "0.9.3"
2
+ VERSION = "0.9.4"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shiba
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.3
4
+ version: 0.9.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Osheroff
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2019-04-09 00:00:00.000000000 Z
12
+ date: 2019-07-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -160,10 +160,9 @@ files:
160
160
  - shiba.gemspec
161
161
  - shiba.yml.example
162
162
  - web/babel.config.js
163
- - web/dist/example_data.json
164
163
  - web/dist/index.html
165
- - web/dist/js/app.91a7529a.js
166
- - web/dist/js/app.91a7529a.js.map
164
+ - web/dist/js/app.bca3a322.js
165
+ - web/dist/js/app.bca3a322.js.map
167
166
  - web/package-lock.json
168
167
  - web/package.json
169
168
  - web/public/index.html
@@ -198,7 +197,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
198
197
  version: '0'
199
198
  requirements: []
200
199
  rubyforge_project:
201
- rubygems_version: 2.7.6
200
+ rubygems_version: 2.6.14.1
202
201
  signing_key:
203
202
  specification_version: 4
204
203
  summary: Catch bad SQL queries before they cause problems in production