parse-db-import 0.0.1 → 0.0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 972c606465d4c1c9802f64c070717ba41b967e89
4
- data.tar.gz: 132635339ee69e412961412e2ec37ff460acc2eb
3
+ metadata.gz: aaaf31d415a930da89fc55c2170dc7436d8309cb
4
+ data.tar.gz: 32ff65c3c35afd7727b886c971c54e65a1f30d01
5
5
  SHA512:
6
- metadata.gz: ffaf78da0be19cebf9e124162977a05972a1674a7b3d67e70c43e9f87a5f7afe226744234b8c0475a6b94e9f13f68831fb759f0268ab445de859c8c216c8496d
7
- data.tar.gz: 76f66fcf5eb274fd5b33a00af87d88e0bf7b47b42b11ee0c90e92b8a237c05d37883046096bc145e19e4ddb011ab637123a46a2638afdf28ce1ad528891fc422
6
+ metadata.gz: b0214153b130dfe655295ccd724817d682ffd1913b917ac8e564bc885d6dd1c5195a8a5d09a008c764d0e95d53f4e2cfd1b0e6ae33035fd3ddc1e3345b3b768c
7
+ data.tar.gz: 2cd0516ed7c721befc06b24a7c1550bbde8a2e8381b1aabf7ae0b661050dbaa5362b36a23238b0db455de736540506f1c63c13aa2b59eb7a1823a0fe7ac0bac4
data/.gitignore CHANGED
@@ -20,3 +20,4 @@ tmp
20
20
  *.o
21
21
  *.a
22
22
  mkmf.log
23
+ tags
@@ -121,7 +121,7 @@ body{font-size:16px;}
121
121
  h2, h3 { page-break-after: avoid; }
122
122
  }
123
123
  </style><title>README</title></head><body><h1 id="parse-db-import">Parse-Db-Import</h1>
124
- <p>This solution is if you need to move away from Parse and build your own backend. This tool allows you to quickly import data exported from Parse into a database supported by active record. Currently it expects the records to be pre-flattened by <a href="#parse-migrator">parse-migrator</a></p>
124
+ <p>This solution is if you need to move away from Parse and build your own backend. This tool allows you to quickly import data exported from Parse into a database supported by active record. Currently it expects the records to be pre-flattened by <a href="https://github.com/JohnMorales/parse-migrator">parse-migrator</a></p>
125
125
  <p>See also</p>
126
126
  <ul>
127
127
  <li><a href="https://github.com/JohnMorales/parse-migrator">parse-migrator</a></li>
@@ -132,6 +132,9 @@ body{font-size:16px;}
132
132
  </code></pre>
133
133
 
134
134
  <h2 id="usage">Usage</h2>
135
+ <p>It's assumed that the database will exist so create the database if that's not the case </p>
136
+ <p><code>createdb sampledb</code></p>
137
+ <p>then </p>
135
138
  <pre><code class="sh"> $ bundle exec parse-db-import --path [path] --dbname [database]
136
139
  </code></pre>
137
140
 
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Parse-Db-Import
1
+ # parse-db-import
2
2
 
3
3
  This solution is if you need to move away from Parse and build your own backend. This tool allows you to quickly import data exported from Parse into a database supported by active record. Currently it expects the records to be pre-flattened by [parse-migrator](https://github.com/JohnMorales/parse-migrator)
4
4
 
@@ -16,6 +16,12 @@ See also
16
16
 
17
17
  ## Usage
18
18
 
19
+ It's assumed that the database will exist so create the database if that's not the case
20
+
21
+ `createdb sampledb`
22
+
23
+ then
24
+
19
25
  ```sh
20
26
  $ bundle exec parse-db-import --path [path] --dbname [database]
21
27
  ```
@@ -29,6 +35,7 @@ See also
29
35
  --host [host] #(optional, will use 'localhost')
30
36
  ```
31
37
 
38
+
32
39
  ## Contributing
33
40
 
34
41
  1. Fork it ( https://github.com/[my-github-username]/parse-db-import/fork )
@@ -1,4 +1,5 @@
1
1
  require 'active_record'
2
+ require "parse/db/import/utils"
2
3
 
3
4
  module Parse
4
5
  module Db
@@ -48,6 +49,19 @@ module Parse
48
49
  missing_columns
49
50
  end
50
51
 
52
+ def get_column_type(val, column)
53
+ return :timestamp if is_date_by_naming_convention(column)
54
+ case val
55
+ when String
56
+ val.length
57
+ when TrueClass, FalseClass
58
+ :boolean
59
+ when Float
60
+ :float
61
+ when Fixnum
62
+ :integer
63
+ end
64
+ end
51
65
 
52
66
  def create_missing_columns(klass, missing_columns)
53
67
  return if missing_columns.length == 0
@@ -55,7 +69,13 @@ module Parse
55
69
  #Create any columns that are missing.
56
70
  dbconnection = klass.connection
57
71
  dbconnection.change_table(klass.table_name) do |t|
58
- missing_columns.each { |k,v| t.column k, :string, { limit: v } }
72
+ missing_columns.each do |k,v|
73
+ if v.is_a? Fixnum
74
+ t.column k, :string, { limit: v }
75
+ else
76
+ t.column k, v
77
+ end
78
+ end
59
79
  end
60
80
  klass.reset_column_information
61
81
  klass.inheritance_column = "ar_type"
@@ -1,4 +1,6 @@
1
1
  require "parse/db/import/utils"
2
+ require "parse/db/import/activerecord_helpers"
3
+
2
4
  module Parse
3
5
  module Db
4
6
  class Import
@@ -10,10 +12,13 @@ module Parse
10
12
  process_parse_file(file) do |record|
11
13
  columns = get_missing_columns(klass, record.keys)
12
14
  unless columns.empty?
13
- columns.each { |k| missing_columns[k] = 0}
15
+ columns.each do |k|
16
+ missing_columns[k] = get_column_type(record[k], k)
17
+ end
14
18
  end
15
19
  missing_columns.each do |k, v|
16
- len = record[k].to_s.length
20
+ next unless v.is_a? Fixnum
21
+ len = record[k].to_s.length
17
22
  missing_columns[k] = len if v < len
18
23
  end
19
24
  end
@@ -1,9 +1,20 @@
1
+ require 'date'
2
+
1
3
  module Parse
2
4
  module Db
3
5
  class Import
4
6
 
5
- def map_arrays_to_strings(record)
7
+ DATE_CONVENTIONS = [ /At$/, /date$/, /^last/ ]
8
+
9
+ def map_data_types(record)
10
+ #Convert arrays to strings, since we're not supporting them yet.
6
11
  record.each { |k, v| record[k] = v.join(', ') if v.is_a? Array }
12
+ #Convert epoch to datetime
13
+ record.each { |k, v| record[k] = DateTime.strptime(v.to_s, "%Q") if is_date_by_naming_convention(k) }
14
+ end
15
+
16
+ def is_date_by_naming_convention column_name
17
+ DATE_CONVENTIONS.any? { |regx| column_name =~ regx }
7
18
  end
8
19
 
9
20
  def klass_from_file(file)
@@ -14,7 +25,7 @@ module Parse
14
25
  def process_parse_file(file, &block)
15
26
  IO.foreach(file) do |record|
16
27
  record = JSON.parse(record)
17
- record = map_arrays_to_strings(record)
28
+ record = map_data_types(record)
18
29
  next if record["delete"]
19
30
  yield(record)
20
31
  end
@@ -1,7 +1,7 @@
1
1
  module Parse
2
2
  module Db
3
3
  class Import
4
- VERSION = "0.0.1"
4
+ VERSION = "0.0.2"
5
5
  end
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: parse-db-import
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - JohnMorales