mongify 1.0.1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +3 -0
  3. data/.yardopts +3 -0
  4. data/CHANGELOG.rdoc +5 -0
  5. data/Gemfile.lock +52 -6
  6. data/LICENSE +1 -1
  7. data/README.rdoc +29 -11
  8. data/Rakefile +37 -9
  9. data/features/options.feature +2 -0
  10. data/features/print.feature +1 -1
  11. data/features/process.feature +10 -1
  12. data/features/step_definitions/process_steps.rb +11 -1
  13. data/features/support/env.rb +1 -1
  14. data/lib/mongify/cli/application.rb +7 -7
  15. data/lib/mongify/cli/command/worker.rb +18 -14
  16. data/lib/mongify/cli/options.rb +2 -1
  17. data/lib/mongify/configuration.rb +5 -5
  18. data/lib/mongify/database/base_connection.rb +6 -6
  19. data/lib/mongify/database/column.rb +40 -40
  20. data/lib/mongify/database/data_row.rb +9 -9
  21. data/lib/mongify/database/no_sql_connection.rb +61 -35
  22. data/lib/mongify/database/sql_connection.rb +44 -15
  23. data/lib/mongify/database/table.rb +62 -46
  24. data/lib/mongify/exceptions.rb +5 -5
  25. data/lib/mongify/progressbar.rb +15 -15
  26. data/lib/mongify/status.rb +8 -8
  27. data/lib/mongify/translation.rb +19 -17
  28. data/lib/mongify/translation/process.rb +16 -123
  29. data/lib/mongify/translation/processor_common.rb +132 -0
  30. data/lib/mongify/translation/sync.rb +112 -0
  31. data/lib/mongify/ui.rb +9 -9
  32. data/lib/mongify/version.rb +1 -1
  33. data/mongify.gemspec +4 -2
  34. data/spec/files/deleting_fields_from_embedding_parent_translation.rb +19 -0
  35. data/spec/files/embedded_parent_translation.rb +1 -1
  36. data/spec/mongify/cli/application_spec.rb +1 -1
  37. data/spec/mongify/cli/options_spec.rb +1 -1
  38. data/spec/mongify/cli/worker_command_spec.rb +46 -17
  39. data/spec/mongify/database/column_spec.rb +21 -21
  40. data/spec/mongify/database/data_row_spec.rb +11 -11
  41. data/spec/mongify/database/no_sql_connection_spec.rb +61 -27
  42. data/spec/mongify/database/sql_connection_spec.rb +62 -2
  43. data/spec/mongify/database/table_spec.rb +53 -29
  44. data/spec/mongify/translation/printer_spec.rb +2 -2
  45. data/spec/mongify/translation/process_spec.rb +50 -34
  46. data/spec/mongify/translation/sync_spec.rb +184 -0
  47. data/spec/mongify/translation_spec.rb +8 -8
  48. data/spec/mongify/ui_spec.rb +12 -12
  49. data/spec/mongify_spec.rb +1 -1
  50. data/spec/spec_helper.rb +8 -1
  51. data/spec/support/config_reader.rb +2 -2
  52. data/spec/support/database_generator.rb +68 -25
  53. data/spec/support/database_output.txt +17 -0
  54. metadata +41 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fb7c986182fbc86a55503066641a0f15a567e760
4
- data.tar.gz: 5644dc3f3c7eddd36abdf037526a6724221647f7
3
+ metadata.gz: 25663b54793dab9192d511f640820faf09c99e27
4
+ data.tar.gz: 6372a0edd4a9eac99b8716bc3222f9914bc7602d
5
5
  SHA512:
6
- metadata.gz: b9594753d2715810d2028b0681d0204857e37c5ecc27ee5e84e3663aa1a1d14daad5b9d8e8024e9522af2883b5388e402d5c5baa43e7d9f7a1d4ad4551423f1a
7
- data.tar.gz: c19b8ccf2077200c84fc9f31f61f2648fc9940aea8f3db9d42b38b1b222ad7d41625d557423cf6ff01eae483dd7a4b03e6e7bfd3e775e78be3dd61dc89ccfdcb
6
+ metadata.gz: a5b7dcc2a292bd15845099761b34f054f640255a4c5382157148e378e0718c135b0c5e07b1eb50047ccb1afa408f55ab9d55acd25a38b3e41e26d4045a15c52d
7
+ data.tar.gz: 9a0e35a33b64be04874f5f351cc8a3d8ecacb325ad1ff1cb66c2a42fa5a778e50e6663d1ee5c49f1b34a49be4ec73a45bce23295936f54299c6ccbc0a79315a1
data/.gitignore CHANGED
@@ -20,7 +20,10 @@ spec/tmp/*
20
20
  .bundle/*
21
21
 
22
22
  .rvmrc
23
+ .ruby-gemset
24
+ .ruby-version
23
25
 
24
26
  spec/support/database.yml
25
27
 
26
28
 
29
+ log/deprecations.log
@@ -0,0 +1,3 @@
1
+ -
2
+ CHANGELOG.rdoc
3
+ LICENSE
@@ -1,3 +1,8 @@
1
+ == 1.1 / 24 March 2014
2
+ * Sync feature add (thanks to {hammady}[https://github.com/hammady])
3
+ * Parent unset in before_save (tanks to {nessche}[https://github.com/nessche])
4
+ * Added batch_size (recommended by {mosheka}[https://github.com/mosheka])
5
+ * bugs and performance improvments
1
6
  == 1.0.1 / 24 December 2013
2
7
  * Updated and locked down gems to prevent Mongify from breaking when rails gets updated.
3
8
  == 1.0.0 / 28 May 2013
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- mongify (1.0.1)
4
+ mongify (1.1.0)
5
5
  activerecord (~> 3.2)
6
6
  activesupport (~> 3.2)
7
7
  bson_ext (~> 1.8.2)
@@ -23,29 +23,74 @@ GEM
23
23
  i18n (~> 0.6, >= 0.6.4)
24
24
  multi_json (~> 1.0)
25
25
  arel (3.0.3)
26
+ binding_of_caller (0.7.2)
27
+ debug_inspector (>= 0.0.1)
28
+ bond (0.5.1)
26
29
  bson (1.8.6)
27
30
  bson_ext (1.8.6)
28
31
  bson (~> 1.8.6)
29
32
  builder (3.0.4)
33
+ coderay (1.1.0)
34
+ columnize (0.3.6)
30
35
  cucumber (1.3.10)
31
36
  builder (>= 2.1.2)
32
37
  diff-lcs (>= 1.1.3)
33
38
  gherkin (~> 2.12)
34
39
  multi_json (>= 1.7.5, < 2.0)
35
40
  multi_test (>= 0.0.2)
41
+ debug_inspector (0.0.2)
42
+ debugger (1.6.6)
43
+ columnize (>= 0.3.1)
44
+ debugger-linecache (~> 1.2.0)
45
+ debugger-ruby_core_source (~> 1.3.2)
46
+ debugger-linecache (1.2.0)
47
+ debugger-ruby_core_source (1.3.2)
36
48
  diff-lcs (1.2.5)
37
49
  gherkin (2.12.2)
38
50
  multi_json (~> 1.3)
39
51
  highline (1.6.20)
40
52
  i18n (0.6.9)
53
+ interception (0.5)
54
+ jist (1.5.1)
55
+ json
56
+ json (1.8.1)
41
57
  metaclass (0.0.1)
58
+ method_source (0.8.2)
42
59
  mocha (0.14.0)
43
60
  metaclass (~> 0.0.1)
44
61
  mongo (1.8.6)
45
62
  bson (~> 1.8.6)
46
63
  multi_json (1.8.2)
47
64
  multi_test (0.0.2)
48
- mysql2 (0.2.21)
65
+ mysql2 (0.3.15)
66
+ pg (0.17.0)
67
+ pry (0.9.12.6)
68
+ coderay (~> 1.0)
69
+ method_source (~> 0.8)
70
+ slop (~> 3.4)
71
+ pry-debugger (0.2.2)
72
+ debugger (~> 1.3)
73
+ pry (~> 0.9.10)
74
+ pry-doc (0.6.0)
75
+ pry (~> 0.9)
76
+ yard (~> 0.8)
77
+ pry-docmore (0.1.1)
78
+ pry
79
+ pry-doc
80
+ pry-plus (1.0.0)
81
+ bond
82
+ jist
83
+ pry-debugger
84
+ pry-doc
85
+ pry-docmore
86
+ pry-rescue
87
+ pry-stack_explorer
88
+ pry-rescue (1.4.0)
89
+ interception (>= 0.4)
90
+ pry
91
+ pry-stack_explorer (0.4.9.1)
92
+ binding_of_caller (>= 0.7)
93
+ pry (>= 0.9.11)
49
94
  rake (10.1.1)
50
95
  rspec (2.14.1)
51
96
  rspec-core (~> 2.14.0)
@@ -55,9 +100,8 @@ GEM
55
100
  rspec-expectations (2.14.4)
56
101
  diff-lcs (>= 1.1.3, < 2.0)
57
102
  rspec-mocks (2.14.4)
103
+ slop (3.5.0)
58
104
  sqlite3 (1.3.8)
59
- sqlite3-ruby (1.3.3)
60
- sqlite3 (>= 1.3.3)
61
105
  tzinfo (0.3.38)
62
106
  watchr (0.7)
63
107
  yard (0.8.7.3)
@@ -69,9 +113,11 @@ DEPENDENCIES
69
113
  cucumber (>= 0.10)
70
114
  mocha (>= 0.9.8)
71
115
  mongify!
72
- mysql2 (~> 0.2.7)
116
+ mysql2 (~> 0.3.1)
117
+ pg (>= 0.17)
118
+ pry-plus
73
119
  rake
74
120
  rspec (>= 2.0)
75
- sqlite3-ruby (>= 1.3)
121
+ sqlite3 (>= 1.3)
76
122
  watchr (>= 0.6)
77
123
  yard (>= 0.5.3)
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2011-2013 Andrew Kalek, Anlek Consulting
1
+ Copyright (c) 2010-2014 Andrew Kalek, Anlek Consulting
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
@@ -24,16 +24,17 @@ In order for Mongify to do its job, it needs to know where your databases are lo
24
24
  Building a config file is as simple as this:
25
25
 
26
26
  sql_connection do
27
- adapter "mysql"
28
- host "localhost"
29
- username "root"
30
- password "passw0rd"
31
- database "my_database"
27
+ adapter "mysql"
28
+ host "localhost"
29
+ username "root"
30
+ password "passw0rd"
31
+ database "my_database"
32
+ batch_size 10000 # This is defaulted to 10000 but in case you want to make that smaller (on lower RAM machines)
32
33
  end
33
34
 
34
35
  mongodb_connection do
35
- host "localhost"
36
- database "my_database"
36
+ host "localhost"
37
+ database "my_database"
37
38
  end
38
39
 
39
40
  You can check your configuration by running
@@ -114,6 +115,7 @@ Save the file as <tt>"translation_file.rb"</tt> and run the command:
114
115
  Commands:
115
116
  "check" or "ck" >> Checks connection for sql and no_sql databases [configuration_file]
116
117
  "process" or "pr" >> Takes a translation and process it to mongodb [configuration_file, translation_file]
118
+ "sync" or "sy" >> Takes a translation and process it to mongodb, only syncs (insert/update) new or updated records based on the updated_at column [configuration_file, translation_file]
117
119
  "translation" or "tr" >> Outputs a translation file from a sql connection [configuration_file]
118
120
 
119
121
  Examples:
@@ -122,6 +124,7 @@ Save the file as <tt>"translation_file.rb"</tt> and run the command:
122
124
  mongify tr database.config
123
125
  mongify check database.config
124
126
  mongify process database.config database_translation.rb
127
+ mongify sync database.config database_translation.rb
125
128
 
126
129
  Common options:
127
130
  -h, --help Show this message
@@ -185,9 +188,13 @@ Table Options are as follow:
185
188
  end
186
189
 
187
190
  table "preferences", :embed_in => "users" do # As of version 0.2, embedded tables with a before_save will take an
188
- before_save do |pref_row, user_row| # extra argument which is the parent row of the embedded table.
191
+ before_save do |pref_row, user_row, unset_user_row| # extra argument which is the parent row of the embedded table.
189
192
  user_row.email_me = pref_row.delete('email_me') # This gives you the ability to move things from an embedded table row
190
- end # to the parent row.
193
+ # to the parent row.
194
+ if pref_row['one_name']
195
+ unset_user_row['last_name'] = true # This will delete/unset the last name for the parent row
196
+ end
197
+ end
191
198
  end
192
199
 
193
200
  More documentation can be found at {Mongify::Database::Table}
@@ -247,9 +254,14 @@ More documentation can be found at {Mongify::Database::Column}
247
254
 
248
255
  == Notes
249
256
 
250
- Mongify has been tested on Ruby 1.8.7-p330 and Ruby 1.9.2-p136
257
+ Mongify has been tested on Ruby 1.8.7-p330, 1.9.2-p136, 1.9.3-p327, 2.0.0-p353, 2.1.1
258
+
251
259
  If you have any issues, please feel free to report them here: {issue tracker}[https://github.com/anlek/mongify/issues]
252
260
 
261
+ == Sync Note
262
+
263
+ If you want to continually sync your sql database with MongoDB using Mongify, you MUST run the sync feature from the start. Using the process command will not permit future syncing. The sync feature leaves the `pre_mongify_id` in your documents as well as it creates it's own collection called `__mongify_sync_helper__` to keep dates and times of your last sync.
264
+
253
265
  == Additional Tools
254
266
 
255
267
  As of May 2013, we've released an add-on tool to Mongify called {Mongify-Mongoid}[https://github.com/anlek/mongify-mongoid] which lets you use the translation.rb file to generate Mongoid models. It generates the model fields, relations (most of the way) and timestamps. This should save you some time from having to re-type all the models by hand.
@@ -272,7 +284,8 @@ You just need bundler >= 1.0.8
272
284
  gem install bundler
273
285
  bundle install
274
286
  copy over spec/support/database.example to spec/support/database.yml and fill in required info
275
- rake test:mysql:setup
287
+ rake test:setup:mysql
288
+ rake test:setup:postgresql
276
289
  rake test
277
290
 
278
291
  == Special Thanks
@@ -292,6 +305,11 @@ Reach me at:
292
305
  * Twitter: {@anlek}[http://www.twitter.com/anlek]
293
306
  * Email: andrew.kalek@anlek[dot]com
294
307
 
308
+ The sync functionality was made by Hossam Hammady from Qatar Computing Research Institute
309
+
310
+ Reach me at:
311
+ * Twitter: {@hammady}[http://www.twitter.com/hammady]
312
+ * Email: hhammady@qf[dot]org[dot]qa
295
313
 
296
314
  == License
297
315
 
data/Rakefile CHANGED
@@ -18,17 +18,17 @@ end
18
18
 
19
19
  if RUBY_VERSION.to_f == 1.8
20
20
  namespace :rcov do
21
- Cucumber::Rake::Task.new(:cucumber) do |t|
21
+ Cucumber::Rake::Task.new(:cucumber) do |t|
22
22
  t.rcov = true
23
23
  t.rcov_opts = %w{--exclude osx\/objc,gems\/,spec\/,features\/ --aggregate coverage.data}
24
24
  t.rcov_opts << %[-o "coverage"]
25
25
  end
26
-
26
+
27
27
  RSpec::Core::RakeTask.new(:rspec) do |t|
28
28
  t.rcov = true
29
29
  t.rcov_opts = %w{--exclude osx\/objc,gems\/,spec\/,features\/}
30
30
  end
31
-
31
+
32
32
  desc "Run both specs and features to generate aggregated coverage"
33
33
  task :all do |t|
34
34
  rm "coverage.data" if File.exist?("coverage.data")
@@ -42,18 +42,47 @@ desc "Run rspec test"
42
42
  task :test do
43
43
  Rake::Task["test:rspec"].invoke
44
44
  if RUBY_VERSION.to_f < 1.9
45
- Rake::Task["rcov:cucumber"].invoke
45
+ Rake::Task["rcov:cucumber"].invoke
46
46
  else
47
- Rake::Task["test:cucumber"].invoke
47
+ Rake::Task["test:cucumber"].invoke
48
48
  end
49
49
  end
50
50
  namespace :test do
51
51
  RSpec::Core::RakeTask.new(:rspec)
52
52
  Cucumber::Rake::Task.new(:cucumber)
53
-
54
- namespace :mysql do
53
+
54
+ namespace :setup do
55
+ desc "Setup a postgresql database based on the spec/support/database.yml settings (under postgresql)"
56
+ task :postgresql do
57
+ require './spec/support/config_reader'
58
+ require 'active_record'
59
+ ::CONNECTION_CONFIG = ConfigReader.new('spec/support/database.yml')
60
+ ActiveRecord::Base.establish_connection(CONNECTION_CONFIG.postgresql)
61
+ conn = ActiveRecord::Base.connection
62
+ conn.create_table(:users, :force => true) do |t|
63
+ t.string :first_name, :last_name
64
+ t.timestamps
65
+ end
66
+
67
+ conn.create_table(:posts, :force => true) do |t|
68
+ t.string :title
69
+ t.integer :owner_id
70
+ t.text :body
71
+ t.datetime :published_at
72
+ t.timestamps
73
+ end
74
+
75
+ conn.create_table(:comments, :force => true) do |t|
76
+ t.text :body
77
+ t.integer :post_id
78
+ t.integer :user_id
79
+ t.timestamps
80
+ end
81
+ puts "Finished"
82
+ end
83
+
55
84
  desc "Setup a mysql database based on the spec/support/database.yml settings"
56
- task :setup do
85
+ task :mysql do
57
86
  require './spec/support/config_reader'
58
87
  require 'active_record'
59
88
  ::CONNECTION_CONFIG = ConfigReader.new('spec/support/database.yml')
@@ -83,5 +112,4 @@ namespace :test do
83
112
  end
84
113
  end
85
114
 
86
-
87
115
  task :default => ['test']
@@ -24,6 +24,7 @@ Feature: Mongify can be controlled using command-line options
24
24
  Commands:
25
25
  "check" or "ck" >> Checks connection for sql and no_sql databases [configuration_file]
26
26
  "process" or "pr" >> Takes a translation and process it to mongodb [configuration_file, translation_file]
27
+ "sync" or "sy" >> Takes a translation and process it to mongodb, only syncs (insert/update) new or updated records based on the updated_at column [configuration_file, translation_file]
27
28
  "translation" or "tr" >> Outputs a translation file from a sql connection [configuration_file]
28
29
 
29
30
  Examples:
@@ -31,6 +32,7 @@ Feature: Mongify can be controlled using command-line options
31
32
  mongify check database.config
32
33
  mongify translation datbase.config > database_translation.rb
33
34
  mongify process database.config database_translation.rb
35
+ mongify sync database.config database_translation.rb
34
36
 
35
37
  See http://github.com/anlek/mongify for more details
36
38
 
@@ -2,7 +2,7 @@ Feature: Database Translation Output
2
2
  In order to translate sql database to a no-sql database
3
3
  As a developer / database admin
4
4
  Needs to be able to generate a translation file
5
-
5
+
6
6
  Scenario: Translation Output request
7
7
  Given a database exists
8
8
  When I run mongify translation spec/files/base_configuration.rb
@@ -14,7 +14,7 @@ Feature: Processing a translation
14
14
  And there should be 0 comments in mongodb
15
15
  And the post with title "First Post" should have 1 comment
16
16
  And the post with title "Second Post" should have 2 comments
17
-
17
+
18
18
  Scenario: Processing while modifying embedding parent.
19
19
  Given a database exists
20
20
  And a blank mongodb
@@ -23,3 +23,12 @@ Feature: Processing a translation
23
23
  And there should be 3 users in mongodb
24
24
  And the first user's notify_by_email attribute should be true
25
25
  And the third user's notify_by_email attribute should be false
26
+
27
+ Scenario: Processing while deleting fields from embedding parent
28
+ Given a database exists
29
+ And a blank mongodb
30
+ When I run mongify process spec/files/base_configuration.rb spec/files/deleting_fields_from_embedding_parent_translation.rb
31
+ Then it succeeds
32
+ And there should be 3 teams in mongodb
33
+ And the first team's phone attribute should not be present
34
+ And the third team's coach's phone attribute should be +1112223334
@@ -1,4 +1,14 @@
1
- Then /^the (first|second|third) (.+)'s (.+) attribute should be (.+)$/ do |collection_place, collection_name, field, value|
1
+ Then /^the (first|second|third) ([^\s]+)'s ([^\s]+) attribute should be (.+)$/ do |collection_place, collection_name, field, value|
2
2
  DatabaseGenerator.mongo_connection.db[collection_name.pluralize].
3
3
  find.to_a.send(collection_place.to_sym)[field].to_s.should == value.to_s
4
+ end
5
+
6
+ Then /^the (first|second|third) ([^\s]+)'s ([^\s]+) attribute should( not)? be present$/ do |collection_place, collection_name, field, negate|
7
+ DatabaseGenerator.mongo_connection.db[collection_name.pluralize].
8
+ find.to_a.send(collection_place.to_sym).has_key?(field).should (negate ? be_false : be_true)
9
+ end
10
+
11
+ Then /^the (first|second|third) ([^\s]+)'s ([^\s]+)'s ([^\s]+) attribute should be (.+)$/ do |collection_place, collection_name, embedded_name, field, value|
12
+ DatabaseGenerator.mongo_connection.db[collection_name.pluralize].
13
+ find.to_a.send(collection_place.to_sym)[embedded_name][field].to_s.should == value.to_s
4
14
  end
@@ -23,7 +23,7 @@ module MongifyWorld
23
23
  @last_exit_status = $?.exitstatus
24
24
  @last_stderr = IO.read(stderr_file.path)
25
25
  end
26
-
26
+
27
27
  # Executes mongify command with arguments
28
28
  def mongify(args)
29
29
  run("ruby -Ilib -rubygems bin/mongify #{args}")
@@ -7,12 +7,12 @@ module Mongify
7
7
  # command line.
8
8
  #
9
9
  class Application
10
-
10
+
11
11
  # Successful execution exit code
12
12
  STATUS_SUCCESS = 0
13
- # Failed execution exit code
13
+ # Failed execution exit code
14
14
  STATUS_ERROR = 1
15
-
15
+
16
16
  def initialize(arguments=[], stdin=$stdin, stdout=$stdout)
17
17
  arguments = ['-h'] if arguments.empty?
18
18
  @options = Options.new(arguments)
@@ -20,7 +20,7 @@ module Mongify
20
20
  Mongify::Configuration.in_stream = stdin
21
21
  Mongify::Configuration.out_stream = stdout
22
22
  end
23
-
23
+
24
24
  # Runs the application
25
25
  def execute!
26
26
  begin
@@ -34,17 +34,17 @@ module Mongify
34
34
  raise error
35
35
  end
36
36
  end
37
-
37
+
38
38
  # Sends output to the UI
39
39
  def output(message)
40
40
  UI.puts(message)
41
41
  end
42
-
42
+
43
43
  # Sets status code as successful
44
44
  def report_success
45
45
  @status = STATUS_SUCCESS
46
46
  end
47
-
47
+
48
48
  # Sets status code as failure (or error)
49
49
  def report_error
50
50
  @status = STATUS_ERROR
@@ -6,15 +6,16 @@ module Mongify
6
6
  #
7
7
  class Worker
8
8
  attr_accessor :view
9
-
9
+
10
10
  # A hash of available commands
11
11
  # Including description, additional shortcuts to run the commands and requirements to run the command
12
12
  AVAILABLE_COMMANDS = {
13
13
  :check => {:commands => ['check', 'ck'], :description => "Checks connection for sql and no_sql databases", :required => [:configuration_file]},
14
14
  :translation => {:commands => ['translation', 'tr'], :description => "Outputs a translation file from a sql connection", :required => [:configuration_file]},
15
- :process => {:commands => ['process', 'pr'], :description => "Takes a translation and process it to mongodb", :required => [:configuration_file, :translation_file]}
15
+ :process => {:commands => ['process', 'pr'], :description => "Takes a translation and process it to mongodb", :required => [:configuration_file, :translation_file]},
16
+ :sync => {:commands => ['sync', 'sy'], :description => "Takes a translation and process it to mongodb, only syncs (insert/update) new or updated records based on the updated_at column", :required => [:configuration_file, :translation_file]}
16
17
  }
17
-
18
+
18
19
  # Prints out a nice display of the list of commands
19
20
  def self.list_commands
20
21
  [].tap do |commands|
@@ -23,7 +24,7 @@ module Mongify
23
24
  end
24
25
  end.sort
25
26
  end
26
-
27
+
27
28
  # Finds a command array by any of the shortcut commands
28
29
  def self.find_command(command)
29
30
  AVAILABLE_COMMANDS.each do |key, options|
@@ -31,20 +32,20 @@ module Mongify
31
32
  end
32
33
  'unknown'
33
34
  end
34
-
35
+
35
36
  def initialize(command, config=nil, translation_file=nil, parser="")
36
37
  @command = command.to_s.downcase
37
38
  @config = config
38
39
  @translation_file = translation_file
39
40
  @parser = parser
40
41
  end
41
-
42
+
42
43
  #Executes the worked based on a given command
43
44
  def execute(view)
44
45
  self.view = view
45
-
46
+
46
47
  current_command, command_options = find_command
47
-
48
+
48
49
  if command_options
49
50
  #FIXME: Should parse configuration file in this action, (when I know it's required)
50
51
  raise ConfigurationFileNotFound, "Database Configuration file is missing or cannot be found" if command_options[:required] && command_options[:required].include?(:configuration_file) && @config.nil?
@@ -54,7 +55,7 @@ module Mongify
54
55
  @translation = Translation.parse(@translation_file)
55
56
  end
56
57
  end
57
-
58
+
58
59
  case current_command
59
60
  when :translation
60
61
  check_connections
@@ -65,18 +66,21 @@ module Mongify
65
66
  when :process
66
67
  check_connections
67
68
  @translation.process(@config.sql_connection, @config.no_sql_connection)
69
+ when :sync
70
+ check_connections
71
+ @translation.sync(@config.sql_connection, @config.no_sql_connection)
68
72
  else
69
73
  view.output("Unknown action #{@command}\n\n#{@parser}")
70
74
  return view.report_error
71
75
  end
72
76
  view.report_success
73
77
  end
74
-
78
+
75
79
  # Passes find command to parent class
76
80
  def find_command(command=@command)
77
81
  self.class.find_command(command)
78
82
  end
79
-
83
+
80
84
  #######
81
85
  private
82
86
  #######
@@ -85,15 +89,15 @@ module Mongify
85
89
  def check_connections
86
90
  check_sql_connection && check_nosql_connection
87
91
  end
88
-
92
+
89
93
  # Checks sql connection if it's valid and has_connection?
90
94
  def check_sql_connection
91
95
  @config.sql_connection.valid? && @config.sql_connection.has_connection?
92
96
  end
93
-
97
+
94
98
  # Checks no sql connection if it's valid and has_connection?
95
99
  def check_nosql_connection
96
- @config.no_sql_connection.valid? && @config.no_sql_connection.has_connection?
100
+ @config.no_sql_connection.valid? && @config.no_sql_connection.has_connection?
97
101
  end
98
102
  end
99
103
  end