mongify 0.0.9 → 0.1.0
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.
- data/CHANGELOG.rdoc +8 -0
- data/Gemfile.lock +1 -1
- data/README.rdoc +40 -16
- data/features/options.feature +3 -7
- data/features/print.feature +1 -1
- data/features/process.feature +0 -1
- data/features/support/env.rb +4 -1
- data/lib/mongify.rb +3 -1
- data/lib/mongify/cli.rb +0 -1
- data/lib/mongify/cli/application.rb +10 -1
- data/lib/mongify/cli/help_command.rb +1 -0
- data/lib/mongify/cli/options.rb +13 -14
- data/lib/mongify/cli/version_command.rb +1 -0
- data/lib/mongify/cli/worker_command.rb +15 -7
- data/lib/mongify/configuration.rb +14 -12
- data/lib/mongify/database.rb +2 -1
- data/lib/mongify/database/base_connection.rb +25 -15
- data/lib/mongify/database/column.rb +99 -21
- data/lib/mongify/database/data_row.rb +67 -0
- data/lib/mongify/database/no_sql_connection.rb +48 -10
- data/lib/mongify/database/sql_connection.rb +34 -4
- data/lib/mongify/database/table.rb +69 -7
- data/lib/mongify/exceptions.rb +7 -0
- data/lib/mongify/translation.rb +45 -2
- data/lib/mongify/translation/printer.rb +4 -3
- data/lib/mongify/translation/process.rb +11 -4
- data/lib/mongify/ui.rb +10 -1
- data/lib/mongify/version.rb +2 -1
- data/spec/mongify/cli/worker_command_spec.rb +3 -4
- data/spec/mongify/configuration_spec.rb +6 -12
- data/spec/mongify/database/base_connection_spec.rb +7 -3
- data/spec/mongify/database/column_spec.rb +171 -28
- data/spec/mongify/database/data_row_spec.rb +102 -0
- data/spec/mongify/database/no_sql_connection_spec.rb +4 -6
- data/spec/mongify/database/table_spec.rb +23 -2
- data/spec/mongify/translation/printer_spec.rb +3 -3
- data/spec/support/config_reader.rb +3 -1
- data/spec/support/generate_database.rb +7 -0
- metadata +7 -5
- data/lib/mongify/cli/report.rb +0 -11
data/CHANGELOG.rdoc
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
== 0.1.0 / 21 Jan 2011
|
2
|
+
* Moved from Alpha to Beta! :)
|
3
|
+
* Improved internal RDocs
|
4
|
+
* Improved specs
|
5
|
+
* Refactored
|
6
|
+
* Renamed 'translate' command to 'translation'
|
7
|
+
* Added :auto_detect option to columns
|
8
|
+
* Added ability to do a before_save on the table.
|
1
9
|
== 0.0.9 / 19 Jan 2011
|
2
10
|
* Added ability to rename tables
|
3
11
|
* Fixed bug 'pre_mogified_id' not being removed in all records
|
data/Gemfile.lock
CHANGED
data/README.rdoc
CHANGED
@@ -7,12 +7,10 @@ However, I've only tested it with MySql and SQLite
|
|
7
7
|
|
8
8
|
Supports any version of MongoDB
|
9
9
|
|
10
|
-
Learn more about
|
10
|
+
Learn more about MongoDB at: http://www.mongodb.org
|
11
11
|
|
12
12
|
== Install
|
13
13
|
|
14
|
-
<b>WARNING: This gem is still in alpha</b>
|
15
|
-
|
16
14
|
gem install mongify
|
17
15
|
|
18
16
|
== Usage
|
@@ -33,7 +31,7 @@ Building a config file is as simple as this:
|
|
33
31
|
|
34
32
|
mongodb_connection do
|
35
33
|
host "localhost"
|
36
|
-
database "
|
34
|
+
database "my_database"
|
37
35
|
end
|
38
36
|
|
39
37
|
You can check your configuration by running
|
@@ -46,9 +44,9 @@ You can check your configuration by running
|
|
46
44
|
|
47
45
|
==== Generating a translation
|
48
46
|
If you're database is large and complex, it might be a bit too much to hand write the translation file, Mongify can help by running the translate command:
|
49
|
-
mongify
|
47
|
+
mongify translation -c database.config
|
50
48
|
Or pipe it right into a file by running
|
51
|
-
mongify
|
49
|
+
mongify translation -c database.config > translation_file.rb
|
52
50
|
|
53
51
|
==== Creating a translation
|
54
52
|
Creating a translation is pretty straight forward. It looks something like this:
|
@@ -89,6 +87,27 @@ Creating a translation is pretty straight forward. It looks something like this:
|
|
89
87
|
Save the file as <tt>"translation_file.rb"</tt> and run the command:
|
90
88
|
|
91
89
|
mongify process translation_file.rb -c database.config
|
90
|
+
|
91
|
+
=== Commands
|
92
|
+
|
93
|
+
Usage: mongify command [database_translation.rb] [-c database.config]
|
94
|
+
|
95
|
+
Commands:
|
96
|
+
"check" or "ck" >> Checks connection for sql and no_sql databases [configuration_file]
|
97
|
+
"process" or "pr" >> Takes a translation and process it to mongodb [configuration_file, translation_file]
|
98
|
+
"translation" or "tr" >> Outputs a translation file from a sql connection [configuration_file]
|
99
|
+
|
100
|
+
Examples:
|
101
|
+
|
102
|
+
mongify translation -c datbase.config
|
103
|
+
mongify tr -c database.config
|
104
|
+
mongify check -c database.config
|
105
|
+
mongify process database_translation.rb -c database.config
|
106
|
+
|
107
|
+
Common options:
|
108
|
+
-h, --help Show this message
|
109
|
+
-v, --version Show version
|
110
|
+
-c, --config FILE Configuration File to use
|
92
111
|
|
93
112
|
== Translation Layout and Options
|
94
113
|
|
@@ -115,12 +134,20 @@ Table Options are as follow:
|
|
115
134
|
# This also assumes you have a user_id present in table_name
|
116
135
|
<em>You can also specify both <b>:on</b> and <b>:as</b> options when embedding</em>
|
117
136
|
|
137
|
+
<b>NOTE: If you rename the owner_id column, make sure you update the :on to the new column name</b>
|
138
|
+
|
118
139
|
table "table_name", :rename_to => 'my_table' # This will allow you to rename the table as it's getting process
|
119
140
|
# Just remember that columns that use :reference need to
|
120
141
|
# reference the new name.
|
121
142
|
|
122
143
|
table "table_name", :ignore => true # This will ignore the whole table (like it doesn't exist)
|
123
144
|
# This option is good for tables like: schema_migrations
|
145
|
+
|
146
|
+
table "table_name" do # A table can take a before_save block that will be called just
|
147
|
+
before_save do |row| # before the row is saved to the no sql database.
|
148
|
+
row.admin = row.delete('permission').to_i > 50 # This gives you the ability to do very powerful things like:
|
149
|
+
end # Moving records around, renaming records, changing values in row based on
|
150
|
+
end # some values! Checkout {Mongify::Database::DataRow} to learn more
|
124
151
|
|
125
152
|
=== Columns
|
126
153
|
|
@@ -142,9 +169,13 @@ Before we cover the options, you need to know what types of columns are supporte
|
|
142
169
|
:decimal # Will be converted to a BigDecimal
|
143
170
|
:string # Will be converted to a string
|
144
171
|
:text # Will be converted to a string
|
145
|
-
:datetime #
|
172
|
+
:datetime # Will be converted to a Time format (DateTime is not currently supported in the Mongo ruby driver)
|
173
|
+
:date # Will be converted to a Time format (Date is not currently supported in the Mongo ruby driver)
|
174
|
+
:timestamps # Will be converted to a Time format
|
175
|
+
:time # Will be converted to a Time format (the date portion of the Time object will be 2000-01-01)
|
146
176
|
:binary # Will be converted to a string
|
147
|
-
|
177
|
+
:boolean # Will be converted to a true or false values
|
178
|
+
|
148
179
|
==== Options
|
149
180
|
|
150
181
|
column "post_id", :integer, :referneces => :posts # Referenced columns need to be marked as such, this will mean that they will be updated
|
@@ -155,9 +186,6 @@ Before we cover the options, you need to know what types of columns are supporte
|
|
155
186
|
|
156
187
|
column "surname", :string, :rename_to => 'last_name'# Rename_to allows you to rename the column
|
157
188
|
|
158
|
-
<em>**this is subject to change during the alpha (0.0.x release)**</em>
|
159
|
-
|
160
|
-
|
161
189
|
== Notes
|
162
190
|
|
163
191
|
I have currently only tested this in Ruby 1.8.7-p330
|
@@ -168,13 +196,9 @@ More testing will be done once the basic functionality is done
|
|
168
196
|
== TODO
|
169
197
|
|
170
198
|
* Allow you to set a :force => true for mongodb_connection, so that it drops existing database before importing
|
171
|
-
|
172
|
-
=== while processing
|
173
|
-
|
174
199
|
* Work with polymorphic tables
|
175
|
-
* Allow running a proc on column value
|
176
200
|
* Update user on what is being processed
|
177
|
-
|
201
|
+
* Improve RDoc
|
178
202
|
|
179
203
|
== Development
|
180
204
|
|
data/features/options.feature
CHANGED
@@ -24,13 +24,12 @@ 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
|
-
"
|
27
|
+
"translation" or "tr" >> Outputs a translation file from a sql connection [configuration_file]
|
28
28
|
|
29
29
|
Examples:
|
30
30
|
|
31
|
-
mongify
|
32
|
-
|
33
|
-
mongify check -c database.config
|
31
|
+
mongify check -c database.config
|
32
|
+
mongify translation -c datbase.config > database_translation.rb
|
34
33
|
mongify process database_translation.rb -c database.config
|
35
34
|
|
36
35
|
See http://github.com/anlek/mongify for more details
|
@@ -40,7 +39,4 @@ Feature: Mongify can be controlled using command-line options
|
|
40
39
|
-v, --version Show version
|
41
40
|
-c, --config FILE Configuration File to use
|
42
41
|
|
43
|
-
Report formatting:
|
44
|
-
-q, --[no-]quiet Suppress extra output
|
45
|
-
|
46
42
|
"""
|
data/features/print.feature
CHANGED
@@ -5,6 +5,6 @@ Feature: Database Translation Output
|
|
5
5
|
|
6
6
|
Scenario: Translation Output request
|
7
7
|
Given a database exists
|
8
|
-
When I run mongify
|
8
|
+
When I run mongify translation -c spec/files/base_configuration.rb
|
9
9
|
Then it succeeds
|
10
10
|
And it should print out the database schema
|
data/features/process.feature
CHANGED
data/features/support/env.rb
CHANGED
@@ -11,7 +11,9 @@ require 'spec/support/config_reader'
|
|
11
11
|
::CONNECTION_CONFIG = ConfigReader.new(File.dirname(File.dirname(File.dirname(File.expand_path(__FILE__)))) + '/spec/support/database.yml')
|
12
12
|
::DATABASE_PRINT = File.read(File.dirname(File.dirname(File.dirname(File.expand_path(__FILE__)))) + '/spec/support/database_output.txt')
|
13
13
|
|
14
|
+
# Used to run mongify command
|
14
15
|
module MongifyWorld
|
16
|
+
# Executes command and tracks results
|
15
17
|
def run(cmd)
|
16
18
|
stderr_file = Tempfile.new('mongify-world')
|
17
19
|
stderr_file.close
|
@@ -19,7 +21,8 @@ module MongifyWorld
|
|
19
21
|
@last_exit_status = $?.exitstatus
|
20
22
|
@last_stderr = IO.read(stderr_file.path)
|
21
23
|
end
|
22
|
-
|
24
|
+
|
25
|
+
# Executes mongify command with arguments
|
23
26
|
def mongify(args)
|
24
27
|
run("ruby -Ilib -rubygems bin/mongify #{args}")
|
25
28
|
end
|
data/lib/mongify.rb
CHANGED
@@ -10,11 +10,13 @@ require 'mongify/translation'
|
|
10
10
|
require 'mongify/configuration'
|
11
11
|
require 'mongify/database'
|
12
12
|
|
13
|
-
module Mongify
|
13
|
+
module Mongify # Namespace for Mongify
|
14
14
|
class << self
|
15
|
+
# Handles setting root for the application
|
15
16
|
def root=(value)
|
16
17
|
@root = value
|
17
18
|
end
|
19
|
+
#Raises RootMissing if you attempt to call root without setting it
|
18
20
|
def root
|
19
21
|
raise RootMissing, "Root not configured" if @root.nil?
|
20
22
|
@root
|
data/lib/mongify/cli.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
module Mongify
|
2
|
+
# The Command Line Interface module
|
2
3
|
module CLI
|
3
4
|
#
|
4
5
|
# Represents an instance of a Mongify application.
|
@@ -7,16 +8,20 @@ module Mongify
|
|
7
8
|
#
|
8
9
|
class Application
|
9
10
|
|
11
|
+
# Successful execution exit code
|
10
12
|
STATUS_SUCCESS = 0
|
13
|
+
# Failed execution exit code
|
11
14
|
STATUS_ERROR = 1
|
12
15
|
|
13
|
-
def initialize(arguments=[
|
16
|
+
def initialize(arguments=[], stdin=$stdin, stdout=$stdout)
|
17
|
+
arguments = ['-h'] if arguments.empty?
|
14
18
|
@options = Options.new(arguments)
|
15
19
|
@status = STATUS_SUCCESS
|
16
20
|
Mongify::Configuration.in_stream = stdin
|
17
21
|
Mongify::Configuration.out_stream = stdout
|
18
22
|
end
|
19
23
|
|
24
|
+
# Runs the application
|
20
25
|
def execute!
|
21
26
|
begin
|
22
27
|
cmd = @options.parse
|
@@ -28,13 +33,17 @@ module Mongify
|
|
28
33
|
return @status
|
29
34
|
end
|
30
35
|
|
36
|
+
# Sends output to the UI
|
31
37
|
def output(message)
|
32
38
|
UI.puts(message)
|
33
39
|
end
|
34
40
|
|
41
|
+
# Sets status code as successful
|
35
42
|
def report_success
|
36
43
|
@status = STATUS_SUCCESS
|
37
44
|
end
|
45
|
+
|
46
|
+
# Sets status code as failure (or error)
|
38
47
|
def report_error
|
39
48
|
@status = STATUS_ERROR
|
40
49
|
end
|
data/lib/mongify/cli/options.rb
CHANGED
@@ -9,12 +9,12 @@ module Mongify
|
|
9
9
|
@parsed = false
|
10
10
|
@argv = argv
|
11
11
|
@parser = OptionParser.new
|
12
|
-
@report_class = VerboseReport
|
13
12
|
#@command_class = ReekCommand
|
14
13
|
set_options
|
15
14
|
|
16
15
|
end
|
17
16
|
|
17
|
+
# Banner for help output
|
18
18
|
def banner
|
19
19
|
progname = @parser.program_name
|
20
20
|
return <<EOB
|
@@ -25,9 +25,8 @@ Commands:
|
|
25
25
|
|
26
26
|
Examples:
|
27
27
|
|
28
|
-
#{progname} translate -c datbase.config
|
29
|
-
#{progname} tr -c database.config
|
30
28
|
#{progname} check -c database.config
|
29
|
+
#{progname} translation -c datbase.config > database_translation.rb
|
31
30
|
#{progname} process database_translation.rb -c database.config
|
32
31
|
|
33
32
|
See http://github.com/anlek/mongify for more details
|
@@ -35,7 +34,8 @@ See http://github.com/anlek/mongify for more details
|
|
35
34
|
EOB
|
36
35
|
end
|
37
36
|
|
38
|
-
|
37
|
+
# Sets the options for CLI
|
38
|
+
# Also used for help output
|
39
39
|
def set_options
|
40
40
|
@parser.banner = banner
|
41
41
|
@parser.separator "Common options:"
|
@@ -48,13 +48,9 @@ EOB
|
|
48
48
|
@parser.on('-c', '--config FILE', "Configuration File to use") do |file|
|
49
49
|
@config_file = file
|
50
50
|
end
|
51
|
-
|
52
|
-
@parser.separator "\nReport formatting:"
|
53
|
-
@parser.on("-q", "--[no-]quiet", "Suppress extra output") do |opt|
|
54
|
-
@report_class = opt ? QuietReport : VerboseReport
|
55
|
-
end
|
56
51
|
end
|
57
|
-
|
52
|
+
|
53
|
+
# Parses CLI passed attributes and figures out what command user is trying to run
|
58
54
|
def parse
|
59
55
|
parse_options
|
60
56
|
|
@@ -71,24 +67,27 @@ EOB
|
|
71
67
|
end
|
72
68
|
end
|
73
69
|
|
70
|
+
#######
|
74
71
|
private
|
72
|
+
#######
|
75
73
|
|
74
|
+
# Returns the translation_file or nil
|
76
75
|
def translation_file(argv=@argv)
|
77
76
|
parse_options
|
78
77
|
return nil if argv.length < 2
|
79
78
|
argv[1]
|
80
79
|
end
|
81
80
|
|
81
|
+
# Returns action (command) user is calling or ''
|
82
82
|
def action(argv=@argv)
|
83
83
|
parse_options
|
84
84
|
@argv.try(:[],0) || ''
|
85
85
|
end
|
86
|
-
|
86
|
+
|
87
|
+
# option parser, ensuring parse_options is only called once
|
87
88
|
def parse_options
|
88
89
|
@parsed = true && @parser.parse!(@argv) unless @parsed
|
89
|
-
end
|
90
|
-
|
91
|
-
|
90
|
+
end
|
92
91
|
end
|
93
92
|
end
|
94
93
|
end
|
@@ -7,11 +7,15 @@ module Mongify
|
|
7
7
|
class WorkerCommand
|
8
8
|
attr_accessor :view
|
9
9
|
|
10
|
+
# A hash of available commands
|
11
|
+
# Including description, additional shortcuts to run the commands and requirements to run the command
|
10
12
|
AVAILABLE_COMMANDS = {
|
11
13
|
:check => {:commands => ['check', 'ck'], :description => "Checks connection for sql and no_sql databases", :required => [:configuration_file]},
|
12
|
-
:
|
14
|
+
:translation => {:commands => ['translation', 'tr'], :description => "Outputs a translation file from a sql connection", :required => [:configuration_file]},
|
13
15
|
:process => {:commands => ['process', 'pr'], :description => "Takes a translation and process it to mongodb", :required => [:configuration_file, :translation_file]}
|
14
16
|
}
|
17
|
+
|
18
|
+
# Prints out a nice display of the list of commands
|
15
19
|
def self.list_commands
|
16
20
|
[].tap do |commands|
|
17
21
|
AVAILABLE_COMMANDS.each do |key, obj|
|
@@ -19,7 +23,8 @@ module Mongify
|
|
19
23
|
end
|
20
24
|
end.sort
|
21
25
|
end
|
22
|
-
|
26
|
+
|
27
|
+
# Finds a command array by any of the shortcut commands
|
23
28
|
def self.find_command(command)
|
24
29
|
AVAILABLE_COMMANDS.each do |key, options|
|
25
30
|
return [key, options] if(options[:commands].include?(command.to_s.downcase))
|
@@ -34,6 +39,7 @@ module Mongify
|
|
34
39
|
@parser = parser
|
35
40
|
end
|
36
41
|
|
42
|
+
#Executes the worked based on a given command
|
37
43
|
def execute(view)
|
38
44
|
self.view = view
|
39
45
|
|
@@ -50,7 +56,7 @@ module Mongify
|
|
50
56
|
end
|
51
57
|
|
52
58
|
case current_command
|
53
|
-
when :
|
59
|
+
when :translation
|
54
60
|
check_connections
|
55
61
|
view.output(Mongify::Translation.load(@config.sql_connection).print)
|
56
62
|
when :check
|
@@ -67,6 +73,7 @@ module Mongify
|
|
67
73
|
view.report_success
|
68
74
|
end
|
69
75
|
|
76
|
+
# Passes find command to parent class
|
70
77
|
def find_command(command=@command)
|
71
78
|
self.class.find_command(command)
|
72
79
|
end
|
@@ -75,19 +82,20 @@ module Mongify
|
|
75
82
|
private
|
76
83
|
#######
|
77
84
|
|
78
|
-
|
79
|
-
|
85
|
+
# Checks both sql and no sql connection
|
86
|
+
def check_connections
|
87
|
+
check_sql_connection && check_nosql_connection
|
80
88
|
end
|
81
89
|
|
90
|
+
# Checks sql connection if it's valid and has_connection?
|
82
91
|
def check_sql_connection
|
83
92
|
@config.sql_connection.valid? && @config.sql_connection.has_connection?
|
84
93
|
end
|
85
94
|
|
95
|
+
# Checks no sql connection if it's valid and has_connection?
|
86
96
|
def check_nosql_connection
|
87
97
|
@config.no_sql_connection.valid? && @config.no_sql_connection.has_connection?
|
88
98
|
end
|
89
|
-
|
90
|
-
|
91
99
|
end
|
92
100
|
end
|
93
101
|
end
|