From 7b09e41fd1dc691fe22106e5b0c02371bc3b9bd2 Mon Sep 17 00:00:00 2001 From: Holger Amann Date: Fri, 22 Jan 2010 22:17:44 +0800 Subject: [PATCH] Fixed reading config --- config.yml | 16 ++++++++++------ mysql2psql | 29 +++++++++++++++-------------- 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/config.yml b/config.yml index 528b6b9..0dd4703 100644 --- a/config.yml +++ b/config.yml @@ -1,16 +1,20 @@ mysql: hostname: localhost port: 3306 + socket: /tmp/mysql.sock username: somename password: secretpassword databasename: somename -postgres: - hostname: localhost - port: 5432 - username: somename - password: secretpassword - databasename: somename +destination: + # if file is given, output goes to file, else postgres + file: + postgres: + hostname: localhost + port: 5432 + username: somename + password: secretpassword + databasename: somename tables: table1, diff --git a/mysql2psql b/mysql2psql index 18aa75e..5392739 100755 --- a/mysql2psql +++ b/mysql2psql @@ -653,20 +653,20 @@ def parse_tablenames(tables) list end -def read_config(file) - config = YAML::load(File.read(file)) +def read_config(filepath) + config = YAML::load(File.read(filepath)) @mysqluser = config["mysql"]["username"] ? config["mysql"]["username"] : '' @mysqlpass = config["mysql"]["password"] ? config["mysql"]["password"] : '' @mysqlhost = config["mysql"]["hostname"] ? config["mysql"]["hostname"] : 'localhost' - @mysqlport = config["mysql"]["port"] ? config["mysql"]["port"].to_i : nil - @mysqlsock = config["mysql"]["socket"] ? config["mysql"]["socket"] : nil - @mysqldb = config["mysql"]["databasename"] + @mysqlport = config["mysql"]["port"] + @mysqlsock = config["mysql"]["socket"] + @mysqldb = config["mysql"]["databasename"] - @file = config["destination"]["file"] ? config["destination"]["file"] : '' - @pguser = config["destination"]["postgres"]["username"] ? config["postgres"]["username"] : '' - @pgpass = config["destination"]["postgres"]["password"] ? config["postgres"]["password"] : '' - @pghost = config["destination"]["postgres"]["hostname"] ? config["postgres"]["hostname"] : 'localhost' - @pgport = config["destination"]["postgres"]["port"] ? config["postgres"]["port"].to_i : 5432 + @destfile = config["destination"]["file"] + @pguser = config["destination"]["postgres"]["username"] ? config["destination"]["postgres"]["username"] : '' + @pgpass = config["destination"]["postgres"]["password"] ? config["destination"]["postgres"]["password"] : '' + @pghost = config["destination"]["postgres"]["hostname"] ? config["destination"]["postgres"]["hostname"] : 'localhost' + @pgport = config["destination"]["postgres"]["port"] ? config["destination"]["postgres"]["port"].to_i : 5432 @pgdb = config["destination"]["postgres"]["databasename"] @tables = config["tables"] ? config["tables"].split(',') : nil @@ -678,12 +678,13 @@ if @tables.nil? exit 1 end -reader = MysqlReader.new(mysqlhost, mysqluser, mysqlpass, mysqldb, mysqlport, mysqlsock) +reader = MysqlReader.new(@mysqlhost, @mysqluser, @mysqlpass, @mysqldb, @mysqlport, @mysqlsock) -if @file.eql?('') - writer = PostgresDbWriter.new(pghost, pguser, pgpass, pgdb, pgport) +if @destfile.nil? + writer = PostgresDbWriter.new(@pghost, @pguser, @pgpass, @pgdb, @pgport) else writer = PostgresFileWriter.new(@file) end -converter = Converter.new(reader, writer, :only_tables => parse_tablenames(tables)) + +converter = Converter.new(reader, writer, :only_tables => parse_tablenames(@tables)) converter.convert -- 2.1.4