mongify 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +20 -0
- data/CHANGELOG.rdoc +22 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +68 -0
- data/LICENSE +20 -0
- data/README.rdoc +86 -0
- data/Rakefile +73 -0
- data/bin/mongify +14 -0
- data/features/options.feature +46 -0
- data/features/print.feature +10 -0
- data/features/process.feature +19 -0
- data/features/step_definitions/mongify_steps.rb +42 -0
- data/features/step_definitions/mongo_steps.rb +7 -0
- data/features/support/env.rb +28 -0
- data/lib/mongify.rb +22 -0
- data/lib/mongify/cli.rb +8 -0
- data/lib/mongify/cli/application.rb +43 -0
- data/lib/mongify/cli/help_command.rb +16 -0
- data/lib/mongify/cli/options.rb +94 -0
- data/lib/mongify/cli/report.rb +11 -0
- data/lib/mongify/cli/version_command.rb +18 -0
- data/lib/mongify/cli/worker_command.rb +93 -0
- data/lib/mongify/configuration.rb +46 -0
- data/lib/mongify/database.rb +5 -0
- data/lib/mongify/database/base_connection.rb +78 -0
- data/lib/mongify/database/column.rb +81 -0
- data/lib/mongify/database/no_sql_connection.rb +62 -0
- data/lib/mongify/database/sql_connection.rb +61 -0
- data/lib/mongify/database/table.rb +74 -0
- data/lib/mongify/exceptions.rb +13 -0
- data/lib/mongify/translation.rb +55 -0
- data/lib/mongify/translation/printer.rb +20 -0
- data/lib/mongify/translation/process.rb +61 -0
- data/lib/mongify/ui.rb +45 -0
- data/lib/mongify/version.rb +3 -0
- data/mongify.gemspec +42 -0
- data/spec/default.watch +199 -0
- data/spec/files/base_configuration.rb +9 -0
- data/spec/files/empty_translation.rb +0 -0
- data/spec/files/simple_translation.rb +26 -0
- data/spec/mongify/cli/application_spec.rb +19 -0
- data/spec/mongify/cli/help_command_spec.rb +18 -0
- data/spec/mongify/cli/options_spec.rb +62 -0
- data/spec/mongify/cli/version_command_spec.rb +24 -0
- data/spec/mongify/cli/worker_command_spec.rb +115 -0
- data/spec/mongify/configuration_spec.rb +25 -0
- data/spec/mongify/database/base_connection_spec.rb +59 -0
- data/spec/mongify/database/column_spec.rb +103 -0
- data/spec/mongify/database/no_sql_connection_spec.rb +131 -0
- data/spec/mongify/database/sql_connection_spec.rb +91 -0
- data/spec/mongify/database/table_spec.rb +120 -0
- data/spec/mongify/translation/printer_spec.rb +34 -0
- data/spec/mongify/translation/process_spec.rb +68 -0
- data/spec/mongify/translation_spec.rb +59 -0
- data/spec/mongify/ui_spec.rb +73 -0
- data/spec/mongify_spec.rb +15 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +22 -0
- data/spec/support/config_reader.rb +21 -0
- data/spec/support/database.example +17 -0
- data/spec/support/database_output.txt +27 -0
- data/spec/support/generate_database.rb +91 -0
- metadata +370 -0
data/.gitignore
ADDED
data/CHANGELOG.rdoc
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
== 0.0.4 / 15 Jan 2011
|
2
|
+
* Switched the way connection files are written out.
|
3
|
+
* Fixed issue with Configuration File reader
|
4
|
+
* Added a Rake task to setup a mysql database for testing (for development only)
|
5
|
+
* Added a way to create a translation file from a sql configuration
|
6
|
+
* Added a printer ability for translation and command
|
7
|
+
* Added MongoDB connection
|
8
|
+
* Improved test coverage
|
9
|
+
* Added the first version of processing command (very basic)
|
10
|
+
* Indexed columns in table class to speedup lookup time
|
11
|
+
* Added ability to update references once database is populated
|
12
|
+
== 0.0.3 / 28 Dec 2010
|
13
|
+
* Switched gemspec generation to raw gemspec and added Bundler for easier development
|
14
|
+
* Added LICENSE
|
15
|
+
* Cleaned up the require statements through out the app
|
16
|
+
== 0.0.2 / 09 Jun 2010
|
17
|
+
* Rewrote the whole CLI interface
|
18
|
+
* Removed datamapper and added active_record
|
19
|
+
* Improved tests to cover most of the code
|
20
|
+
* Changed overall commands for Mongify
|
21
|
+
== 0.0.1 / 22 Mar 2010
|
22
|
+
* Initial Setup
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
mongify (0.0.4)
|
5
|
+
activerecord (>= 2.3.10)
|
6
|
+
activesupport (>= 2.3.10)
|
7
|
+
bson_ext (>= 1.1.5)
|
8
|
+
mongo (>= 1.1.5)
|
9
|
+
net-ssh (>= 2.0)
|
10
|
+
|
11
|
+
GEM
|
12
|
+
remote: http://rubygems.org/
|
13
|
+
specs:
|
14
|
+
activerecord (2.3.10)
|
15
|
+
activesupport (= 2.3.10)
|
16
|
+
activesupport (2.3.10)
|
17
|
+
bson (1.1.5)
|
18
|
+
bson_ext (1.1.5)
|
19
|
+
builder (3.0.0)
|
20
|
+
cucumber (0.10.0)
|
21
|
+
builder (>= 2.1.2)
|
22
|
+
diff-lcs (~> 1.1.2)
|
23
|
+
gherkin (~> 2.3.2)
|
24
|
+
json (~> 1.4.6)
|
25
|
+
term-ansicolor (~> 1.0.5)
|
26
|
+
diff-lcs (1.1.2)
|
27
|
+
gherkin (2.3.3)
|
28
|
+
json (~> 1.4.6)
|
29
|
+
json (1.4.6)
|
30
|
+
mocha (0.9.10)
|
31
|
+
rake
|
32
|
+
mongo (1.1.5)
|
33
|
+
bson (>= 1.1.5)
|
34
|
+
mysql (2.8.1)
|
35
|
+
net-ssh (2.0.24)
|
36
|
+
rake (0.8.7)
|
37
|
+
rcov (0.9.9)
|
38
|
+
rspec (2.4.0)
|
39
|
+
rspec-core (~> 2.4.0)
|
40
|
+
rspec-expectations (~> 2.4.0)
|
41
|
+
rspec-mocks (~> 2.4.0)
|
42
|
+
rspec-core (2.4.0)
|
43
|
+
rspec-expectations (2.4.0)
|
44
|
+
diff-lcs (~> 1.1.2)
|
45
|
+
rspec-mocks (2.4.0)
|
46
|
+
sqlite3-ruby (1.3.2)
|
47
|
+
term-ansicolor (1.0.5)
|
48
|
+
watchr (0.7)
|
49
|
+
yard (0.6.4)
|
50
|
+
|
51
|
+
PLATFORMS
|
52
|
+
ruby
|
53
|
+
|
54
|
+
DEPENDENCIES
|
55
|
+
activerecord (>= 2.3.10)
|
56
|
+
activesupport (>= 2.3.10)
|
57
|
+
bson_ext (>= 1.1.5)
|
58
|
+
cucumber (>= 0.10)
|
59
|
+
mocha (>= 0.9.8)
|
60
|
+
mongify!
|
61
|
+
mongo (>= 1.1.5)
|
62
|
+
mysql (>= 2.8.1)
|
63
|
+
net-ssh (>= 2.0)
|
64
|
+
rcov (>= 0.9.9)
|
65
|
+
rspec (>= 2.0)
|
66
|
+
sqlite3-ruby (>= 1.3)
|
67
|
+
watchr (>= 0.6)
|
68
|
+
yard (>= 0.5.3)
|
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Andrew Kalek, Anlek Consulting
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
= Mongify
|
2
|
+
|
3
|
+
A data translator from sql database to mongoDB.
|
4
|
+
|
5
|
+
Learn more about mongoDB at: http://www.mongodb.org
|
6
|
+
|
7
|
+
== Install
|
8
|
+
|
9
|
+
=== WARNING: This gem is still in very very early alpha
|
10
|
+
|
11
|
+
gem install mongify
|
12
|
+
|
13
|
+
== Usage
|
14
|
+
|
15
|
+
=== WARNING: Mongify is still a work in progress, so much so, that the code below will currently _NOT_ work and is likely to significantly change!
|
16
|
+
|
17
|
+
Build a config file such as:
|
18
|
+
|
19
|
+
sql_connection do
|
20
|
+
adaptor "mysql"
|
21
|
+
host "localhost"
|
22
|
+
database "my_database"
|
23
|
+
end
|
24
|
+
|
25
|
+
mongodb_connection do
|
26
|
+
host 'localhost'
|
27
|
+
database 'my_collection'
|
28
|
+
end
|
29
|
+
|
30
|
+
Build a translation file such as:
|
31
|
+
|
32
|
+
table "accounts"
|
33
|
+
|
34
|
+
table "users"
|
35
|
+
|
36
|
+
table "user_accounts", :embed_in => :users, :on => :user_id do |t|
|
37
|
+
t.column "account_id", :references => :account
|
38
|
+
end
|
39
|
+
|
40
|
+
Save the file as <tt>"my_database_translation.rb"</tt> and run the command:
|
41
|
+
|
42
|
+
mongify check -c datbase.config
|
43
|
+
mongify process database_translation.rb -c database.config
|
44
|
+
|
45
|
+
**this is subject to change at any time**
|
46
|
+
|
47
|
+
== Development
|
48
|
+
=== Requirements
|
49
|
+
You just need bundler 1.0
|
50
|
+
|
51
|
+
gem install bundler
|
52
|
+
bundle install
|
53
|
+
copy over spec/support/database.example to spec/support/database.yml and fill in required info
|
54
|
+
rake test:mysql:setup
|
55
|
+
|
56
|
+
=== Setup
|
57
|
+
Before you can run the specs, you need to make sure to setup the spec/support/database.yml file with your database info
|
58
|
+
(you can copy database.example within the same folder).
|
59
|
+
|
60
|
+
== Special Thanks
|
61
|
+
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.
|
62
|
+
=== More Special Thanks
|
63
|
+
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.
|
64
|
+
|
65
|
+
== License
|
66
|
+
|
67
|
+
Copyright (c) 2011 Andrew Kalek, Anlek Consulting
|
68
|
+
|
69
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
70
|
+
a copy of this software and associated documentation files (the
|
71
|
+
"Software"), to deal in the Software without restriction, including
|
72
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
73
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
74
|
+
permit persons to whom the Software is furnished to do so, subject to
|
75
|
+
the following conditions:
|
76
|
+
|
77
|
+
The above copyright notice and this permission notice shall be
|
78
|
+
included in all copies or substantial portions of the Software.
|
79
|
+
|
80
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
81
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
82
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
83
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
84
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
85
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
86
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'bundler'
|
2
|
+
Bundler::GemHelper.install_tasks
|
3
|
+
|
4
|
+
require 'cucumber/rake/task'
|
5
|
+
require 'rspec/core/rake_task'
|
6
|
+
|
7
|
+
|
8
|
+
task :cleanup_rcov_files do
|
9
|
+
rm_rf 'coverage.data'
|
10
|
+
end
|
11
|
+
|
12
|
+
desc 'clobber generated files'
|
13
|
+
task :clobber do
|
14
|
+
rm_rf "pkg"
|
15
|
+
rm_rf "tmp"
|
16
|
+
rm "Gemfile.lock" if File.exist?("Gemfile.lock")
|
17
|
+
end
|
18
|
+
|
19
|
+
namespace :rcov do
|
20
|
+
Cucumber::Rake::Task.new(:cucumber) do |t|
|
21
|
+
t.rcov = true
|
22
|
+
t.rcov_opts = %w{--exclude osx\/objc,gems\/,spec\/,features\/ --aggregate coverage.data}
|
23
|
+
t.rcov_opts << %[-o "coverage"]
|
24
|
+
end
|
25
|
+
|
26
|
+
RSpec::Core::RakeTask.new(:rspec) do |t|
|
27
|
+
t.rcov = true
|
28
|
+
t.rcov_opts = %w{--exclude osx\/objc,gems\/,spec\/,features\/}
|
29
|
+
end
|
30
|
+
|
31
|
+
desc "Run both specs and features to generate aggregated coverage"
|
32
|
+
task :all do |t|
|
33
|
+
rm "coverage.data" if File.exist?("coverage.data")
|
34
|
+
Rake::Task["rcov:cucumber"].invoke
|
35
|
+
Rake::Task["rcov:rspec"].invoke
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
namespace :test do
|
40
|
+
namespace :mysql do
|
41
|
+
desc "Setup a mysql database based on the spec/support/database.yml settings"
|
42
|
+
task :setup do
|
43
|
+
require 'spec/support/config_reader'
|
44
|
+
require 'active_record'
|
45
|
+
::CONNECTION_CONFIG = ConfigReader.new('spec/support/database.yml')
|
46
|
+
ActiveRecord::Base.establish_connection(CONNECTION_CONFIG.mysql)
|
47
|
+
conn = ActiveRecord::Base.connection
|
48
|
+
conn.create_table(:users, :force => true) do |t|
|
49
|
+
t.string :first_name, :last_name
|
50
|
+
t.timestamps
|
51
|
+
end
|
52
|
+
|
53
|
+
conn.create_table(:posts, :force => true) do |t|
|
54
|
+
t.string :title
|
55
|
+
t.integer :owner_id
|
56
|
+
t.text :body
|
57
|
+
t.datetime :published_at
|
58
|
+
t.timestamps
|
59
|
+
end
|
60
|
+
|
61
|
+
conn.create_table(:comments, :force => true) do |t|
|
62
|
+
t.text :body
|
63
|
+
t.integer :post_id
|
64
|
+
t.integer :user_id
|
65
|
+
t.timestamps
|
66
|
+
end
|
67
|
+
puts "Finished"
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
|
73
|
+
task :default => ['rcov:all']
|
data/bin/mongify
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# Mongify converts a sql database to a no_sql_database (by default to mongodb)
|
4
|
+
# Visit http://github.com/anlek/mongify for more information.
|
5
|
+
#
|
6
|
+
# Author: Andrew Kalek
|
7
|
+
#
|
8
|
+
|
9
|
+
$:.unshift File.join(File.dirname(File.dirname(File.expand_path(__FILE__))), 'lib')
|
10
|
+
require 'mongify/cli'
|
11
|
+
|
12
|
+
Mongify.root = Dir.pwd
|
13
|
+
|
14
|
+
exit Mongify::CLI::Application.new(ARGV).execute!
|
@@ -0,0 +1,46 @@
|
|
1
|
+
Feature: Mongify can be controlled using command-line options
|
2
|
+
In order to change Mongify's default behaviour
|
3
|
+
As a user
|
4
|
+
I want to supply options on the command line
|
5
|
+
|
6
|
+
Scenario: returns non-zero status on bad options
|
7
|
+
When I run mongify --no-such-option
|
8
|
+
Then the exit status indicates an error
|
9
|
+
And it reports the error "Error: invalid option: --no-such-option"
|
10
|
+
And stdout equals ""
|
11
|
+
|
12
|
+
Scenario: display the current version number
|
13
|
+
When I run mongify --version
|
14
|
+
Then it succeeds
|
15
|
+
And it reports the current version
|
16
|
+
|
17
|
+
Scenario: display the help information
|
18
|
+
When I run mongify --help
|
19
|
+
Then it succeeds
|
20
|
+
And it reports:
|
21
|
+
"""
|
22
|
+
Usage: mongify command [database_translation.rb] [-c database.config]
|
23
|
+
|
24
|
+
Commands:
|
25
|
+
"check" or "ck" >> Checks connection for sql and no_sql databases [configuration_file]
|
26
|
+
"process" or "pr" >> Takes a translation and process it to mongodb [configuration_file, translation_file]
|
27
|
+
"translate" or "tr" >> Spits out translation from a sql connection [configuration_file]
|
28
|
+
|
29
|
+
Examples:
|
30
|
+
|
31
|
+
mongify translate -c datbase.config
|
32
|
+
mongify tr -c database.config
|
33
|
+
mongify check -c database.config
|
34
|
+
mongify process database_translation.rb -c database.config
|
35
|
+
|
36
|
+
See http://github.com/anlek/mongify for more details
|
37
|
+
|
38
|
+
Common options:
|
39
|
+
-h, --help Show this message
|
40
|
+
-v, --version Show version
|
41
|
+
-c, --config FILE Configuration File to use
|
42
|
+
|
43
|
+
Report formatting:
|
44
|
+
-q, --[no-]quiet Suppress extra output
|
45
|
+
|
46
|
+
"""
|
@@ -0,0 +1,10 @@
|
|
1
|
+
Feature: Database Translation Output
|
2
|
+
In order to translate sql database to a no-sql database
|
3
|
+
As a developer / database admin
|
4
|
+
Needs to be able to generate a translation file
|
5
|
+
|
6
|
+
Scenario: Translation Output request
|
7
|
+
Given a database exists
|
8
|
+
When I run mongify translate -c spec/files/base_configuration.rb
|
9
|
+
Then it succeeds
|
10
|
+
And it should print out the database schema
|
@@ -0,0 +1,19 @@
|
|
1
|
+
Feature: Processing a translation
|
2
|
+
In order for Mongify to be useful
|
3
|
+
As a user
|
4
|
+
I want to be able to process a translation and move my data to mongodb!
|
5
|
+
|
6
|
+
@wip
|
7
|
+
Scenario: Process
|
8
|
+
Given a database exists
|
9
|
+
And a blank mongodb
|
10
|
+
When I run mongify process spec/files/simple_translation.rb -c spec/files/base_configuration.rb
|
11
|
+
Then it succeeds
|
12
|
+
And there should be 3 users in mongodb
|
13
|
+
And there should be 3 posts in mongodb
|
14
|
+
And there should be 3 comments in mongodb
|
15
|
+
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
|
@@ -0,0 +1,42 @@
|
|
1
|
+
When /^I run mongify (.*)$/ do |args|
|
2
|
+
mongify(args)
|
3
|
+
end
|
4
|
+
|
5
|
+
Then /^stdout equals "([^\"]*)"$/ do |report|
|
6
|
+
@last_stdout.should == report
|
7
|
+
end
|
8
|
+
|
9
|
+
Then /^it reports:$/ do |report|
|
10
|
+
@last_stdout.should == report
|
11
|
+
end
|
12
|
+
|
13
|
+
Then /^stderr reports:$/ do |report|
|
14
|
+
@last_stderr.should == report
|
15
|
+
end
|
16
|
+
|
17
|
+
Then /^it succeeds$/ do
|
18
|
+
puts @last_stderr if @last_stderr
|
19
|
+
@last_exit_status.should == Mongify::CLI::Application::STATUS_SUCCESS
|
20
|
+
end
|
21
|
+
|
22
|
+
Then /^it reports the current version$/ do
|
23
|
+
@last_stdout.should == "mongify #{Mongify::VERSION}\n"
|
24
|
+
end
|
25
|
+
|
26
|
+
Then /^the exit status indicates an error$/ do
|
27
|
+
@last_exit_status.should == Mongify::CLI::Application::STATUS_ERROR
|
28
|
+
end
|
29
|
+
|
30
|
+
Then /^it reports the error ['"](.*)['"]$/ do |string|
|
31
|
+
@last_stderr.chomp.should == string
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
|
36
|
+
Given /^a database exists$/ do
|
37
|
+
GenerateDatabase.sqlite
|
38
|
+
end
|
39
|
+
|
40
|
+
Then /^it should print out the database schema$/ do
|
41
|
+
@last_stdout.should == DATABASE_PRINT
|
42
|
+
end
|