partial_ks 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES.md +4 -0
- data/CONTRIBUTING.md +17 -2
- data/README.md +1 -1
- data/lib/partial_ks/filtered_table.rb +6 -4
- data/lib/partial_ks/version.rb +1 -1
- data/test/filtered_table_test.rb +6 -0
- data/test/runner_test.rb +4 -4
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 27cf67a4ac72c019e9ce39c13be6949746d319cb
|
4
|
+
data.tar.gz: c8aaa05cf43a2c2a3bbc0d5076147ee2593f1d35
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 41c5e26c8792bc97720b97aae22da1f4f0ca39014fc7e99b3eb20529557ffeb1dedd2015b164174acca8bf66a683ea0f2cd167b425bff7b04c237ab0c8f55873
|
7
|
+
data.tar.gz: 4cbdfbb74cfb845bba856ff2db9bfead21222f42cb61df535404cb3b9b959ad44f8f56880615e9cf7c41770030ca6d15bf221828428e36fffd4b9e59d035bf6d
|
data/CHANGES.md
CHANGED
data/CONTRIBUTING.md
CHANGED
@@ -1,10 +1,25 @@
|
|
1
|
-
|
1
|
+
This document should tell all you need to know for contributing to this project.
|
2
|
+
|
3
|
+
# Testing
|
4
|
+
|
5
|
+
Tested with activerecord 4.2.7.1, 4.2.8 and 5.0.1 (on Ruby 2.3.3)
|
2
6
|
|
3
7
|
|
4
8
|
To install and run tests :
|
5
9
|
|
6
10
|
```
|
7
11
|
rm Gemfile.lock
|
8
|
-
ACTIVERECORD_VERSION="
|
12
|
+
ACTIVERECORD_VERSION="~> 4.2.8" bundle
|
9
13
|
bundle exec rake
|
10
14
|
```
|
15
|
+
|
16
|
+
# Design
|
17
|
+
|
18
|
+
Partial KS is meant to run on *two* databases : the source DB and the target DB.
|
19
|
+
|
20
|
+
The building of the filter is done on the target DB.
|
21
|
+
- Hence, instructions for a table *cannot* be run until all data for its parent
|
22
|
+
table is fully downloaded onto the target DB.
|
23
|
+
|
24
|
+
Filters are run on the source DB.
|
25
|
+
- Note that a SQL statement from the target DB will behave differently on the source DB.
|
data/README.md
CHANGED
@@ -20,7 +20,7 @@ You can specify manual configurations if needed.
|
|
20
20
|
|
21
21
|
```
|
22
22
|
manual_configuration = [
|
23
|
-
[User, nil, User.where(:id => [1])], # specify a subset of users. as users have no parent, specify `nil`
|
23
|
+
[User, nil, -> { User.where(:id => [1]) }], # specify a subset of users. as users have no parent, specify `nil`
|
24
24
|
[BlogPost, User] # filter blog_posts by User
|
25
25
|
]
|
26
26
|
```
|
@@ -25,10 +25,12 @@ module PartialKs
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def filter_based_on_custom_filter_relation
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
28
|
+
relation = custom_filter_relation.respond_to?(:call) ? custom_filter_relation.call : custom_filter_relation
|
29
|
+
|
30
|
+
if relation.is_a?(ActiveRecord::Relation) || relation.respond_to?(:where_sql)
|
31
|
+
relation.where_sql.to_s.sub(where_regexp, "")
|
32
|
+
elsif relation.is_a?(String)
|
33
|
+
relation.sub(where_regexp, "")
|
32
34
|
end
|
33
35
|
end
|
34
36
|
|
data/lib/partial_ks/version.rb
CHANGED
data/test/filtered_table_test.rb
CHANGED
@@ -21,6 +21,12 @@ describe "kitchen sync filter" do
|
|
21
21
|
filtered_table.kitchen_sync_filter.must_equal({"only" => '"post_tags"."id" IN (1, 2)'})
|
22
22
|
end
|
23
23
|
|
24
|
+
it "uses the filter inside a lambda" do
|
25
|
+
filter = -> { PostTag.where(:id => [1, 2]) }
|
26
|
+
filtered_table = PartialKs::FilteredTable.new(table, nil, custom_filter_relation: filter)
|
27
|
+
filtered_table.kitchen_sync_filter.must_equal({"only" => '"post_tags"."id" IN (1, 2)'})
|
28
|
+
end
|
29
|
+
|
24
30
|
it "uses a SQL where fragment as a filter if provided" do
|
25
31
|
string_filter = "1=0"
|
26
32
|
filtered_table = PartialKs::FilteredTable.new(table, nil, custom_filter_relation: string_filter)
|
data/test/runner_test.rb
CHANGED
@@ -35,7 +35,7 @@ describe 'running based on output from generator' do
|
|
35
35
|
end
|
36
36
|
|
37
37
|
it "yields all table names" do
|
38
|
-
expected_table_names =
|
38
|
+
expected_table_names = [User, Tag, BlogPost].map(&:table_name)
|
39
39
|
actual_table_names = []
|
40
40
|
runner.run! do |tables_to_filter, table_names|
|
41
41
|
actual_table_names += table_names
|
@@ -45,7 +45,7 @@ describe 'running based on output from generator' do
|
|
45
45
|
end
|
46
46
|
|
47
47
|
it "yields all non-null filters" do
|
48
|
-
expected_filters =
|
48
|
+
expected_filters = [User, BlogPost].map(&:table_name)
|
49
49
|
actual_filters = {}
|
50
50
|
|
51
51
|
runner.run! do |tables_to_filter, table_names|
|
@@ -53,8 +53,8 @@ describe 'running based on output from generator' do
|
|
53
53
|
end
|
54
54
|
|
55
55
|
actual_filters.size.must_equal expected_filters.size
|
56
|
-
actual_filters.keys.must_equal expected_filters
|
57
|
-
expected_filters.each do |table_name
|
56
|
+
actual_filters.keys.must_equal expected_filters
|
57
|
+
expected_filters.each do |table_name|
|
58
58
|
actual_filters[table_name]["only"].must_be_kind_of String
|
59
59
|
end
|
60
60
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: partial_ks
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thong Kuah
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-03-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -52,8 +52,9 @@ dependencies:
|
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
-
description:
|
56
|
-
|
55
|
+
description: 'A library to use kitchen-sync to sync a subset of your database
|
56
|
+
|
57
|
+
'
|
57
58
|
email: kuahyeow@gmail.com
|
58
59
|
executables: []
|
59
60
|
extensions: []
|
@@ -104,7 +105,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
104
105
|
version: '0'
|
105
106
|
requirements: []
|
106
107
|
rubyforge_project:
|
107
|
-
rubygems_version: 2.
|
108
|
+
rubygems_version: 2.5.2
|
108
109
|
signing_key:
|
109
110
|
specification_version: 4
|
110
111
|
summary: Partial KS
|