xmysql2psql 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,34 @@
1
+ require 'test_helper'
2
+
3
+ require 'xmysql2psql/converter'
4
+
5
+ class ConverterTest < Test::Unit::TestCase
6
+
7
+ class << self
8
+ def startup
9
+ seed_test_database
10
+ @@options=get_test_config_by_label(:localmysql_to_file_convert_nothing)
11
+ end
12
+ def shutdown
13
+ delete_files_for_test_config(@@options)
14
+ end
15
+ end
16
+ def setup
17
+ end
18
+ def teardown
19
+ end
20
+ def options
21
+ @@options
22
+ end
23
+
24
+ def test_new_converter
25
+ assert_nothing_raised do
26
+ reader=get_test_reader(options)
27
+ writer=get_test_file_writer(options)
28
+ converter=Xmysql2psql::Converter.new(reader,writer,options)
29
+ assert_equal 0,converter.convert
30
+ end
31
+ end
32
+
33
+
34
+ end
@@ -0,0 +1,35 @@
1
+ require 'test_helper'
2
+
3
+ require 'xmysql2psql/mysql_reader'
4
+
5
+ class MysqlReaderBaseTest < Test::Unit::TestCase
6
+
7
+ class << self
8
+ def startup
9
+ seed_test_database
10
+ @@options = get_test_config_by_label(:localmysql_to_file_convert_nothing)
11
+ end
12
+ def shutdown
13
+ delete_files_for_test_config(@@options)
14
+ end
15
+ end
16
+ def setup
17
+ end
18
+ def teardown
19
+ end
20
+ def options
21
+ @@options
22
+ end
23
+
24
+ def test_mysql_connection
25
+ assert_nothing_raised do
26
+ reader = Xmysql2psql::MysqlReader.new(options)
27
+ end
28
+ end
29
+ def test_mysql_reconnect
30
+ assert_nothing_raised do
31
+ reader = Xmysql2psql::MysqlReader.new(options)
32
+ reader.reconnect
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,47 @@
1
+ require 'test_helper'
2
+
3
+ class MysqlReaderTest < Test::Unit::TestCase
4
+
5
+ class << self
6
+ def startup
7
+ seed_test_database
8
+ @@options = get_test_config_by_label(:localmysql_to_file_convert_nothing)
9
+ @@reader=get_test_reader(@@options)
10
+ end
11
+ def shutdown
12
+ delete_files_for_test_config(@@options)
13
+ end
14
+ end
15
+ def setup
16
+ end
17
+ def teardown
18
+ end
19
+ def reader
20
+ @@reader
21
+ end
22
+
23
+ def test_db_connection
24
+ assert_nothing_raised do
25
+ reader.mysql.ping
26
+ end
27
+ end
28
+ def test_tables_collection
29
+ values = reader.tables.select{|t| t.name == 'numeric_types_basics'}
30
+ assert_true values.length==1
31
+ assert_equal 'numeric_types_basics', values[0].name
32
+ end
33
+ def test_paginated_read
34
+ expected_rows=3
35
+ page_size=2
36
+ expected_pages=(1.0 * expected_rows / page_size).ceil
37
+
38
+ row_count=my_row_count=0
39
+ table = reader.tables.select{|t| t.name == 'numeric_types_basics'}[0]
40
+ reader.paginated_read(table, page_size) do |row,counter|
41
+ row_count=counter
42
+ my_row_count+=1
43
+ end
44
+ assert_equal expected_rows, row_count
45
+ assert_equal expected_rows, my_row_count
46
+ end
47
+ end
@@ -0,0 +1,30 @@
1
+ require 'test_helper'
2
+
3
+ require 'xmysql2psql/postgres_db_writer'
4
+
5
+ class PostgresDbWriterBaseTest < Test::Unit::TestCase
6
+
7
+ class << self
8
+ def startup
9
+ seed_test_database
10
+ @@options=get_test_config_by_label(:localmysql_to_db_convert_nothing)
11
+ end
12
+ def shutdown
13
+ delete_files_for_test_config(@@options)
14
+ end
15
+ end
16
+ def setup
17
+ end
18
+ def teardown
19
+ end
20
+ def options
21
+ @@options
22
+ end
23
+
24
+ def test_pg_connection
25
+ assert_nothing_raised do
26
+ reader = Xmysql2psql::PostgresDbWriter.new(options)
27
+ end
28
+ end
29
+
30
+ end
@@ -0,0 +1,30 @@
1
+ module Test::Unit
2
+
3
+ class TestCase
4
+
5
+ def self.must(name, &block)
6
+ test_name = "test_#{name.gsub(/\s+/,'_')}".to_sym
7
+ defined = instance_method(test_name) rescue false
8
+ raise "#{test_name} is already defined in #{self}" if defined
9
+ if block_given?
10
+ define_method(test_name, &block)
11
+ else
12
+ define_method(test_name) do
13
+ flunk "No implementation provided for #{name}"
14
+ end
15
+ end
16
+ end
17
+
18
+ end
19
+ end
20
+
21
+
22
+ module Test::Unit::Assertions
23
+ def assert_false(object, message="")
24
+ assert_equal(false, object, message)
25
+ end
26
+ def assert_true(object, message="")
27
+ assert_equal(true, object, message)
28
+ end
29
+ end
30
+
@@ -0,0 +1,88 @@
1
+ require 'rubygems'
2
+ begin
3
+ gem 'test-unit'
4
+ require "test/unit"
5
+ rescue LoadError
6
+ # assume using stdlib Test:Unit
7
+ require 'test/unit'
8
+ end
9
+
10
+ require 'ext_test_unit'
11
+
12
+ def seed_test_database
13
+ options=get_test_config_by_label(:localmysql_to_file_convert_nothing)
14
+ seedfilepath = "#{File.dirname(__FILE__)}/../fixtures/seed_integration_tests.sql"
15
+ rc=system("mysql -u#{options.mysqlusername} #{options.mysqldatabase} < #{seedfilepath}")
16
+ raise StandardError unless rc
17
+ return true
18
+ rescue
19
+ raise StandardError.new("Failed to seed integration test db. See README for setup requirements.")
20
+ ensure
21
+ delete_files_for_test_config(options)
22
+ end
23
+
24
+ def get_test_reader(options)
25
+ require 'xmysql2psql/mysql_reader'
26
+ Xmysql2psql::MysqlReader.new(options)
27
+ rescue
28
+ raise StandardError.new("Failed to initialize integration test db. See README for setup requirements.")
29
+ end
30
+
31
+ def get_test_file_writer(options)
32
+ require 'xmysql2psql/postgres_file_writer'
33
+ Xmysql2psql::PostgresFileWriter.new(options.destfile)
34
+ rescue => e
35
+ puts e.inspect
36
+ raise StandardError.new("Failed to initialize file writer from #{options.inspect}. See README for setup requirements.")
37
+ end
38
+
39
+ def get_test_converter(options)
40
+ require 'xmysql2psql/converter'
41
+ reader=get_test_reader(options)
42
+ writer=get_test_file_writer(options)
43
+ Xmysql2psql::Converter.new(reader,writer,options)
44
+ rescue
45
+ raise StandardError.new("Failed to initialize converter from #{options.inspect}. See README for setup requirements.")
46
+ end
47
+
48
+ def get_temp_file(basename)
49
+ require 'tempfile'
50
+ f = Tempfile.new(basename)
51
+ path = f.path
52
+ f.close!()
53
+ path
54
+ end
55
+
56
+
57
+ def get_new_test_config(to_file = true, include_tables = [], exclude_tables = [], supress_data = false, supress_ddl = false, force_truncate = false)
58
+ require 'xmysql2psql/config'
59
+ require 'xmysql2psql/config_base'
60
+ to_filename = to_file ? get_temp_file('xmysql2psql_tmp_output') : nil
61
+ configtext = Xmysql2psql::Config.template(to_filename, include_tables, exclude_tables, supress_data, supress_ddl, force_truncate)
62
+ configfile=get_temp_file('xmysql2psql_tmp_config')
63
+ File.open(configfile, 'w') {|f| f.write(configtext) }
64
+ Xmysql2psql::ConfigBase.new( configfile )
65
+ rescue
66
+ raise StandardError.new("Failed to initialize options from #{configfile}. See README for setup requirements.")
67
+ end
68
+
69
+ def get_test_config_by_label(name)
70
+ case name
71
+ when :localmysql_to_file_convert_nothing
72
+ get_new_test_config(true, ['unobtainium'], ['kryptonite'], true, true, false)
73
+ when :localmysql_to_file_convert_all
74
+ get_new_test_config(true, [], [], false, false, false)
75
+ when :localmysql_to_db_convert_all
76
+ get_new_test_config(false, [], [], false, false, false)
77
+ when :localmysql_to_db_convert_nothing
78
+ get_new_test_config(false, ['unobtainium'], ['kryptonite'], true, true, false)
79
+ else
80
+ raise StandardError.new("Invalid label: #{name}")
81
+ end
82
+ end
83
+
84
+ def delete_files_for_test_config(config)
85
+ File.delete(config.destfile) if File.exists?(config.destfile)
86
+ File.delete(config.filepath) if File.exists?(config.filepath)
87
+ rescue
88
+ end
@@ -0,0 +1,49 @@
1
+ require 'test_helper'
2
+ require 'xmysql2psql/config_base'
3
+
4
+ #
5
+ #
6
+ class ConfigBaseTest < Test::Unit::TestCase
7
+ attr_reader :config, :configfilepath
8
+ def setup
9
+ @configfilepath="#{File.dirname(__FILE__)}/../fixtures/config_all_options.yml"
10
+ @config = Xmysql2psql::ConfigBase.new( configfilepath )
11
+ end
12
+
13
+ def teardown
14
+ @config = nil
15
+ end
16
+
17
+ def test_config_loaded
18
+ assert_not_nil config.config
19
+ assert_equal configfilepath,config.filepath
20
+ end
21
+
22
+ def test_uninitialized_error_when_not_found_and_no_default
23
+ assert_raises(Xmysql2psql::UninitializedValueError) do
24
+ value = @config.not_found(:none)
25
+ end
26
+ end
27
+
28
+ def test_default_when_not_found
29
+ expected = 'defaultvalue'
30
+ value = @config.not_found(expected)
31
+ assert_equal expected,value
32
+ end
33
+
34
+ def test_mysql_hostname
35
+ value = @config.mysqlhostname
36
+ assert_equal 'localhost',value
37
+ end
38
+
39
+ def test_mysql_hostname_array_access
40
+ value = @config[:mysqlhostname]
41
+ assert_equal 'localhost',value
42
+ end
43
+
44
+ def test_dest_file
45
+ value = @config.destfile
46
+ assert_equal 'somefile',value
47
+ end
48
+
49
+ end
@@ -0,0 +1,31 @@
1
+ require 'test_helper'
2
+
3
+ require 'xmysql2psql/config'
4
+
5
+ class ConfigTest < Test::Unit::TestCase
6
+ attr_reader :configfile_new, :configfile_all_opts, :configfile_not_found
7
+ def setup
8
+ @configfile_all_opts = "#{File.dirname(__FILE__)}/../fixtures/config_all_options.yml"
9
+ @configfile_not_found = "#{File.dirname(__FILE__)}/../fixtures/config_not_found.yml.do_not_create_this_file"
10
+ @configfile_new = get_temp_file('xmysql2psql_test_config')
11
+ end
12
+ def teardown
13
+ File.delete(configfile_new) if File.exists?(configfile_new)
14
+ end
15
+
16
+ def test_config_loaded
17
+ value = Xmysql2psql::Config.new(configfile_all_opts, false)
18
+ assert_not_nil value
19
+ end
20
+
21
+ def test_config_file_not_found
22
+ assert_raise(Xmysql2psql::ConfigurationFileNotFound) do
23
+ value = Xmysql2psql::Config.new(configfile_not_found, false)
24
+ end
25
+ end
26
+ def test_initialize_new_config_file
27
+ assert_raise(Xmysql2psql::ConfigurationFileInitialized) do
28
+ value = Xmysql2psql::Config.new(configfile_new, true)
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,29 @@
1
+ require 'test_helper'
2
+
3
+ require 'xmysql2psql'
4
+
5
+ class PostgresFileWriterTest < Test::Unit::TestCase
6
+ attr_accessor :destfile
7
+ def setup
8
+ begin
9
+ f = Tempfile.new('xmysql2psql_test_destfile')
10
+ @destfile = f.path
11
+ f.close!()
12
+ rescue => e
13
+ raise StandardError.new("Failed to initialize integration test db. See README for setup requirements.")
14
+ end
15
+ end
16
+ def teardown
17
+ File.delete(destfile) if File.exists?(destfile)
18
+ end
19
+
20
+ def test_basic_write
21
+ writer = Xmysql2psql::PostgresFileWriter.new(destfile)
22
+ writer.close
23
+ content = IO.read(destfile)
24
+ assert_not_nil content.match("SET client_encoding = 'UTF8'")
25
+ assert_nil content.match("unobtanium")
26
+ end
27
+
28
+
29
+ end
@@ -0,0 +1,79 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{xmysql2psql}
8
+ s.version = "0.2.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Kota Mizushima <mizukota@gmail.com>"]
12
+ s.date = %q{2013-05-28}
13
+ s.default_executable = %q{xmysql2psql}
14
+ s.description = %q{It can create postgresql dump from mysql database or directly load data from mysql to
15
+ postgresql (at about 100 000 records per minute). Translates most data types and indexes.}
16
+ s.email = %q{gallagher.paul@gmail.com}
17
+ s.executables = ["xmysql2psql"]
18
+ s.extra_rdoc_files = [
19
+ "README.rdoc"
20
+ ]
21
+ s.files = [
22
+ ".gitignore",
23
+ "MIT-LICENSE",
24
+ "README.rdoc",
25
+ "Rakefile",
26
+ "bin/xmysql2psql",
27
+ "lib/xmysql2psql.rb",
28
+ "lib/xmysql2psql/config.rb",
29
+ "lib/xmysql2psql/config_base.rb",
30
+ "lib/xmysql2psql/converter.rb",
31
+ "lib/xmysql2psql/errors.rb",
32
+ "lib/xmysql2psql/mysql_reader.rb",
33
+ "lib/xmysql2psql/postgres_db_writer.rb",
34
+ "lib/xmysql2psql/postgres_file_writer.rb",
35
+ "lib/xmysql2psql/postgres_writer.rb",
36
+ "lib/xmysql2psql/version.rb",
37
+ "lib/xmysql2psql/writer.rb",
38
+ "xmysql2psql.gemspec",
39
+ "test/fixtures/config_all_options.yml",
40
+ "test/fixtures/seed_integration_tests.sql",
41
+ "test/integration/convert_to_db_test.rb",
42
+ "test/integration/convert_to_file_test.rb",
43
+ "test/integration/converter_test.rb",
44
+ "test/integration/mysql_reader_base_test.rb",
45
+ "test/integration/mysql_reader_test.rb",
46
+ "test/integration/postgres_db_writer_base_test.rb",
47
+ "test/lib/ext_test_unit.rb",
48
+ "test/lib/test_helper.rb",
49
+ "test/units/config_base_test.rb",
50
+ "test/units/config_test.rb",
51
+ "test/units/postgres_file_writer_test.rb"
52
+ ]
53
+ s.homepage = %q{http://github.com/kmizu/xmysql2psql}
54
+ s.rdoc_options = ["--charset=UTF-8"]
55
+ s.require_paths = ["lib"]
56
+ s.rubygems_version = %q{1.3.7}
57
+ s.summary = %q{Tool for converting mysql database to postgresql}
58
+ s.test_files = [
59
+ "test/integration/convert_to_db_test.rb",
60
+ "test/integration/convert_to_file_test.rb",
61
+ "test/integration/converter_test.rb",
62
+ "test/integration/mysql_reader_base_test.rb",
63
+ "test/integration/mysql_reader_test.rb",
64
+ "test/integration/postgres_db_writer_base_test.rb",
65
+ "test/lib/ext_test_unit.rb",
66
+ "test/lib/test_helper.rb",
67
+ "test/units/config_base_test.rb",
68
+ "test/units/config_test.rb",
69
+ "test/units/postgres_file_writer_test.rb"
70
+ ]
71
+
72
+ s.specification_version = 3
73
+
74
+ s.add_runtime_dependency(%q<pg>, [">= 0.15.0"])
75
+ s.add_development_dependency(%q<test-unit>, [">= 2.5.5"])
76
+ s.add_dependency(%q<mysql>, ["= 2.8.1"])
77
+ s.add_dependency(%q<test-unit>, [">= 2.1.1"])
78
+ end
79
+
metadata ADDED
@@ -0,0 +1,144 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: xmysql2psql
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Kota Mizushima <mizukota@gmail.com>
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-05-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: pg
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: 0.15.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: 0.15.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: test-unit
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: 2.5.5
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: 2.5.5
41
+ - !ruby/object:Gem::Dependency
42
+ name: mysql
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '='
46
+ - !ruby/object:Gem::Version
47
+ version: 2.8.1
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '='
53
+ - !ruby/object:Gem::Version
54
+ version: 2.8.1
55
+ - !ruby/object:Gem::Dependency
56
+ name: test-unit
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: 2.1.1
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: 2.1.1
69
+ description: |-
70
+ It can create postgresql dump from mysql database or directly load data from mysql to
71
+ postgresql (at about 100 000 records per minute). Translates most data types and indexes.
72
+ email: gallagher.paul@gmail.com
73
+ executables:
74
+ - xmysql2psql
75
+ extensions: []
76
+ extra_rdoc_files:
77
+ - README.rdoc
78
+ files:
79
+ - .gitignore
80
+ - MIT-LICENSE
81
+ - README.rdoc
82
+ - Rakefile
83
+ - bin/xmysql2psql
84
+ - lib/xmysql2psql.rb
85
+ - lib/xmysql2psql/config.rb
86
+ - lib/xmysql2psql/config_base.rb
87
+ - lib/xmysql2psql/converter.rb
88
+ - lib/xmysql2psql/errors.rb
89
+ - lib/xmysql2psql/mysql_reader.rb
90
+ - lib/xmysql2psql/postgres_db_writer.rb
91
+ - lib/xmysql2psql/postgres_file_writer.rb
92
+ - lib/xmysql2psql/postgres_writer.rb
93
+ - lib/xmysql2psql/version.rb
94
+ - lib/xmysql2psql/writer.rb
95
+ - xmysql2psql.gemspec
96
+ - test/fixtures/config_all_options.yml
97
+ - test/fixtures/seed_integration_tests.sql
98
+ - test/integration/convert_to_db_test.rb
99
+ - test/integration/convert_to_file_test.rb
100
+ - test/integration/converter_test.rb
101
+ - test/integration/mysql_reader_base_test.rb
102
+ - test/integration/mysql_reader_test.rb
103
+ - test/integration/postgres_db_writer_base_test.rb
104
+ - test/lib/ext_test_unit.rb
105
+ - test/lib/test_helper.rb
106
+ - test/units/config_base_test.rb
107
+ - test/units/config_test.rb
108
+ - test/units/postgres_file_writer_test.rb
109
+ homepage: http://github.com/kmizu/xmysql2psql
110
+ licenses: []
111
+ metadata: {}
112
+ post_install_message:
113
+ rdoc_options:
114
+ - --charset=UTF-8
115
+ require_paths:
116
+ - lib
117
+ required_ruby_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - '>='
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ required_rubygems_version: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - '>='
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ requirements: []
128
+ rubyforge_project:
129
+ rubygems_version: 2.0.6
130
+ signing_key:
131
+ specification_version: 3
132
+ summary: Tool for converting mysql database to postgresql
133
+ test_files:
134
+ - test/integration/convert_to_db_test.rb
135
+ - test/integration/convert_to_file_test.rb
136
+ - test/integration/converter_test.rb
137
+ - test/integration/mysql_reader_base_test.rb
138
+ - test/integration/mysql_reader_test.rb
139
+ - test/integration/postgres_db_writer_base_test.rb
140
+ - test/lib/ext_test_unit.rb
141
+ - test/lib/test_helper.rb
142
+ - test/units/config_base_test.rb
143
+ - test/units/config_test.rb
144
+ - test/units/postgres_file_writer_test.rb