lol_dba 1.4.3 → 1.5.0

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.
data/.travis.yml CHANGED
@@ -2,6 +2,7 @@ language: ruby
2
2
  rvm:
3
3
  - 1.9.2
4
4
  - 1.9.3
5
+ - 2.0.0
5
6
  gemfile:
6
7
  - Gemfile
7
8
  script: "bundle exec rake"
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source :rubygems
1
+ source 'https://rubygems.org'
2
2
 
3
3
  gem 'activerecord'
4
4
  gem 'actionpack'
data/Gemfile.lock CHANGED
@@ -1,73 +1,73 @@
1
1
  GEM
2
- remote: http://rubygems.org/
2
+ remote: https://rubygems.org/
3
3
  specs:
4
- actionpack (3.2.9)
5
- activemodel (= 3.2.9)
6
- activesupport (= 3.2.9)
4
+ actionpack (3.2.12)
5
+ activemodel (= 3.2.12)
6
+ activesupport (= 3.2.12)
7
7
  builder (~> 3.0.0)
8
8
  erubis (~> 2.7.0)
9
9
  journey (~> 1.0.4)
10
- rack (~> 1.4.0)
10
+ rack (~> 1.4.5)
11
11
  rack-cache (~> 1.2)
12
12
  rack-test (~> 0.6.1)
13
13
  sprockets (~> 2.2.1)
14
- activemodel (3.2.9)
15
- activesupport (= 3.2.9)
14
+ activemodel (3.2.12)
15
+ activesupport (= 3.2.12)
16
16
  builder (~> 3.0.0)
17
- activerecord (3.2.9)
18
- activemodel (= 3.2.9)
19
- activesupport (= 3.2.9)
17
+ activerecord (3.2.12)
18
+ activemodel (= 3.2.12)
19
+ activesupport (= 3.2.12)
20
20
  arel (~> 3.0.2)
21
21
  tzinfo (~> 0.3.29)
22
- activesupport (3.2.9)
22
+ activesupport (3.2.12)
23
23
  i18n (~> 0.6)
24
24
  multi_json (~> 1.0)
25
25
  arel (3.0.2)
26
26
  builder (3.0.4)
27
- diff-lcs (1.1.3)
27
+ diff-lcs (1.2.1)
28
28
  erubis (2.7.0)
29
29
  hike (1.2.1)
30
- i18n (0.6.1)
30
+ i18n (0.6.4)
31
31
  journey (1.0.4)
32
- json (1.7.5)
33
- multi_json (1.5.0)
34
- rack (1.4.1)
32
+ json (1.7.7)
33
+ multi_json (1.6.1)
34
+ rack (1.4.5)
35
35
  rack-cache (1.2)
36
36
  rack (>= 0.4)
37
- rack-ssl (1.3.2)
37
+ rack-ssl (1.3.3)
38
38
  rack
39
39
  rack-test (0.6.2)
40
40
  rack (>= 1.0)
41
- railties (3.2.9)
42
- actionpack (= 3.2.9)
43
- activesupport (= 3.2.9)
41
+ railties (3.2.12)
42
+ actionpack (= 3.2.12)
43
+ activesupport (= 3.2.12)
44
44
  rack-ssl (~> 1.3.2)
45
45
  rake (>= 0.8.7)
46
46
  rdoc (~> 3.4)
47
47
  thor (>= 0.14.6, < 2.0)
48
48
  rake (10.0.3)
49
- rdoc (3.12)
49
+ rdoc (3.12.2)
50
50
  json (~> 1.4)
51
- rspec-core (2.12.2)
52
- rspec-expectations (2.12.1)
53
- diff-lcs (~> 1.1.3)
54
- rspec-mocks (2.12.0)
55
- rspec-rails (2.12.0)
51
+ rspec-core (2.13.1)
52
+ rspec-expectations (2.13.0)
53
+ diff-lcs (>= 1.1.3, < 2.0)
54
+ rspec-mocks (2.13.0)
55
+ rspec-rails (2.13.0)
56
56
  actionpack (>= 3.0)
57
57
  activesupport (>= 3.0)
58
58
  railties (>= 3.0)
59
- rspec-core (~> 2.12.0)
60
- rspec-expectations (~> 2.12.0)
61
- rspec-mocks (~> 2.12.0)
59
+ rspec-core (~> 2.13.0)
60
+ rspec-expectations (~> 2.13.0)
61
+ rspec-mocks (~> 2.13.0)
62
62
  sprockets (2.2.2)
63
63
  hike (~> 1.2)
64
64
  multi_json (~> 1.0)
65
65
  rack (~> 1.0)
66
66
  tilt (~> 1.1, != 1.3.0)
67
- sqlite3 (1.3.6)
68
- thor (0.16.0)
69
- tilt (1.3.3)
70
- tzinfo (0.3.35)
67
+ sqlite3 (1.3.7)
68
+ thor (0.17.0)
69
+ tilt (1.3.5)
70
+ tzinfo (0.3.37)
71
71
 
72
72
  PLATFORMS
73
73
  ruby
data/bin/lol_dba ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ if File.exists?(File.join(File.expand_path('../../', __FILE__), '.git'))
4
+ $:.unshift(File.expand_path('../../lib', __FILE__))
5
+ end
6
+
7
+ require 'lol_dba'
8
+ require 'lol_dba/cli'
9
+
10
+ LolDba::CLI.start
data/lib/lol_dba.rb CHANGED
@@ -74,7 +74,7 @@ EOM
74
74
  end
75
75
 
76
76
  def self.check_for_indexes(migration_format = false)
77
- Dir.glob(Rails.root + "app/models/**/*.rb").each {|file| require file }
77
+ Dir.glob(Rails.root + "app/models/**/*.rb").sort.each {|file| require file }
78
78
 
79
79
  model_classes = []
80
80
  ObjectSpace.each_object(Module) do |obj|
@@ -0,0 +1,53 @@
1
+ require 'optparse'
2
+
3
+ module LolDba
4
+ class CLI
5
+
6
+ class << self
7
+ def start
8
+ options = {:format => 'migration'}
9
+ OptionParser.new do |opts|
10
+ opts.on("-f", '--format=[FORMAT]', 'Specify the format to be used (migration or sql), defaults to migration.') { |v| options[:format] = v }
11
+ opts.on('-d', '--debug', 'Show stack traces when an error occurs.') { |v| options[:debug] = v }
12
+ end.parse!
13
+ new(Dir.pwd, options).start
14
+ end
15
+ end
16
+
17
+ def initialize(path, options)
18
+ @path, @options = path, options
19
+ end
20
+
21
+ def start
22
+ load_application
23
+ validate_format!
24
+ send("generate_#{@options[:format]}")
25
+ rescue Exception => e
26
+ $stderr.puts "Failed: #{e.class}: #{e.message}"
27
+ $stderr.puts e.backtrace.map { |t| " from #{t}" } if @options[:debug]
28
+ end
29
+
30
+ protected
31
+
32
+ def validate_format!
33
+ unless self.respond_to?("generate_#{@options[:format]}")
34
+ $stderr.puts "Unknown format: #{@options[:format]}"
35
+ exit 1
36
+ end
37
+ end
38
+
39
+ # Tks to https://github.com/voormedia/rails-erd/blob/master/lib/rails_erd/cli.rb
40
+ def load_application
41
+ $stderr.puts "Loading application in '#{File.basename(@path)}'..."
42
+ require "#{@path}/config/environment"
43
+ end
44
+
45
+ def generate_sql
46
+ LolDba::SqlGenerator.generate
47
+ end
48
+
49
+ def generate_migration
50
+ LolDba.simple_migration
51
+ end
52
+ end
53
+ end
@@ -1,3 +1,3 @@
1
1
  module LolDba
2
- VERSION = "1.4.3" unless defined? LolDba::VERSION
2
+ VERSION = "1.5.0" unless defined? LolDba::VERSION
3
3
  end
data/lol_dba.gemspec CHANGED
@@ -13,10 +13,11 @@ Gem::Specification.new do |s|
13
13
  s.description = "lol_dba is a small package of rake tasks that scan your application models and displays a list of columns that probably should be indexed. Also, it can generate .sql migration scripts."
14
14
 
15
15
  s.files = `git ls-files`.split("\n")
16
+ s.executables = s.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
16
17
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
18
  s.require_paths = ["lib", "lib/lol_dba"]
18
19
 
19
20
  s.add_dependency 'activerecord', '>= 3.0'
20
21
  s.add_dependency 'actionpack', '>= 3.0'
21
22
  s.add_dependency 'railties', '>= 3.0'
22
- end
23
+ end
data/spec/spec_helper.rb CHANGED
@@ -13,7 +13,7 @@ ActiveRecord::Base.establish_connection(
13
13
 
14
14
  class Rails
15
15
  def self.root
16
- "spec/fixtures"
16
+ "spec/fixtures/"
17
17
  end
18
18
  end
19
19
 
@@ -21,8 +21,5 @@ load 'fixtures/schema.rb'
21
21
 
22
22
  root_dir = File.dirname(__FILE__)
23
23
 
24
- # Load models
25
- Dir["#{root_dir}/fixtures/app/models/**/*.rb"].each { |f| require f}
26
-
27
- # load controllers
28
- Dir["#{root_dir}/fixtures/app/controllers/**/*.rb"].each { |f| require f}
24
+ #add current dir to the load path
25
+ $:.unshift('.')
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lol_dba
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.3
4
+ version: 1.5.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ authors:
13
13
  autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
- date: 2013-01-31 00:00:00.000000000 Z
16
+ date: 2013-03-24 00:00:00.000000000 Z
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
19
19
  name: activerecord
@@ -71,7 +71,8 @@ email:
71
71
  - elad@eizesus.com
72
72
  - ''
73
73
  - vsharshov@gmail.com
74
- executables: []
74
+ executables:
75
+ - lol_dba
75
76
  extensions: []
76
77
  extra_rdoc_files: []
77
78
  files:
@@ -81,7 +82,9 @@ files:
81
82
  - Gemfile.lock
82
83
  - README.md
83
84
  - Rakefile
85
+ - bin/lol_dba
84
86
  - lib/lol_dba.rb
87
+ - lib/lol_dba/cli.rb
85
88
  - lib/lol_dba/migration.rb
86
89
  - lib/lol_dba/railtie.rb
87
90
  - lib/lol_dba/sql_generator.rb
@@ -128,7 +131,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
128
131
  version: '0'
129
132
  requirements: []
130
133
  rubyforge_project:
131
- rubygems_version: 1.8.24
134
+ rubygems_version: 1.8.25
132
135
  signing_key:
133
136
  specification_version: 3
134
137
  summary: A small package of rake tasks to track down missing database indexes and