mongify 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,8 @@
1
+ == 0.1.2 / 14 Feb 2011
2
+ * More Improvements to README and RDOC
3
+ * Added ability to :force => true on a mongodb_connection, forcing it to drop database before processing.
4
+ * Improved UI output
5
+ * Added activesupport notifications to keep track of what is happening with the system during import.
1
6
  == 0.1.1 / 28 Jan 2011
2
7
  * Renamed GenerateDatabase to DatabaseGenerator
3
8
  * Renamed Table#embed? to Table#embedded?
@@ -1,23 +1,32 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- mongify (0.1.1)
5
- activerecord (>= 2.3.10)
6
- activesupport (>= 2.3.10)
4
+ mongify (0.1.2)
5
+ activerecord (>= 3.0.3)
6
+ activesupport (>= 3.0.3)
7
7
  bson_ext (>= 1.1.5)
8
8
  mongo (>= 1.1.5)
9
9
  mysql2
10
10
  net-ssh (>= 2.0)
11
+ progressbar (>= 0.9)
11
12
 
12
13
  GEM
13
14
  remote: http://rubygems.org/
14
15
  specs:
15
- activerecord (2.3.10)
16
- activesupport (= 2.3.10)
17
- activesupport (2.3.10)
16
+ activemodel (3.0.3)
17
+ activesupport (= 3.0.3)
18
+ builder (~> 2.1.2)
19
+ i18n (~> 0.4)
20
+ activerecord (3.0.3)
21
+ activemodel (= 3.0.3)
22
+ activesupport (= 3.0.3)
23
+ arel (~> 2.0.2)
24
+ tzinfo (~> 0.3.23)
25
+ activesupport (3.0.3)
26
+ arel (2.0.7)
18
27
  bson (1.2.0)
19
28
  bson_ext (1.2.0)
20
- builder (3.0.0)
29
+ builder (2.1.2)
21
30
  cucumber (0.10.0)
22
31
  builder (>= 2.1.2)
23
32
  diff-lcs (~> 1.1.2)
@@ -27,6 +36,7 @@ GEM
27
36
  diff-lcs (1.1.2)
28
37
  gherkin (2.3.3)
29
38
  json (~> 1.4.6)
39
+ i18n (0.5.0)
30
40
  json (1.4.6)
31
41
  mocha (0.9.10)
32
42
  rake
@@ -34,7 +44,8 @@ GEM
34
44
  bson (>= 1.2.0)
35
45
  mysql (2.8.1)
36
46
  mysql2 (0.2.6)
37
- net-ssh (2.0.24)
47
+ net-ssh (2.1.0)
48
+ progressbar (0.9.0)
38
49
  rake (0.8.7)
39
50
  rcov (0.9.9)
40
51
  rspec (2.4.0)
@@ -49,6 +60,7 @@ GEM
49
60
  sqlite3-ruby (1.3.3)
50
61
  sqlite3 (>= 1.3.3)
51
62
  term-ansicolor (1.0.5)
63
+ tzinfo (0.3.24)
52
64
  watchr (0.7)
53
65
  yard (0.6.4)
54
66
 
@@ -15,7 +15,7 @@ Learn more about MongoDB at: http://www.mongodb.org
15
15
 
16
16
  == Usage
17
17
 
18
- ===Creating a configuration file
18
+ === Creating a configuration file
19
19
 
20
20
  In order for Mongify to do it's job, it needs to know where your databases are located.
21
21
 
@@ -36,6 +36,13 @@ Building a config file is as simple as this:
36
36
 
37
37
  You can check your configuration by running
38
38
  mongify check -c datbase.config
39
+
40
+ ==== Options
41
+ Currently the only option that is support it is for the mongodb_connection.
42
+
43
+ mongodb_connection :force => true do # Forcing a mongodb_connection will drop the database before processing
44
+ # ...
45
+ end
39
46
 
40
47
  <em>You can omit the mongodb connection till you're ready to process your translation</em>
41
48
 
@@ -84,6 +91,16 @@ Creating a translation is pretty straight forward. It looks something like this:
84
91
  column "notify_by_email", :boolean
85
92
  end
86
93
 
94
+ table "notes", :embed_in => true, :polymorphic => 'notable' do
95
+ column "id", :key
96
+ column "user_id", :integer, :references => "users"
97
+ column "notable_id", :integer
98
+ column "notable_type", :string
99
+ column "body", :text
100
+ column "created_at", :datetime
101
+ column "updated_at", :datetime
102
+ end
103
+
87
104
  Save the file as <tt>"translation_file.rb"</tt> and run the command:
88
105
 
89
106
  mongify process translation_file.rb -c database.config
@@ -126,15 +143,19 @@ Structure for defining a table is as follows:
126
143
 
127
144
  Table Options are as follow:
128
145
  table "table_name" # Does a straight copy of the table
129
- table "table_name", :embed_in => :users # Embeds table_name into users, assuming a user_id is present in table_name.
130
- # This will also assume you want the table embedded as an array.
131
- table "table_name", :embed_in => :users, :on => 'owner_id'# Embeds table_name into users, linking it via a owner_id
146
+ table "table_name", :embed_in => 'users' # Embeds table_name into users, assuming a user_id is present in table_name.
132
147
  # This will also assume you want the table embedded as an array.
133
- table "table_name", :embed_in => :users, :as => :object # Embeds table_name into users as a one to one relationship
134
- # This also assumes you have a user_id present in table_name
135
- <em>You can also specify both <b>:on</b> and <b>:as</b> options when embedding</em>
136
-
137
- <b>NOTE: If you rename the owner_id column, make sure you update the :on to the new column name</b>
148
+
149
+ table "table_name", # Embeds table_name into users, linking it via a owner_id
150
+ :embed_in => 'users', # This will also assume you want the table embedded as an array.
151
+ :on => 'owner_id'
152
+
153
+ table "table_name", # Embeds table_name into users as a one to one relationship
154
+ :embed_in => 'users', # This also assumes you have a user_id present in table_name
155
+ :on => 'owner_id', # You can also specify both :on and :as options when embedding
156
+ :as => 'object' # NOTE: If you rename the owner_id column, make sure you
157
+ # update the :on to the new column name
158
+
138
159
 
139
160
  table "table_name", :rename_to => 'my_table' # This will allow you to rename the table as it's getting process
140
161
  # Just remember that columns that use :reference need to
@@ -144,8 +165,8 @@ Table Options are as follow:
144
165
  # This option is good for tables like: schema_migrations
145
166
 
146
167
  table "table_name", # This allows you to specify the table as being polymorphic
147
- :polymorphic => 'notable', # and provide the name of the polymorphic relationship.
148
- :embed_in => true # Setting embed_in => true allows the relationship to be
168
+ :polymorphic => 'notable', # and provide the name of the polymorphic relationship.
169
+ :embed_in => true # Setting embed_in => true allows the relationship to be
149
170
  # embedded directly into the parent class.
150
171
  # If you do not embed it, the polymorphic table will be copied in to
151
172
  # MongoDB and the notable_id will be updated to the new BSON::ObjectID
@@ -187,11 +208,13 @@ Before we cover the options, you need to know what types of columns are supporte
187
208
 
188
209
  column "post_id", :integer, :referneces => :posts # Referenced columns need to be marked as such, this will mean that they will be updated
189
210
  # with the new BSON::ObjectID.
190
- <b>NOTE: if you rename the table 'posts', you should set the :references to the new name</b>
211
+ # NOTE: if you rename the table 'posts', you should set the :references to the new name
191
212
 
192
213
  column "name", :string, :ignore => true # Ignoring a column will make the column NOT copy over to the new database
193
214
 
194
- column "surname", :string, :rename_to => 'last_name'# Rename_to allows you to rename the column
215
+ column "surname",
216
+ :string,
217
+ :rename_to => 'last_name' # Rename_to allows you to rename the column
195
218
 
196
219
  == Notes
197
220
 
@@ -202,7 +225,6 @@ More testing will be done once the basic functionality is done
202
225
 
203
226
  == TODO
204
227
 
205
- * Allow you to set a :force => true for mongodb_connection, so that it drops existing database before importing
206
228
  * Update user on what is being processed
207
229
 
208
230
  == Development
@@ -220,9 +242,16 @@ You just need bundler 1.0.8
220
242
 
221
243
  Just want to thank my wife (Alessia) who not only puts up with me working on my free time but sometimes helps out listening to my craziness or helping me name classes or functions.
222
244
 
223
- === More Special Thanks
245
+ I would also like to thank Mon_Ouie on the Ruby IRC channel for helping me figure out how to setup the internal configuration file reading.
246
+
247
+ == About
248
+
249
+ This gem was made by Andrew Kalek
250
+
251
+ Reach me at:
252
+ * Twitter: {@anlek}[http://www.twitter.com/anlek]
253
+ * Email: andrew.kalek@anlek[dot]com
224
254
 
225
- I'd like to thank Mon_Ouie on the Ruby IRC channel for helping me figure out how to setup the internal configuration file reading.
226
255
 
227
256
  == License
228
257
 
@@ -3,13 +3,17 @@
3
3
  #
4
4
  require 'active_support/core_ext'
5
5
  require 'active_record'
6
+ require 'progressbar'
6
7
 
7
8
  require 'mongify/ui'
9
+ require 'mongify/status'
8
10
  require 'mongify/exceptions'
9
11
  require 'mongify/translation'
10
12
  require 'mongify/configuration'
11
13
  require 'mongify/database'
12
14
 
15
+ Mongify::Status.register
16
+
13
17
  module Mongify # Namespace for Mongify
14
18
  class << self
15
19
  # Handles setting root for the application
@@ -6,7 +6,7 @@ module Mongify
6
6
  #
7
7
  # Basic format should look something like this:
8
8
  #
9
- # no_sql_connection do
9
+ # no_sql_connection {options} do
10
10
  # adapter "mongodb"
11
11
  # host "localhost"
12
12
  # database "my_database"
@@ -19,6 +19,10 @@ module Mongify
19
19
  # username
20
20
  # password
21
21
  # port
22
+ #
23
+ # Options:
24
+ # :force => true # This will force a database drop before processing
25
+ # <em>You're also able to set attributes via the options</em>
22
26
  #
23
27
  class NoSqlConnection < Mongify::Database::BaseConnection
24
28
  include Mongo
@@ -26,8 +30,9 @@ module Mongify
26
30
  #Required fields for a no sql connection
27
31
  REQUIRED_FIELDS = %w{host database}
28
32
 
29
- def initialize(options=nil)
33
+ def initialize(options={})
30
34
  super options
35
+ @options = options
31
36
  adapter 'mongodb' if adapter.nil? || adapter == 'mongo'
32
37
  end
33
38
 
@@ -50,6 +55,12 @@ module Mongify
50
55
  super && @database.present?
51
56
  end
52
57
 
58
+ # Returns true if :force was set to true
59
+ # This will force a drop of the database upon connection
60
+ def forced?
61
+ !!@options['force']
62
+ end
63
+
53
64
  # Sets up a connection to the database
54
65
  def setup_connection_adapter
55
66
  connection = Connection.new(host, port)
@@ -58,8 +69,12 @@ module Mongify
58
69
  end
59
70
 
60
71
  # Returns a mongo connection
72
+ # NOTE: If forced? is true, the first time a connection is made, it will ask to drop the
73
+ # database before continuing
61
74
  def connection
62
- @connection ||= setup_connection_adapter
75
+ return @connection if @connection
76
+ @connection = setup_connection_adapter
77
+ @connection
63
78
  end
64
79
 
65
80
  # Returns true or false depending if we have a connection to a mongo server
@@ -102,6 +117,24 @@ module Mongify
102
117
  db[collection_name].update({}, { '$unset' => { 'pre_mongified_id' => 1} }, :multi => true)
103
118
  end
104
119
 
120
+ # Asks user permission to drop the database
121
+ def ask_to_drop_database
122
+ if UI.ask("Are you sure you want to drop #{database} database?")
123
+ drop_database
124
+ end
125
+ end
126
+
127
+ #######
128
+ private
129
+ #######
130
+
131
+ # Drops the mongodb database
132
+ def drop_database
133
+ connection.drop_database(database)
134
+ end
135
+
136
+
137
+
105
138
  end
106
139
  end
107
140
  end
@@ -14,16 +14,19 @@ module Mongify
14
14
  #
15
15
  # Table Options are as follow:
16
16
  # table "table_name" # Does a straight copy of the table
17
- # table "table_name", :embed_in => :users # Embeds table_name into users, assuming a user_id is present in table_name.
17
+ # table "table_name", :embed_in => 'users' # Embeds table_name into users, assuming a user_id is present in table_name.
18
18
  # # This will also assume you want the table embedded as an array.
19
- # table "table_name", :embed_in => :users, :on => 'owner_id'# Embeds table_name into users, linking it via a owner_id
20
- # # This will also assume you want the table embedded as an array.
21
- # table "table_name", :embed_in => :users, :as => :object # Embeds table_name into users as a one to one relationship
22
- # # This also assumes you have a user_id present in table_name
23
- # table "table_name", :embed_in => :posts, :on => 'post_id', :as => 'array'
24
- # # You can also do both :on and :as
25
19
  #
26
- # <b>NOTE: If you rename the owner_id column, make sure you update the :on to the new column name</b>
20
+ # table "table_name", # Embeds table_name into users, linking it via a owner_id
21
+ # :embed_in => 'users', # This will also assume you want the table embedded as an array.
22
+ # :on => 'owner_id'
23
+ #
24
+ # table "table_name", # Embeds table_name into users as a one to one relationship
25
+ # :embed_in => 'users', # This also assumes you have a user_id present in table_name
26
+ # :on => 'owner_id', # You can also specify both :on and :as options when embedding
27
+ # :as => 'object' # NOTE: If you rename the owner_id column, make sure you
28
+ # # update the :on to the new column name
29
+ #
27
30
  #
28
31
  # table "table_name", :rename_to => 'my_table' # This will allow you to rename the table as it's getting process
29
32
  # # Just remember that columns that use :reference need to
@@ -32,19 +35,19 @@ module Mongify
32
35
  # table "table_name", :ignore => true # This will ignore the whole table (like it doesn't exist)
33
36
  # # This option is good for tables like: schema_migrations
34
37
  #
35
- # table "table_name", :polymorphic => 'commentable' # This will identfiy the table as polymorphic and the new ids
36
- # # will be updated as needed.
37
- #
38
38
  # table "table_name", # This allows you to specify the table as being polymorphic
39
- # :polymorphic => 'notable', # and provide the name of the polymorphic relationship.
40
- # :embed_in => true # Setting embed_in => true allows the relationship to be
39
+ # :polymorphic => 'notable', # and provide the name of the polymorphic relationship.
40
+ # :embed_in => true # Setting embed_in => true allows the relationship to be
41
41
  # # embedded directly into the parent class.
42
- #
42
+ # # If you do not embed it, the polymorphic table will be copied in to
43
+ # # MongoDB and the notable_id will be updated to the new BSON::ObjectID
44
+ #
43
45
  # table "table_name" do # A table can take a before_save block that will be called just
44
46
  # before_save do |row| # before the row is saved to the no sql database.
45
47
  # row.admin = row.delete('permission').to_i > 50 # This gives you the ability to do very powerful things like:
46
48
  # end # Moving records around, renaming records, changing values in row based on
47
- # end # some values! Checkout {Mongify::Database::DataRow} to learn more
49
+ # end # some values! Checkout Mongify::Database::DataRow to learn more
50
+
48
51
  class Table
49
52
 
50
53
  attr_accessor :name, :sql_name
@@ -0,0 +1,26 @@
1
+ module Mongify
2
+ # This class is responsible for generating progress bars with status of mongify
3
+ class Status
4
+ class << self
5
+ # Registers the ActiveSupport::Notifications for Mongify
6
+ def register
7
+ @bars = {}
8
+ ActiveSupport::Notifications.subscribe(/^mongify\./) do |*args|
9
+ event = ActiveSupport::Notifications::Event.new(*args)
10
+ # puts event.name
11
+ mongify, name, action = event.name.split('.', 3)
12
+ case action
13
+ when 'start'
14
+ @bars[name] = ProgressBar.new(name.humanize, event.payload[:size] || 0)
15
+ when 'inc'
16
+ @bars[name].try(:inc)
17
+ when 'finish'
18
+ @bars[name].try(:finish)
19
+ else
20
+ UI.warn("Unknown Notification Event #{event.name}")
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -37,6 +37,18 @@ module Mongify
37
37
  # column "user_id", :integer, :references => "users"
38
38
  # column "notify_by_email", :boolean
39
39
  # end
40
+ #
41
+ # table "notes", :embed_in => true, :polymorphic => 'notable' do
42
+ # column "id", :key
43
+ # column "user_id", :integer, :references => "users"
44
+ # column "notable_id", :integer
45
+ # column "notable_type", :string
46
+ # column "body", :text
47
+ # column "created_at", :datetime
48
+ # column "updated_at", :datetime
49
+ # end
50
+ #
51
+
40
52
  class Translation
41
53
  include Printer
42
54
  include Process
@@ -101,6 +113,7 @@ module Mongify
101
113
  tables.reject{|t| t.embedded?}
102
114
  end
103
115
 
116
+ # Returns an array of all tables that have a polymorphic relationship
104
117
  def polymorphic_tables
105
118
  all_tables.reject{ |t| t.ignored? || !t.polymorphic? }
106
119
  end
@@ -17,6 +17,8 @@ module Mongify
17
17
  self.no_sql_connection = no_sql_connection
18
18
  raise "noSql Connection is not valid" unless self.no_sql_connection.valid?
19
19
 
20
+ no_sql_connection.ask_to_drop_database if no_sql_connection.forced?
21
+
20
22
  copy_data
21
23
  copy_embedded_tables
22
24
  update_reference_ids
@@ -31,15 +33,19 @@ module Mongify
31
33
 
32
34
  # Does the straight copy (of tables)
33
35
  def copy_data
36
+ ActiveSupport::Notifications.instrument('mongify.copy_data.start', :size => self.copy_tables.count)
34
37
  self.copy_tables.each do |t|
35
38
  sql_connection.select_rows(t.sql_name).each do |row|
36
39
  no_sql_connection.insert_into(t.name, t.translate(row))
37
40
  end
41
+ ActiveSupport::Notifications.instrument('mongify.copy_data.inc')
38
42
  end
43
+ ActiveSupport::Notifications.instrument('mongify.copy_data.finish')
39
44
  end
40
45
 
41
46
  # Does a copy of the embedded tables
42
47
  def copy_embedded_tables
48
+ ActiveSupport::Notifications.instrument('mongify.copy_embedded_tables.start', :size => self.embed_tables.count)
43
49
  self.embed_tables.each do |t|
44
50
  sql_connection.select_rows(t.sql_name).each do |row|
45
51
  target_row = no_sql_connection.find_one(t.embed_in, {:pre_mongified_id => row[t.embed_on]})
@@ -51,17 +57,19 @@ module Mongify
51
57
  save_function_call = t.embedded_as_object? ? '$set' : '$addToSet'
52
58
  no_sql_connection.update(t.embed_in, target_row['_id'], {save_function_call => {t.name => row}})
53
59
  end
60
+ ActiveSupport::Notifications.instrument('mongify.copy_embedded_tables.inc')
54
61
  end
62
+ ActiveSupport::Notifications.instrument('mongify.copy_embedded_tables.finish')
55
63
  end
56
64
 
57
65
  # Moves over polymorphic data
58
66
  def copy_polymorphic_tables
67
+ ActiveSupport::Notifications.instrument('mongify.copy_polymorphic_tables.start', :size => self.polymorphic_tables.count)
59
68
  self.polymorphic_tables.each do |t|
60
69
  polymorphic_id_col, polymorphic_type_col = "#{t.polymorphic_as}_id", "#{t.polymorphic_as}_type"
61
70
  sql_connection.select_rows(t.sql_name).each do |row|
62
71
  table_name = row[polymorphic_type_col].tableize
63
72
  new_id = no_sql_connection.get_id_using_pre_mongified_id(table_name, row[polymorphic_id_col])
64
- puts "getting new id for #{table_name}, #{row[polymorphic_id_col]} and getting #{new_id}"
65
73
  if new_id
66
74
  row = t.translate(row)
67
75
  row.merge!(fetch_reference_ids(t, row))
@@ -76,21 +84,26 @@ module Mongify
76
84
  no_sql_connection.insert_into(t.name, row)
77
85
  end
78
86
  else
79
- puts "#{table_name} table not found on #{t.sql_name} polymorphic import"
87
+ UI.warn "#{table_name} table not found on #{t.sql_name} polymorphic import"
80
88
  end
81
89
  end
90
+ ActiveSupport::Notifications.instrument('mongify.copy_polymorphic_tables.inc')
82
91
  end
92
+ ActiveSupport::Notifications.instrument('mongify.copy_polymorphic_tables.finish')
83
93
  end
84
94
 
85
95
  # Updates the reference ids in the no sql database
86
96
  def update_reference_ids
97
+ ActiveSupport::Notifications.instrument('mongify.update_reference_ids.start', :size => self.tables.size)
87
98
  self.tables.each do |t|
88
99
  no_sql_connection.select_rows(t.name).each do |row|
89
100
  id = row["_id"]
90
101
  attributes = fetch_reference_ids(t, row)
91
102
  no_sql_connection.update(t.name, id, {"$set" => attributes}) unless attributes.blank?
92
103
  end
104
+ ActiveSupport::Notifications.instrument('mongify.update_reference_ids.inc')
93
105
  end
106
+ ActiveSupport::Notifications.instrument('mongify.update_reference_ids.finish')
94
107
  end
95
108
 
96
109
  # Fetches the new _id from a collection
@@ -105,7 +118,13 @@ module Mongify
105
118
 
106
119
  # Removes 'pre_mongiifed_id's from all collection
107
120
  def remove_pre_mongified_ids
108
- self.copy_tables.each { |t| no_sql_connection.remove_pre_mongified_ids(t.name) }
121
+ ActiveSupport::Notifications.instrument('mongify.remove_pre_mongified_ids.start', :size => self.tables.size)
122
+ p = ProgressBar.new("Removed pre_mongified_ids", self.copy_tables.count)
123
+ self.copy_tables.each do |t|
124
+ no_sql_connection.remove_pre_mongified_ids(t.name)
125
+ ActiveSupport::Notifications.instrument('mongify.remove_pre_mongified_ids.inc')
126
+ end
127
+ ActiveSupport::Notifications.instrument('mongify.remove_pre_mongified_ids.finish')
109
128
  end
110
129
 
111
130
  end
@@ -1,4 +1,4 @@
1
1
  module Mongify
2
2
  # Mongify's Current Version Number
3
- VERSION = "0.1.1"
3
+ VERSION = "0.1.2"
4
4
  end
@@ -13,12 +13,13 @@ Gem::Specification.new do |s|
13
13
 
14
14
  s.default_executable = "mongify"
15
15
 
16
- s.add_dependency('activerecord', ">= 2.3.10")
17
- s.add_dependency('activesupport', ">= 2.3.10")
16
+ s.add_dependency('activerecord', ">=3.0.3")
17
+ s.add_dependency('activesupport', ">=3.0.3")
18
18
  s.add_dependency('mysql2')
19
19
  s.add_dependency('mongo', ">= 1.1.5")
20
20
  s.add_dependency('bson_ext', ">= 1.1.5")
21
21
  s.add_dependency('net-ssh', ">= 2.0")
22
+ s.add_dependency('progressbar', ">= 0.9")
22
23
 
23
24
  s.add_development_dependency('rspec', '>= 2.0')
24
25
  s.add_development_dependency('rcov', '>= 0.9.9')
@@ -123,6 +123,43 @@ describe Mongify::Database::NoSqlConnection do
123
123
  end
124
124
  end
125
125
  end
126
+
127
+ context "force" do
128
+ before(:each) do
129
+ @mock_connection = mock(:connected? => true, :drop_database => true)
130
+ Mongo::Connection.stub(:new).and_return(@mock_connection)
131
+ @mongodb_connection = Mongify::Database::NoSqlConnection.new(:host => 'localhost', :database => 'blue', :force => true)
132
+ Mongify::UI.stub(:ask).and_return(true)
133
+ end
134
+ it "should be true" do
135
+ @mongodb_connection.should be_forced
136
+ end
137
+ it "should be false" do
138
+ Mongify::Database::NoSqlConnection.new(:host => 'localhost', :database => 'blue', :force => false).should_not be_forced
139
+ end
140
+
141
+ it "should drop database" do
142
+ @mongodb_connection.connection.should_receive(:drop_database).with('blue').and_return(true)
143
+ @mongodb_connection.send(:drop_database)
144
+ end
145
+
146
+ context "ask permission" do
147
+ it "should ask to drop database" do
148
+ Mongify::UI.should_receive(:ask).and_return(false)
149
+ @mongodb_connection.send(:ask_to_drop_database)
150
+ end
151
+ it "should not drop database if permission is declined" do
152
+ Mongify::UI.should_receive(:ask).and_return(false)
153
+ @mongodb_connection.should_receive(:drop_database).never
154
+ @mongodb_connection.send(:ask_to_drop_database)
155
+ end
156
+ it "should drop database if permission is granted" do
157
+ Mongify::UI.should_receive(:ask).and_return(true)
158
+ @mongodb_connection.should_receive(:drop_database).once
159
+ @mongodb_connection.send(:ask_to_drop_database)
160
+ end
161
+ end
162
+ end
126
163
 
127
164
 
128
165
  describe "working connection" do
@@ -41,6 +41,11 @@ describe Mongify::Translation::Process do
41
41
  end
42
42
  end
43
43
 
44
+ it "should ask_to_drop_database if mongodb_connection is forced" do
45
+ @no_sql_connection.should_receive(:forced?).and_return(true)
46
+ @no_sql_connection.should_receive(:ask_to_drop_database).and_return(false)
47
+ @translation.process(@sql_connection, @no_sql_connection)
48
+ end
44
49
 
45
50
 
46
51
  context "fetch_reference_ids" do
@@ -92,7 +97,7 @@ describe Mongify::Translation::Process do
92
97
  @translation.stub(:fetch_reference_ids).and_return({})
93
98
  end
94
99
  it "should loop through embedded tables" do
95
- @translation.should_receive(:embed_tables).and_return([@embed_table])
100
+ @translation.should_receive(:embed_tables).at_least(1).and_return([@embed_table])
96
101
  @no_sql_connection.should_receive(:find_one).and_return({'_id' => 500})
97
102
  @no_sql_connection.should_receive(:update)
98
103
  @translation.send(:copy_embedded_tables)
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongify
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 31
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 1
10
- version: 0.1.1
9
+ - 2
10
+ version: 0.1.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Andrew Kalek
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-01-28 00:00:00 -05:00
18
+ date: 2011-02-14 00:00:00 -05:00
19
19
  default_executable: mongify
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -26,12 +26,12 @@ dependencies:
26
26
  requirements:
27
27
  - - ">="
28
28
  - !ruby/object:Gem::Version
29
- hash: 23
29
+ hash: 1
30
30
  segments:
31
- - 2
32
31
  - 3
33
- - 10
34
- version: 2.3.10
32
+ - 0
33
+ - 3
34
+ version: 3.0.3
35
35
  type: :runtime
36
36
  version_requirements: *id001
37
37
  - !ruby/object:Gem::Dependency
@@ -42,12 +42,12 @@ dependencies:
42
42
  requirements:
43
43
  - - ">="
44
44
  - !ruby/object:Gem::Version
45
- hash: 23
45
+ hash: 1
46
46
  segments:
47
- - 2
48
47
  - 3
49
- - 10
50
- version: 2.3.10
48
+ - 0
49
+ - 3
50
+ version: 3.0.3
51
51
  type: :runtime
52
52
  version_requirements: *id002
53
53
  - !ruby/object:Gem::Dependency
@@ -112,9 +112,24 @@ dependencies:
112
112
  type: :runtime
113
113
  version_requirements: *id006
114
114
  - !ruby/object:Gem::Dependency
115
- name: rspec
115
+ name: progressbar
116
116
  prerelease: false
117
117
  requirement: &id007 !ruby/object:Gem::Requirement
118
+ none: false
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ hash: 25
123
+ segments:
124
+ - 0
125
+ - 9
126
+ version: "0.9"
127
+ type: :runtime
128
+ version_requirements: *id007
129
+ - !ruby/object:Gem::Dependency
130
+ name: rspec
131
+ prerelease: false
132
+ requirement: &id008 !ruby/object:Gem::Requirement
118
133
  none: false
119
134
  requirements:
120
135
  - - ">="
@@ -125,11 +140,11 @@ dependencies:
125
140
  - 0
126
141
  version: "2.0"
127
142
  type: :development
128
- version_requirements: *id007
143
+ version_requirements: *id008
129
144
  - !ruby/object:Gem::Dependency
130
145
  name: rcov
131
146
  prerelease: false
132
- requirement: &id008 !ruby/object:Gem::Requirement
147
+ requirement: &id009 !ruby/object:Gem::Requirement
133
148
  none: false
134
149
  requirements:
135
150
  - - ">="
@@ -141,11 +156,11 @@ dependencies:
141
156
  - 9
142
157
  version: 0.9.9
143
158
  type: :development
144
- version_requirements: *id008
159
+ version_requirements: *id009
145
160
  - !ruby/object:Gem::Dependency
146
161
  name: cucumber
147
162
  prerelease: false
148
- requirement: &id009 !ruby/object:Gem::Requirement
163
+ requirement: &id010 !ruby/object:Gem::Requirement
149
164
  none: false
150
165
  requirements:
151
166
  - - ">="
@@ -156,11 +171,11 @@ dependencies:
156
171
  - 10
157
172
  version: "0.10"
158
173
  type: :development
159
- version_requirements: *id009
174
+ version_requirements: *id010
160
175
  - !ruby/object:Gem::Dependency
161
176
  name: mocha
162
177
  prerelease: false
163
- requirement: &id010 !ruby/object:Gem::Requirement
178
+ requirement: &id011 !ruby/object:Gem::Requirement
164
179
  none: false
165
180
  requirements:
166
181
  - - ">="
@@ -172,11 +187,11 @@ dependencies:
172
187
  - 8
173
188
  version: 0.9.8
174
189
  type: :development
175
- version_requirements: *id010
190
+ version_requirements: *id011
176
191
  - !ruby/object:Gem::Dependency
177
192
  name: yard
178
193
  prerelease: false
179
- requirement: &id011 !ruby/object:Gem::Requirement
194
+ requirement: &id012 !ruby/object:Gem::Requirement
180
195
  none: false
181
196
  requirements:
182
197
  - - ">="
@@ -188,11 +203,11 @@ dependencies:
188
203
  - 3
189
204
  version: 0.5.3
190
205
  type: :development
191
- version_requirements: *id011
206
+ version_requirements: *id012
192
207
  - !ruby/object:Gem::Dependency
193
208
  name: watchr
194
209
  prerelease: false
195
- requirement: &id012 !ruby/object:Gem::Requirement
210
+ requirement: &id013 !ruby/object:Gem::Requirement
196
211
  none: false
197
212
  requirements:
198
213
  - - ">="
@@ -203,11 +218,11 @@ dependencies:
203
218
  - 6
204
219
  version: "0.6"
205
220
  type: :development
206
- version_requirements: *id012
221
+ version_requirements: *id013
207
222
  - !ruby/object:Gem::Dependency
208
223
  name: sqlite3-ruby
209
224
  prerelease: false
210
- requirement: &id013 !ruby/object:Gem::Requirement
225
+ requirement: &id014 !ruby/object:Gem::Requirement
211
226
  none: false
212
227
  requirements:
213
228
  - - ">="
@@ -218,11 +233,11 @@ dependencies:
218
233
  - 3
219
234
  version: "1.3"
220
235
  type: :development
221
- version_requirements: *id013
236
+ version_requirements: *id014
222
237
  - !ruby/object:Gem::Dependency
223
238
  name: mysql
224
239
  prerelease: false
225
- requirement: &id014 !ruby/object:Gem::Requirement
240
+ requirement: &id015 !ruby/object:Gem::Requirement
226
241
  none: false
227
242
  requirements:
228
243
  - - ">="
@@ -234,7 +249,7 @@ dependencies:
234
249
  - 1
235
250
  version: 2.8.1
236
251
  type: :development
237
- version_requirements: *id014
252
+ version_requirements: *id015
238
253
  description: Mongify allows you to map your sql data into a mongodb document database.
239
254
  email:
240
255
  - andrew.kalek@anlek.com
@@ -276,6 +291,7 @@ files:
276
291
  - lib/mongify/database/sql_connection.rb
277
292
  - lib/mongify/database/table.rb
278
293
  - lib/mongify/exceptions.rb
294
+ - lib/mongify/status.rb
279
295
  - lib/mongify/translation.rb
280
296
  - lib/mongify/translation/printer.rb
281
297
  - lib/mongify/translation/process.rb