pg_closure_tree_rebuild 0.1.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -2
- data/lib/pg_closure_tree_rebuild.rb +5 -0
- data/lib/pg_closure_tree_rebuild/runner.rb +31 -0
- data/lib/pg_closure_tree_rebuild/version.rb +1 -1
- data/tasks/closure_tree.rake +4 -26
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ad6d8c266153123f106dcc223c3e5c588076f78b
|
4
|
+
data.tar.gz: a88791a4e3374895146aeaaded5945c2f9509bd0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5be88e56ff568468c3e493f5df5f352a8ee8d5bee66099465df2d01053a44826c275897513a988f9ed2338b5dfb21a75e7de1820aff34572bb9f0056d3ba6e4a
|
7
|
+
data.tar.gz: 6bb4e48b8f12a7cda3e263a042c45b20e3476777a718638c94557ad10ce1266df10114070857df712c05e3c86b32cc951ea74ffed41bbd86e277abfe36eb047a
|
data/.travis.yml
CHANGED
@@ -1,5 +1,10 @@
|
|
1
|
+
require 'ruby-progressbar'
|
2
|
+
require 'sequel'
|
3
|
+
require 'active_support/core_ext/string/inflections'
|
4
|
+
|
1
5
|
require 'pg_closure_tree_rebuild/version'
|
2
6
|
require 'pg_closure_tree_rebuild/builder'
|
7
|
+
require 'pg_closure_tree_rebuild/runner'
|
3
8
|
require 'pg_closure_tree_rebuild/railtie' if defined?(Rails)
|
4
9
|
|
5
10
|
module PgClosureTreeRebuild
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module PgClosureTreeRebuild
|
2
|
+
class Runner
|
3
|
+
def initialize(db, table, hierarchies = nil, parent_id = 'parent_id', id = 'id')
|
4
|
+
@db = db
|
5
|
+
|
6
|
+
hierarchies ||= "#{table.singularize}_hierarchies"
|
7
|
+
parent_id ||= 'parent_id'
|
8
|
+
id ||= 'id'
|
9
|
+
|
10
|
+
@scope = db[table.to_sym]
|
11
|
+
hierarchies = hierarchies.to_sym
|
12
|
+
|
13
|
+
@builder = PgClosureTreeRebuild::Builder.new(
|
14
|
+
@scope,
|
15
|
+
hierarchies.to_sym,
|
16
|
+
id: id.to_sym,
|
17
|
+
parent_id: parent_id.to_sym
|
18
|
+
)
|
19
|
+
end
|
20
|
+
|
21
|
+
def run
|
22
|
+
puts 'Calculating chains...'
|
23
|
+
bar = ProgressBar.create(total: @builder.chains.size)
|
24
|
+
|
25
|
+
puts "Records: #{@scope.count}"
|
26
|
+
|
27
|
+
puts 'Importing...'
|
28
|
+
@builder.rebuild(@db) { bar.increment }
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/tasks/closure_tree.rake
CHANGED
@@ -1,37 +1,15 @@
|
|
1
1
|
require 'pg_closure_tree_rebuild'
|
2
|
-
require 'ruby-progressbar'
|
3
|
-
require 'sequel'
|
4
|
-
require 'active_support/core_ext/string/inflections'
|
5
2
|
require 'benchmark'
|
6
3
|
|
7
4
|
namespace :closure_tree do
|
8
5
|
desc 'Rebuild hierarchy (TABLE, HIERARCHIES, DATABASE_URL, PARENT_ID, ID)'
|
9
6
|
task :rebuild do
|
10
7
|
puts Benchmark.measure {
|
11
|
-
|
8
|
+
db = Sequel.connect(ENV['DATABASE_URL'])
|
12
9
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
id = ENV['ID'] || 'id'
|
17
|
-
|
18
|
-
scope = DB[table.to_sym]
|
19
|
-
hierarchies = hierarchies.to_sym
|
20
|
-
|
21
|
-
builder = PgClosureTreeRebuild::Builder.new(
|
22
|
-
scope,
|
23
|
-
hierarchies.to_sym,
|
24
|
-
id: id.to_sym,
|
25
|
-
parent_id: parent_id.to_sym
|
26
|
-
)
|
27
|
-
|
28
|
-
puts 'Calculating chains...'
|
29
|
-
bar = ProgressBar.create(total: builder.chains.size)
|
30
|
-
|
31
|
-
puts "Records: #{scope.count}"
|
32
|
-
|
33
|
-
puts 'Importing...'
|
34
|
-
builder.rebuild(DB) { bar.increment }
|
10
|
+
PgClosureTreeRebuild::Runner.new(
|
11
|
+
db, ENV['TABLE'], ENV['HIERARCHIES'], ENV['PARENT_ID'], ENV['ID']
|
12
|
+
).run
|
35
13
|
}
|
36
14
|
end
|
37
15
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pg_closure_tree_rebuild
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Viktor Sokolov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-12-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sequel
|
@@ -185,6 +185,7 @@ files:
|
|
185
185
|
- lib/pg_closure_tree_rebuild.rb
|
186
186
|
- lib/pg_closure_tree_rebuild/builder.rb
|
187
187
|
- lib/pg_closure_tree_rebuild/railtie.rb
|
188
|
+
- lib/pg_closure_tree_rebuild/runner.rb
|
188
189
|
- lib/pg_closure_tree_rebuild/version.rb
|
189
190
|
- pg_closure_tree_rebuild.gemspec
|
190
191
|
- tasks/closure_tree.rake
|
@@ -208,7 +209,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
208
209
|
version: '0'
|
209
210
|
requirements: []
|
210
211
|
rubyforge_project:
|
211
|
-
rubygems_version: 2.
|
212
|
+
rubygems_version: 2.4.8
|
212
213
|
signing_key:
|
213
214
|
specification_version: 4
|
214
215
|
summary: 'Quick #rebuild! method implementation for closure_tree on PostgreSQL.'
|