neo4apis-activerecord 0.8.0 → 0.9.0

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: b53fa80a0d3d755b2a75ef5eae630959abcbe30d
4
- data.tar.gz: 23bb41f32bcb6a0dcaeaf0175d5346c232fb1f09
3
+ metadata.gz: a3ab07342eda78cdb202597bf1fcbe5a924ecb1a
4
+ data.tar.gz: 1cdd5de52c0fe390cadd3683b1ad874c33009de8
5
5
  SHA512:
6
- metadata.gz: 6fb8cf560adb2bb673391278770368ff33b6485b28d12a8c7ee55b6cd98d517de9bbf44caf50ee1408bc0360cf8eb605fbda938d100adac1595f96677fd73df2
7
- data.tar.gz: ad7443131b73bf5cbfc47a727cd0faa34da0d2129a248fa21eb8e067e9ee7ac239c257dc5572ec1f21e0a0db16f0eaa0109e76646c1c4a37204245625a034582
6
+ metadata.gz: d4aca961167f3389348d9c9d9aacd323e1023efe5c8decbe2699bfcaf392f7b6afbb93175ecacddd0c9c0ec104408b5096f2f7690c7362088ee168a849b2e7ea
7
+ data.tar.gz: b32d89846180162ab0b5dcfc43d8fc1e0224c8b55f958e800acfc4f7ef8776533f6f206953273e8d9afab5f9f9fce6e66f876fd5a36b60efab485c9295cfc922
@@ -1,29 +1,45 @@
1
1
  require 'neo4apis'
2
2
  require 'ostruct'
3
+ require 'composite_primary_keys'
3
4
 
4
5
  module Neo4Apis
5
6
  class ActiveRecord < Base
6
7
  batch_size 1000
7
8
 
8
9
  def self.model_importer(model_class)
9
- return if model_class.primary_key.nil?
10
- uuid model_class.name.to_sym, model_class.primary_key
10
+ if model_class.primary_key.is_a?(Array)
11
+ relationship_name = model_class.table_name
12
+ associations = model_class.reflect_on_all_associations
11
13
 
12
- importer model_class.name.to_sym do |object|
13
- node = add_model_node model_class, object
14
+ importer model_class.name.to_sym do |object|
15
+ from_node = object.send(associations[0].name)
16
+ from_node = add_model_node from_node.class, from_node
14
17
 
15
- model_class.reflect_on_all_associations.each do |association_reflection|
16
- case association_reflection.macro
17
- when :belongs_to, :has_one
18
- if options[:"import_#{association_reflection.macro}"]
19
- referenced_object = object.send(association_reflection.name)
20
- add_model_relationship association_reflection.name, node, referenced_object if referenced_object
21
- end
22
- when :has_many, :has_and_belongs_to_many
23
- if options[:"import_#{association_reflection.macro}"]
24
- object.send(association_reflection.name).each do |referenced_object|
18
+ to_node = object.send(associations[1].name)
19
+
20
+ puts 'add_model_relationship...'
21
+ add_model_relationship relationship_name, from_node, to_node
22
+ end
23
+ else
24
+ return if model_class.primary_key.nil?
25
+ uuid model_class.name.to_sym, model_class.primary_key
26
+
27
+ importer model_class.name.to_sym do |object|
28
+ node = add_model_node model_class, object
29
+
30
+ model_class.reflect_on_all_associations.each do |association_reflection|
31
+ case association_reflection.macro
32
+ when :belongs_to, :has_one
33
+ if options[:"import_#{association_reflection.macro}"]
34
+ referenced_object = object.send(association_reflection.name)
25
35
  add_model_relationship association_reflection.name, node, referenced_object if referenced_object
26
36
  end
37
+ when :has_many, :has_and_belongs_to_many
38
+ if options[:"import_#{association_reflection.macro}"]
39
+ object.send(association_reflection.name).each do |referenced_object|
40
+ add_model_relationship association_reflection.name, node, referenced_object if referenced_object
41
+ end
42
+ end
27
43
  end
28
44
  end
29
45
  end
@@ -34,7 +50,8 @@ module Neo4Apis
34
50
  referenced_class = referenced_object.class
35
51
  referenced_node = add_model_node referenced_class, referenced_object
36
52
 
37
- add_relationship relationship_name, node, referenced_node
53
+ require 'pry'
54
+ add_relationship relationship_name, node, referenced_node rescue binding.pry
38
55
  end
39
56
 
40
57
  def add_model_node(model_class, object)
@@ -68,7 +68,7 @@ module Neo4Apis
68
68
  puts 'Importing tables: ' + model_classes.map(&:table_name).join(', ')
69
69
 
70
70
  model_classes.each do |model_class|
71
- ::Neo4Apis::ActiveRecord.model_importer(model_class)
71
+ NEO4APIS_CLIENT_CLASS.model_importer(model_class)
72
72
  end
73
73
 
74
74
  neo4apis_client.batch do
@@ -53,8 +53,13 @@ module Neo4Apis
53
53
  end
54
54
 
55
55
  def apply_identified_primary_key!(model_class)
56
- identity = ::ActiveRecord::Base.connection.primary_key(model_class.table_name)
56
+ identity = if model_class.columns.map(&:type) == [:integer, :integer]
57
+ model_class.columns.map(&:name)
58
+ else
59
+ ::ActiveRecord::Base.connection.primary_key(model_class.table_name)
60
+ end
57
61
  identity ||= identify_primary_key(model_class.column_names, model_class.name)
62
+
58
63
  model_class.primary_key = identity if identity
59
64
  end
60
65
  end
@@ -22,8 +22,6 @@ module Neo4Apis
22
22
  case standardize(column)
23
23
  when 'id', 'uuid', /#{standardize(class_name.singularize)}id/, /#{standardize(class_name.pluralize)}id/
24
24
  true
25
- when
26
- true
27
25
  end
28
26
  end.tap do |found_key| # rubocop:disable Style/MultilineBlockChain
29
27
  fail UnfoundPrimaryKeyError, "Could not find a primary key for #{class_name}." if found_key.nil?
@@ -3,7 +3,7 @@ $LOAD_PATH.unshift lib unless $LOAD_PATH.include?(lib)
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = 'neo4apis-activerecord'
6
- s.version = '0.8.0'
6
+ s.version = '0.9.0'
7
7
  s.required_ruby_version = '>= 1.9.1'
8
8
 
9
9
  s.authors = 'Brian Underwood'
@@ -20,4 +20,5 @@ A ruby gem using neo4apis to make importing SQL data to neo4j easy
20
20
 
21
21
  s.add_dependency('neo4apis', '>= 0.8.1')
22
22
  s.add_dependency('activerecord', '~> 4.0')
23
+ s.add_dependency('composite_primary_keys', '~> 8.0')
23
24
  end
metadata CHANGED
@@ -1,43 +1,57 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: neo4apis-activerecord
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Underwood
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-10 00:00:00.000000000 Z
11
+ date: 2015-08-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: neo4apis
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: 0.8.1
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: 0.8.1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: activerecord
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
33
  version: '4.0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '4.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: composite_primary_keys
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '8.0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '8.0'
41
55
  description: |
42
56
  A ruby gem using neo4apis to make importing SQL data to neo4j easy
43
57
  email: public@brian-underwood.codes
@@ -63,17 +77,17 @@ require_paths:
63
77
  - lib
64
78
  required_ruby_version: !ruby/object:Gem::Requirement
65
79
  requirements:
66
- - - '>='
80
+ - - ">="
67
81
  - !ruby/object:Gem::Version
68
82
  version: 1.9.1
69
83
  required_rubygems_version: !ruby/object:Gem::Requirement
70
84
  requirements:
71
- - - '>='
85
+ - - ">="
72
86
  - !ruby/object:Gem::Version
73
87
  version: '0'
74
88
  requirements: []
75
89
  rubyforge_project:
76
- rubygems_version: 2.4.6
90
+ rubygems_version: 2.4.5
77
91
  signing_key:
78
92
  specification_version: 4
79
93
  summary: An ruby gem to import SQL data to neo4j using activerecord