@@ -26,10 +26,17 @@ def self.require_deps
2626 end
2727
2828 def self . specify_options ( c )
29+ c . option 'engine' , "--engine ENGINE" , "Database engine, (default: 'mysql', postgres also supported)"
2930 c . option 'dbname' , '--dbname DB' , 'Database name'
3031 c . option 'user' , '--user USER' , 'Database user name'
3132 c . option 'password' , '--password PW' , "Database user's password, (default: '')"
3233 c . option 'host' , '--host HOST' , 'Database host name (default: "localhost")'
34+ c . option 'port' , '--port PORT' , 'Custom database port connect to (optional)'
35+ c . option 'blog_id' , '--blog_id ID' , 'Specify a single Movable Type blog ID to import (default: all blogs)'
36+ c . option 'categories' , '--categories' , "If true, save post's categories in its YAML front matter. (default: true)"
37+ c . option 'src_encoding' , '--src_encoding ENCODING' , "Encoding of strings from database. (default: UTF-8)"
38+ c . option 'dest_encoding' , '--dest_encoding ENCODING' , "Encoding of output strings. (default: UTF-8)"
39+ c . option 'comments' , '--comments' , "If true, output comments in _comments directory (default: false)"
3340 end
3441
3542 # By default this migrator will include posts for all your MovableType blogs.
@@ -58,6 +65,7 @@ def self.specify_options(c)
5865 def self . process ( options )
5966 options = default_options . merge ( options )
6067
68+ engine = options . fetch ( 'engine' , 'mysql' )
6169 dbname = options . fetch ( 'dbname' )
6270 user = options . fetch ( 'user' )
6371 pass = options . fetch ( 'password' , "" )
@@ -66,7 +74,19 @@ def self.process(options)
6674
6775 posts_name_by_id = { } if comments
6876
69- db = Sequel . mysql ( dbname , :user => user , :password => pass , :host => host )
77+ db_opts = { user => user , :password => pass , :host => host }
78+
79+ # Use the default port by default, but set the port if one is provided.
80+ if options [ 'port' ]
81+ db_opts [ :port ] = options [ 'port' ]
82+ end
83+
84+ if engine != 'mysql' && engine != 'postgres'
85+ abort ( "unsupported --engine value supplied '#{ engine } '. Only 'mysql' and 'postgres' are supported" )
86+ end
87+
88+ db = Sequel . public_send ( engine , dbname , db_opts )
89+
7090 post_categories = db [ :mt_placement ] . join ( :mt_category , :category_id => :placement_category_id )
7191
7292 FileUtils . mkdir_p "_posts"
0 commit comments