pgdexter 0.1.2 → 0.1.3

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
  SHA1:
3
- metadata.gz: b472c8289c8c878c0ea790a3ec5fdf43e22bfaa1
4
- data.tar.gz: 55f96eb8bd0a8739c79fb7c749a8aee68b2a119f
3
+ metadata.gz: 9f136be602609b6abb8f11ef02fa7cf18a8db33a
4
+ data.tar.gz: c58324b44d32b867df2a5a127a70b4d713e2dfa2
5
5
  SHA512:
6
- metadata.gz: 873d3d0f9471f90c9b90721274623c6c3dcfbcfe88989143a6b66a5ce1345a2187bab75ef4f32f52efd9f34a1e1806524696854348e592d6eb31bec25ca193c8
7
- data.tar.gz: a545b2b1a9d2f6650ec04c1769b243863c412fbff3b1e0575ab4cc6c98648119e487a2bc75f0afeeb704895184580ada13169a05edb3e00bc0caca37759183bc
6
+ metadata.gz: 8f39e8a9794a937fe79a637f46e76ee71eba53e9bf3b60a734ad6af270a9236216d5182440586bde0762fd05d48be11c02bb3e620039ec02e2acce1633b81d36
7
+ data.tar.gz: b870ca6f00a6bc2f6d76c49d6805d0910d4053457ca5c11ccb666de863406fcd07acf37fdf7f23fb4d89f0df6795724fe74fca601738aa47f6832edbafa03a86
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## 0.1.3
2
+
3
+ - Fixed error with non-lowercase columns
4
+ - Fixed error with `json` columns
5
+
1
6
  ## 0.1.2
2
7
 
3
8
  - Added `--exclude` option
data/README.md CHANGED
@@ -40,7 +40,7 @@ tail -F -n +1 <log-file> | dexter <database-url>
40
40
 
41
41
  This finds slow queries and generates output like:
42
42
 
43
- ```log
43
+ ```
44
44
  2017-06-25T17:52:19+00:00 Started
45
45
  2017-06-25T17:52:22+00:00 Processing 189 new query fingerprints
46
46
  2017-06-25T17:52:22+00:00 Index found: genres_movies (genre_id)
@@ -54,9 +54,9 @@ This finds slow queries and generates output like:
54
54
 
55
55
  To be safe, Dexter will not create indexes unless you pass the `--create` flag. In this case, you’ll see:
56
56
 
57
- ```log
57
+ ```
58
58
  2017-06-25T17:52:22+00:00 Index found: ratings (user_id)
59
- 2017-06-25T17:52:22+00:00 Creating index: CREATE INDEX CONCURRENTLY ON ratings (user_id)
59
+ 2017-06-25T17:52:22+00:00 Creating index: CREATE INDEX CONCURRENTLY ON "ratings" ("user_id")
60
60
  2017-06-25T17:52:37+00:00 Index created: 15243 ms
61
61
  ```
62
62
 
@@ -86,3 +86,18 @@ Everyone is encouraged to help improve this project. Here are a few ways you can
86
86
  - Fix bugs and [submit pull requests](https://github.com/ankane/dexter/pulls)
87
87
  - Write, clarify, or fix documentation
88
88
  - Suggest or add new features
89
+
90
+ To get started, run:
91
+
92
+ ```sh
93
+ git clone https://github.com/ankane/dexter.git
94
+ cd dexter
95
+ bundle
96
+ rake install
97
+ ```
98
+
99
+ To run tests, use:
100
+
101
+ ```sh
102
+ rake test
103
+ ```
data/Rakefile CHANGED
@@ -5,6 +5,7 @@ Rake::TestTask.new(:test) do |t|
5
5
  t.libs << "test"
6
6
  t.libs << "lib"
7
7
  t.test_files = FileList["test/**/*_test.rb"]
8
+ t.warning = false
8
9
  end
9
10
 
10
11
  task default: :test
data/exe/dexter CHANGED
File without changes
@@ -106,7 +106,9 @@ module Dexter
106
106
  candidates = {}
107
107
  columns(tables).each do |col|
108
108
  unless index_set.include?([col[:table], [col[:column]]])
109
- candidates[col] = select_all("SELECT * FROM hypopg_create_index('CREATE INDEX ON #{col[:table]} (#{[col[:column]].join(", ")})');").first["indexname"]
109
+ unless ["json", "jsonb"].include?(col[:type])
110
+ candidates[col] = select_all("SELECT * FROM hypopg_create_index('CREATE INDEX ON #{quote_ident(col[:table])} (#{[col[:column]].map { |c| quote_ident(c) }.join(", ")})')").first["indexname"]
111
+ end
110
112
  end
111
113
  end
112
114
  candidates
@@ -190,7 +192,7 @@ module Dexter
190
192
  # 3. create indexes that still don't exist
191
193
  # 4. release lock
192
194
  new_indexes.each do |index|
193
- statement = "CREATE INDEX CONCURRENTLY ON #{index[:table]} (#{index[:columns].join(", ")})"
195
+ statement = "CREATE INDEX CONCURRENTLY ON #{quote_ident(index[:table])} (#{index[:columns].map { |c| quote_ident(c) }.join(", ")})"
194
196
  log "Creating index: #{statement}"
195
197
  started_at = Time.now
196
198
  select_all(statement)
@@ -198,7 +200,7 @@ module Dexter
198
200
  end
199
201
  end
200
202
  else
201
- log "No indexes found"
203
+ log "No new indexes found"
202
204
  end
203
205
 
204
206
  new_indexes
@@ -222,7 +224,7 @@ module Dexter
222
224
  end
223
225
 
224
226
  def select_all(query)
225
- # use exec_params instead of exec for securiy
227
+ # use exec_params instead of exec for security
226
228
  #
227
229
  # Unlike PQexec, PQexecParams allows at most one SQL command in the given string.
228
230
  # (There can be semicolons in it, but not more than one nonempty command.)
@@ -260,7 +262,8 @@ module Dexter
260
262
  columns = select_all <<-SQL
261
263
  SELECT
262
264
  table_name,
263
- column_name
265
+ column_name,
266
+ data_type
264
267
  FROM
265
268
  information_schema.columns
266
269
  WHERE
@@ -268,7 +271,7 @@ module Dexter
268
271
  table_name IN (#{tables.map { |t| quote(t) }.join(", ")})
269
272
  SQL
270
273
 
271
- columns.map { |v| {table: v["table_name"], column: v["column_name"]} }
274
+ columns.map { |v| {table: v["table_name"], column: v["column_name"], type: v["data_type"]} }
272
275
  end
273
276
 
274
277
  def indexes(tables)
@@ -1,3 +1,3 @@
1
1
  module Dexter
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
data/pgdexter.gemspec CHANGED
@@ -26,4 +26,5 @@ Gem::Specification.new do |spec|
26
26
 
27
27
  spec.add_development_dependency "bundler"
28
28
  spec.add_development_dependency "rake"
29
+ spec.add_development_dependency "minitest"
29
30
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pgdexter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kane
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-06-27 00:00:00.000000000 Z
11
+ date: 2017-07-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: slop
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: minitest
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
83
97
  description:
84
98
  email:
85
99
  - andrew@chartkick.com