Installing Mongify
gem install mongify
Once installed you get a mongify command in your terminal
Usage: mongify command database.config [database_translation.rb]
Commands:
"check" or "ck" >> Checks connection for sql and no_sql databases [configuration_file]
"process" or "pr" >> Takes a translation and process it to mongodb [configuration_file, translation_file]
"translation" or "tr" >> Outputs a translation file from a sql connection [configuration_file]
Examples:
mongify translation datbase.config
mongify tr database.config
mongify check database.config
mongify process database.config database_translation.rb
Common options:
-h, --help Show this message
-v, --version Show version
Structure
In order to Mongify your database, we'll need two things: ul li A database configuration file - Used by Mongify to locate connections to the SQL and MongoDB databases. li A translation file - Used to translate your SQL data before saving it into MongoDB.
Configuration
Before you can do anything with Mongify, you need to setup a configuration file: database.config
sql_connection do
adapter "mysql"
host "localhost"
username "root"
password "passw0rd"
database "my_database"
end
mongodb_connection do
host "localhost"
database "my_database"
end
Translation
In order for Mongify to know what to do with your data, you must provide (or generate) a translation file: translation.rb
table "users" do
column "id", :key
column "first_name", :string
column "last_name", :string
column "created_at", :datetime
column "updated_at", :datetime
end
table "posts" do
column "id", :key
column "title", :string
column "owner_id", :integer, :references => :users
column "body", :text
column "published_at", :datetime
column "created_at", :datetime
column "updated_at", :datetime
end
table "comments", :embed_in => :posts, :on => :post_id do
column "id", :key
column "body", :text
column "post_id", :integer, :referneces => :posts
column "user_id", :integer, :references => :users
column "created_at", :datetime
column "updated_at", :datetime
end
table "preferences", :embed_in => :users, :as => :object do
column "id", :key
column "user_id", :integer, :references => "users"
column "notify_by_email", :boolean
end
table "notes", :embed_in => true, :polymorphic => 'notable' do
column "id", :key
column "user_id", :integer, :references => "users"
column "notable_id", :integer
column "notable_type", :string
column "body", :text
column "created_at", :datetime
column "updated_at", :datetime
end
To see what you can do with Tables and Columns, please refer to our Documentation
Commands
Mongify has 3 commands:
Check
Checkis a simple command and all it does is check if your database.config file is correct and all connections work
mongify check datbase.config
Translation
Translation is used to auto generate a translation from your SQL database.You simple run it as:
mongify translation database.config
Or to port the output into translation.rb, you can:
mongify translation database.config > translation.rb
Process
Once you have your translation file setup the way you want it, you can tell mongify to move the data by issuing the process command
mongify process database.config translation.rb
