Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Data for MongoDB #12

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added mongodb/districts.bson
Binary file not shown.
1 change: 1 addition & 0 deletions mongodb/districts.metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"options":{},"indexes":[{"v":1,"key":{"_id":1},"name":"_id_","ns":"wilayah_administratif.districts"}]}
Binary file added mongodb/provinces.bson
Binary file not shown.
1 change: 1 addition & 0 deletions mongodb/provinces.metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"options":{},"indexes":[{"v":1,"key":{"_id":1},"name":"_id_","ns":"wilayah_administratif.provinces"}]}
Binary file added mongodb/regencies.bson
Binary file not shown.
1 change: 1 addition & 0 deletions mongodb/regencies.metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"options":{},"indexes":[{"v":1,"key":{"_id":1},"name":"_id_","ns":"wilayah_administratif.regencies"}]}
Binary file added mongodb/system.indexes.bson
Binary file not shown.
Binary file added mongodb/villages.bson
Binary file not shown.
1 change: 1 addition & 0 deletions mongodb/villages.metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"options":{},"indexes":[{"v":1,"key":{"_id":1},"name":"_id_","ns":"wilayah_administratif.villages"}]}
11 changes: 11 additions & 0 deletions scripts/mysql_mongodb_converter/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# MySQL to MongoDB conversion
Using Mongify, a ruby based application to convert and translate mysql database to mongodb.
Please check http://mongify.com/getting_started.html

# Getting started
- Install mongify `gem install mongify`
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use Gemfile instead?

- Make sure you have import the wilayah-administratif-indonesia dump file (indonesia.mysql) on your running MySQL database
- Make sure you have a running MongoDB
- Check `database.config` and adjust the connection crendentials for both MySQL and MongoDB
- Run `mongify check database.config` to verify the connection
- Run the conversion process `mongify process database.config translation.rb`
12 changes: 12 additions & 0 deletions scripts/mysql_mongodb_converter/database.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
sql_connection do
adapter "mysql"
host "localhost"
username "root"
password ""
database "wilayah_administratif"
end

mongodb_connection do
host "localhost"
database "wilayah_administratif"
end
35 changes: 35 additions & 0 deletions scripts/mysql_mongodb_converter/translation.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
table "districts" do
column "id", :key, :as => :integer, :rename_to => "code"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be better if you use 2 spaces indentation for Ruby code as in https://github.com/bbatsov/ruby-style-guide#spaces-indentation.

column "regency_id", :integer, :references => "regencies", :rename_to => "regency"
column "name", :string

before_save do |row|
row.code = row.delete('pre_mongified_id')
end
end

table "provinces" do
column "id", :key, :as => :integer
column "name", :string
before_save do |row|
row.code = row.delete('pre_mongified_id')
end
end

table "regencies" do
column "id", :key, :as => :integer, :rename_to => "code"
column "province_id", :integer, :references => "provinces", :rename_to => "province"
column "name", :string
before_save do |row|
row.code = row.delete('pre_mongified_id')
end
end

table "villages" do
column "id", :key, :as => :integer, :rename_to => "code"
column "district_id", :integer, :references => "districts", :rename_to => "district"
column "name", :string
before_save do |row|
row.code = row.delete('pre_mongified_id')
end
end