Permalink
Browse files

Ability to define specific tables for export via YAML config file

  • Loading branch information...
1 parent 595eb49 commit c81a83a039f24f674c1cdc466c1ec12aef276b8b Chris Cummer committed Mar 8, 2009
Showing with 17 additions and 5 deletions.
  1. +1 −1 README
  2. +16 −4 mysql2sqlite.rb
View
2 README
@@ -2,7 +2,7 @@
== DESCRIPTION
-A Ruby script for exporting MySQL databases to Sqlite databases.
+A Ruby script to convert and export MySQL databases to Sqlite databases.
== USAGE
View
@@ -8,6 +8,8 @@
class MySQL2SqliteConverter
+
+
def initialize( args )
init_result = ( args.length == 1 ) ? init_from_yaml( args ) : init_from_command_line( args )
@@ -26,7 +28,9 @@ def mysql_to_sqlite()
arr = Array[]
- IO.popen( "mysqldump -u #{@username} -p#{@password} --compact --compatible=ansi --complete-insert --skip-extended-insert --default-character-set=binary #{@database_name}" ) do |pipe|
+ mysqldump_str = generate_mysqldump_str()
+
+ IO.popen( mysqldump_str ) do |pipe|
pipe.each_line do |line|
next if contains_disallowed_sql( line )
@@ -57,7 +61,7 @@ def init_from_yaml( args )
ruby_obj = YAML::load_file( args[0] )
config = ruby_obj[ 'config' ]
- return ( !config.nil? ) ? init( config['database'], config['username'], config['password'], config['overwrite'] ) : false
+ return ( !config.nil? ) ? init( config['database'], config['username'], config['password'], config['overwrite'], config['tables'] ) : false
else
return false
end
@@ -70,8 +74,8 @@ def init_from_command_line( args )
end
- def init( database_name, username, password, overwrite_files )
- @database_name, @username, @password, @overwrite_files = database_name, username, password, overwrite_files
+ def init( database_name, username, password, overwrite_files = true, tables = nil )
+ @database_name, @username, @password, @overwrite_files, @tables = database_name, username, password, overwrite_files, tables
return true
end
@@ -97,6 +101,14 @@ def handle_existing_file( file )
end
+ def generate_mysqldump_str()
+ table_str = ( nil != @tables ) ? @tables.join( ' ' ) : ''
+
+ mysqldump_str = "mysqldump -u #{@username} -p#{@password} --compact --compatible=ansi --complete-insert --skip-extended-insert --default-character-set=binary #{@database_name} " + table_str
+ return mysqldump_str
+ end
+
+
# Don't attempt to include lines of MySQL data that Sqlite doesn't recognize
def contains_disallowed_sql( line )
return true if line.include?( 'KEY "' )

0 comments on commit c81a83a

Please sign in to comment.