lol_dba 1.6.1 → 1.6.2
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 +4 -4
- data/.gitignore +2 -1
- data/Gemfile +1 -3
- data/Gemfile.lock +77 -45
- data/bin/lol_dba +0 -0
- data/lib/lol_dba.rb +1 -1
- data/lib/lol_dba/version.rb +1 -1
- data/spec/associations_index_spec.rb +21 -21
- data/spec/common_function_spec.rb +18 -20
- data/spec/spec_helper.rb +2 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ed0a092881863ebd48f2561980814fa873e7140c
|
4
|
+
data.tar.gz: c5fba5c48943648577294aafc66d71dc8471e552
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c36497910a4c76bdbd0b30bc4fa1f70ff3feb4219ea57e0af467197d1e9138c4906614d236ff54ab4a5e8191ed168948579faf45349ac8fd4e215526b1dd37a6
|
7
|
+
data.tar.gz: fc5fb00645da95082db6f39c30fe67956824510885bb792a326ea03cfd1f3c68590e23a25631acc5d278f007a2952a55f2fa905c2b153f6b555341ba5bfddb76
|
data/.gitignore
CHANGED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,67 +1,99 @@
|
|
1
1
|
GEM
|
2
2
|
remote: https://rubygems.org/
|
3
3
|
specs:
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
4
|
+
actionmailer (4.1.6)
|
5
|
+
actionpack (= 4.1.6)
|
6
|
+
actionview (= 4.1.6)
|
7
|
+
mail (~> 2.5, >= 2.5.4)
|
8
|
+
actionpack (4.1.6)
|
9
|
+
actionview (= 4.1.6)
|
10
|
+
activesupport (= 4.1.6)
|
8
11
|
rack (~> 1.5.2)
|
9
12
|
rack-test (~> 0.6.2)
|
10
|
-
|
11
|
-
activesupport (= 4.
|
12
|
-
builder (~> 3.1
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
13
|
+
actionview (4.1.6)
|
14
|
+
activesupport (= 4.1.6)
|
15
|
+
builder (~> 3.1)
|
16
|
+
erubis (~> 2.7.0)
|
17
|
+
activemodel (4.1.6)
|
18
|
+
activesupport (= 4.1.6)
|
19
|
+
builder (~> 3.1)
|
20
|
+
activerecord (4.1.6)
|
21
|
+
activemodel (= 4.1.6)
|
22
|
+
activesupport (= 4.1.6)
|
23
|
+
arel (~> 5.0.0)
|
24
|
+
activesupport (4.1.6)
|
25
|
+
i18n (~> 0.6, >= 0.6.9)
|
26
|
+
json (~> 1.7, >= 1.7.7)
|
27
|
+
minitest (~> 5.1)
|
23
28
|
thread_safe (~> 0.1)
|
24
|
-
tzinfo (~>
|
25
|
-
arel (
|
26
|
-
|
27
|
-
|
28
|
-
diff-lcs (1.2.4)
|
29
|
+
tzinfo (~> 1.1)
|
30
|
+
arel (5.0.1.20140414130214)
|
31
|
+
builder (3.2.2)
|
32
|
+
diff-lcs (1.2.5)
|
29
33
|
erubis (2.7.0)
|
30
|
-
|
31
|
-
|
32
|
-
|
34
|
+
hike (1.2.3)
|
35
|
+
i18n (0.6.11)
|
36
|
+
json (1.8.1)
|
37
|
+
mail (2.6.1)
|
38
|
+
mime-types (>= 1.16, < 3)
|
39
|
+
mime-types (2.3)
|
40
|
+
minitest (5.4.1)
|
41
|
+
multi_json (1.10.1)
|
33
42
|
rack (1.5.2)
|
34
43
|
rack-test (0.6.2)
|
35
44
|
rack (>= 1.0)
|
36
|
-
|
37
|
-
|
38
|
-
|
45
|
+
rails (4.1.6)
|
46
|
+
actionmailer (= 4.1.6)
|
47
|
+
actionpack (= 4.1.6)
|
48
|
+
actionview (= 4.1.6)
|
49
|
+
activemodel (= 4.1.6)
|
50
|
+
activerecord (= 4.1.6)
|
51
|
+
activesupport (= 4.1.6)
|
52
|
+
bundler (>= 1.3.0, < 2.0)
|
53
|
+
railties (= 4.1.6)
|
54
|
+
sprockets-rails (~> 2.0)
|
55
|
+
railties (4.1.6)
|
56
|
+
actionpack (= 4.1.6)
|
57
|
+
activesupport (= 4.1.6)
|
39
58
|
rake (>= 0.8.7)
|
40
59
|
thor (>= 0.18.1, < 2.0)
|
41
|
-
rake (10.
|
42
|
-
rspec-core (
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
60
|
+
rake (10.3.2)
|
61
|
+
rspec-core (3.1.4)
|
62
|
+
rspec-support (~> 3.1.0)
|
63
|
+
rspec-expectations (3.1.1)
|
64
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
65
|
+
rspec-support (~> 3.1.0)
|
66
|
+
rspec-mocks (3.1.1)
|
67
|
+
rspec-support (~> 3.1.0)
|
68
|
+
rspec-rails (3.1.0)
|
47
69
|
actionpack (>= 3.0)
|
48
70
|
activesupport (>= 3.0)
|
49
71
|
railties (>= 3.0)
|
50
|
-
rspec-core (~>
|
51
|
-
rspec-expectations (~>
|
52
|
-
rspec-mocks (~>
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
72
|
+
rspec-core (~> 3.1.0)
|
73
|
+
rspec-expectations (~> 3.1.0)
|
74
|
+
rspec-mocks (~> 3.1.0)
|
75
|
+
rspec-support (~> 3.1.0)
|
76
|
+
rspec-support (3.1.0)
|
77
|
+
sprockets (2.12.2)
|
78
|
+
hike (~> 1.2)
|
79
|
+
multi_json (~> 1.0)
|
80
|
+
rack (~> 1.0)
|
81
|
+
tilt (~> 1.1, != 1.3.0)
|
82
|
+
sprockets-rails (2.1.4)
|
83
|
+
actionpack (>= 3.0)
|
84
|
+
activesupport (>= 3.0)
|
85
|
+
sprockets (~> 2.8)
|
86
|
+
sqlite3 (1.3.9)
|
87
|
+
thor (0.19.1)
|
88
|
+
thread_safe (0.3.4)
|
89
|
+
tilt (1.4.1)
|
90
|
+
tzinfo (1.2.2)
|
91
|
+
thread_safe (~> 0.1)
|
58
92
|
|
59
93
|
PLATFORMS
|
60
94
|
ruby
|
61
95
|
|
62
96
|
DEPENDENCIES
|
63
|
-
|
64
|
-
activerecord
|
65
|
-
railties
|
97
|
+
rails
|
66
98
|
rspec-rails
|
67
99
|
sqlite3
|
data/bin/lol_dba
CHANGED
File without changes
|
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
|
-
|
77
|
+
Rails.application.eager_load! unless ENV["RAILS_ENV"] == 'test'
|
78
78
|
|
79
79
|
model_classes = []
|
80
80
|
ObjectSpace.each_object(Module) do |obj|
|
data/lib/lol_dba/version.rb
CHANGED
@@ -7,64 +7,64 @@ describe "Collect indexes based on associations:" do
|
|
7
7
|
let(:warning_messages){ lol_dba[1] }
|
8
8
|
|
9
9
|
it "find relationship indexes" do
|
10
|
-
relationship_indexes.
|
10
|
+
expect(relationship_indexes).not_to be_empty
|
11
11
|
|
12
|
-
relationship_indexes.
|
13
|
-
relationship_indexes.
|
14
|
-
relationship_indexes.
|
15
|
-
relationship_indexes.
|
12
|
+
expect(relationship_indexes).to have_key("companies")
|
13
|
+
expect(relationship_indexes).to have_key("companies_freelancers")
|
14
|
+
expect(relationship_indexes).to have_key("addresses")
|
15
|
+
expect(relationship_indexes).to have_key("purchases")
|
16
16
|
end
|
17
17
|
|
18
18
|
it "find indexes for belongs_to" do
|
19
|
-
relationship_indexes["addresses"].
|
19
|
+
expect(relationship_indexes["addresses"]).to include("country_id")
|
20
20
|
end
|
21
21
|
|
22
22
|
it "find indexes for belongs_to with custom foreign key" do
|
23
|
-
relationship_indexes["companies"].
|
23
|
+
expect(relationship_indexes["companies"]).to include("owner_id")
|
24
24
|
end
|
25
25
|
|
26
26
|
it "find indexes for has_and_belongs_to_many" do
|
27
|
-
relationship_indexes["companies_freelancers"].
|
27
|
+
expect(relationship_indexes["companies_freelancers"]).to include(["freelancer_id", "company_id"])
|
28
28
|
end
|
29
29
|
|
30
30
|
it "find indexes for has_and_belongs_to_many with custom join_table, primary and foreign keys" do
|
31
|
-
relationship_indexes["purchases"].
|
31
|
+
expect(relationship_indexes["purchases"]).to include(["present_id", "buyer_id"])
|
32
32
|
end
|
33
33
|
|
34
34
|
it "do not add an already existing index" do
|
35
|
-
relationship_indexes["companies"].
|
35
|
+
expect(relationship_indexes["companies"]).not_to include("country_id")
|
36
36
|
end
|
37
37
|
|
38
38
|
it "find indexes for has_many :through" do
|
39
|
-
relationship_indexes["billable_weeks"].
|
39
|
+
expect(relationship_indexes["billable_weeks"]).to include(["remote_worker_id", "timesheet_id"])
|
40
40
|
end
|
41
41
|
|
42
42
|
it "find indexes for has_many :through with source and foreign key" do
|
43
|
-
relationship_indexes["complex_billable_week"].
|
43
|
+
expect(relationship_indexes["complex_billable_week"]).to include(["freelancer_id", "id_complex_timesheet"])
|
44
44
|
end
|
45
45
|
|
46
46
|
it "do not include wrong class" do
|
47
|
-
relationship_indexes["wrongs"].
|
48
|
-
relationship_indexes["addresses_wrongs"].
|
47
|
+
expect(relationship_indexes["wrongs"]).to be_nil
|
48
|
+
expect(relationship_indexes["addresses_wrongs"]).to be_nil
|
49
49
|
end
|
50
50
|
|
51
51
|
it "have warnings(non-existent table) on test data" do
|
52
|
-
warning_messages.
|
53
|
-
warning_messages.
|
54
|
-
warning_messages.
|
52
|
+
expect(warning_messages).not_to be_empty
|
53
|
+
expect(warning_messages).to match(/\'wrongs\'/)
|
54
|
+
expect(warning_messages).to match(/\'addresses_wrongs\'/)
|
55
55
|
end
|
56
56
|
|
57
57
|
it "find indexes for STI" do
|
58
|
-
relationship_indexes["users"].
|
58
|
+
expect(relationship_indexes["users"]).to include(["id", "type"])
|
59
59
|
end
|
60
60
|
|
61
61
|
it "find indexes for STI with custom inheritance column" do
|
62
|
-
relationship_indexes["freelancers"].
|
62
|
+
expect(relationship_indexes["freelancers"]).to include(["id", "worker_type"])
|
63
63
|
end
|
64
64
|
|
65
65
|
it "find indexes, than use custom class name option in association" do
|
66
|
-
relationship_indexes["employers_freelancers"].
|
67
|
-
relationship_indexes["companies_freelancers"].
|
66
|
+
expect(relationship_indexes["employers_freelancers"]).to be_nil
|
67
|
+
expect(relationship_indexes["companies_freelancers"]).to include(["freelancer_id", "company_id"])
|
68
68
|
end
|
69
69
|
|
70
70
|
end
|
@@ -7,15 +7,13 @@ describe "Function form_migration_content:" do
|
|
7
7
|
end
|
8
8
|
|
9
9
|
it "print migration skeleton with set name" do
|
10
|
-
#$stdout.should_receive(:puts).with(/TestMigration/i)
|
11
10
|
migration = LolDba.form_migration_content("TestMigration", @add)
|
12
|
-
migration.
|
11
|
+
expect(migration).to match(/class TestMigration/i)
|
13
12
|
end
|
14
13
|
|
15
14
|
it "print migration with add_keys params" do
|
16
|
-
# $stdout.should_receive(:puts).with(/add_index :report, :_id_test_plan/i)
|
17
15
|
migration = LolDba.form_migration_content("TestMigration", @add)
|
18
|
-
migration.
|
16
|
+
expect(migration).to match(/add_index :report, :_id_test_plan/i)
|
19
17
|
end
|
20
18
|
end
|
21
19
|
|
@@ -23,27 +21,27 @@ describe "Function form_data_for_migration:" do
|
|
23
21
|
|
24
22
|
it "return data for migrations for non-indexed single key in table" do
|
25
23
|
relationship_indexes = {:users => [:user_id]}
|
26
|
-
LolDba.
|
24
|
+
allow(LolDba).to receive(:key_exists?).with(:users, :user_id).and_return(false)
|
27
25
|
|
28
26
|
add_indexes = LolDba.form_data_for_migration(relationship_indexes)
|
29
27
|
|
30
|
-
add_indexes.first.
|
28
|
+
expect(add_indexes.first).to eq("add_index :users, :user_id")
|
31
29
|
end
|
32
30
|
|
33
31
|
it "return data for migrations for non-indexed composite key in table" do
|
34
32
|
relationship_indexes = {:friends => [[:user_id, :friend_id]]}
|
35
|
-
LolDba.
|
33
|
+
allow(LolDba).to receive(:key_exists?).with(:friends, [:user_id, :friend_id]).and_return(false)
|
36
34
|
|
37
35
|
add_indexes = LolDba.form_data_for_migration(relationship_indexes)
|
38
36
|
|
39
|
-
add_indexes.first.
|
37
|
+
expect(add_indexes.first).to eq("add_index :friends, [:user_id, :friend_id]")
|
40
38
|
end
|
41
39
|
|
42
40
|
it "ignore empty or nil keys for table" do
|
43
41
|
relationship_indexes = {:table => [""], :table2 => [nil]}
|
44
42
|
add_indexes = LolDba.form_data_for_migration(relationship_indexes)
|
45
43
|
|
46
|
-
add_indexes.
|
44
|
+
expect(add_indexes).to be_empty
|
47
45
|
end
|
48
46
|
|
49
47
|
end
|
@@ -51,19 +49,19 @@ end
|
|
51
49
|
describe "Function key_exists?:" do
|
52
50
|
|
53
51
|
it "return true if key is already indexed" do
|
54
|
-
LolDba.key_exists?("companies", "country_id").
|
52
|
+
expect(LolDba.key_exists?("companies", "country_id")).to be_truthy
|
55
53
|
end
|
56
54
|
|
57
55
|
it "return false if key is not indexed yet" do
|
58
|
-
LolDba.key_exists?("addresses", "country_id").
|
56
|
+
expect(LolDba.key_exists?("addresses", "country_id")).to be_falsey
|
59
57
|
end
|
60
58
|
|
61
59
|
it "return true if key is primary key(default)" do
|
62
|
-
LolDba.key_exists?("addresses", "id").
|
60
|
+
expect(LolDba.key_exists?("addresses", "id")).to be_truthy
|
63
61
|
end
|
64
62
|
|
65
63
|
it "return true if key is custom primary key" do
|
66
|
-
LolDba.key_exists?("gifts", "custom_primary_key").
|
64
|
+
expect(LolDba.key_exists?("gifts", "custom_primary_key")).to be_truthy
|
67
65
|
end
|
68
66
|
|
69
67
|
end
|
@@ -75,23 +73,23 @@ describe "Function puts_migration_content:" do
|
|
75
73
|
end
|
76
74
|
|
77
75
|
it "print migration code" do
|
78
|
-
$stdout.
|
79
|
-
$stdout.
|
80
|
-
$stdout.
|
76
|
+
expect($stdout).to receive(:puts).with("")
|
77
|
+
expect($stdout).to receive(:puts).with(/TIP/)
|
78
|
+
expect($stdout).to receive(:puts).with(/TestMigration/i)
|
81
79
|
LolDba.puts_migration_content("TestMigration", @relationship_indexes, "")
|
82
80
|
end
|
83
81
|
|
84
82
|
it "print warning messages if they exist" do
|
85
83
|
warning = "warning text here"
|
86
|
-
$stdout.
|
87
|
-
$stdout.
|
84
|
+
expect($stdout).to receive(:puts).at_least(:once).with(warning)
|
85
|
+
expect($stdout).to receive(:puts)
|
88
86
|
|
89
87
|
LolDba.puts_migration_content("TestMigration", {}, warning)
|
90
88
|
end
|
91
89
|
|
92
90
|
it "print nothing if no indexes and warning messages exist" do
|
93
|
-
$stdout.
|
94
|
-
$stdout.
|
91
|
+
expect($stdout).to receive(:puts).with("")
|
92
|
+
expect($stdout).to receive(:puts).with("Yey, no missing indexes found!")
|
95
93
|
LolDba.puts_migration_content("TestMigration",{}, "")
|
96
94
|
end
|
97
95
|
|
data/spec/spec_helper.rb
CHANGED
@@ -1,6 +1,4 @@
|
|
1
|
-
require '
|
2
|
-
require 'active_support'
|
3
|
-
require 'action_controller'
|
1
|
+
require 'rails/all'
|
4
2
|
require 'lol_dba'
|
5
3
|
require 'rspec/rails'
|
6
4
|
|
@@ -16,7 +14,7 @@ module Rails
|
|
16
14
|
"spec/fixtures/"
|
17
15
|
end
|
18
16
|
end
|
19
|
-
|
17
|
+
Dir.glob("#{Rails.root}/app/models/*.rb").sort.each { |file| require_dependency file }
|
20
18
|
load 'fixtures/schema.rb'
|
21
19
|
|
22
20
|
root_dir = File.dirname(__FILE__)
|
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.6.
|
4
|
+
version: 1.6.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Diego Plentz
|
@@ -12,7 +12,7 @@ authors:
|
|
12
12
|
autorequire:
|
13
13
|
bindir: bin
|
14
14
|
cert_chain: []
|
15
|
-
date: 2014-09-
|
15
|
+
date: 2014-09-20 00:00:00.000000000 Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
name: activerecord
|