mysql2psql 0.1.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.
- data/.gitignore +4 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +135 -0
- data/Rakefile +87 -0
- data/bin/mysql2psql +7 -0
- data/lib/mysql2psql.rb +41 -0
- data/lib/mysql2psql/config.rb +100 -0
- data/lib/mysql2psql/config_base.rb +39 -0
- data/lib/mysql2psql/converter.rb +55 -0
- data/lib/mysql2psql/errors.rb +16 -0
- data/lib/mysql2psql/mysql_reader.rb +191 -0
- data/lib/mysql2psql/postgres_db_writer.rb +179 -0
- data/lib/mysql2psql/postgres_file_writer.rb +142 -0
- data/lib/mysql2psql/postgres_writer.rb +143 -0
- data/lib/mysql2psql/version.rb +9 -0
- data/lib/mysql2psql/writer.rb +6 -0
- data/mysql2psql.gemspec +91 -0
- data/test/fixtures/seed_integration_tests.sql +24 -0
- data/test/integration/convert_to_db_test.rb +29 -0
- data/test/integration/convert_to_file_test.rb +66 -0
- data/test/integration/converter_test.rb +34 -0
- data/test/integration/mysql_reader_base_test.rb +35 -0
- data/test/integration/mysql_reader_test.rb +47 -0
- data/test/integration/postgres_db_writer_base_test.rb +30 -0
- data/test/lib/ext_test_unit.rb +30 -0
- data/test/lib/test_helper.rb +88 -0
- data/test/units/config_base_test.rb +49 -0
- data/test/units/config_test.rb +31 -0
- data/test/units/postgres_file_writer_test.rb +29 -0
- metadata +167 -0
@@ -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 'mysql2psql/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 = Mysql2psql::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 'mysql2psql/mysql_reader'
|
26
|
+
Mysql2psql::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 'mysql2psql/postgres_file_writer'
|
33
|
+
Mysql2psql::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 'mysql2psql/converter'
|
41
|
+
reader=get_test_reader(options)
|
42
|
+
writer=get_test_file_writer(options)
|
43
|
+
Mysql2psql::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 'mysql2psql/config'
|
59
|
+
require 'mysql2psql/config_base'
|
60
|
+
to_filename = to_file ? get_temp_file('mysql2psql_tmp_output') : nil
|
61
|
+
configtext = Mysql2psql::Config.template(to_filename, include_tables, exclude_tables, supress_data, supress_ddl, force_truncate)
|
62
|
+
configfile=get_temp_file('mysql2psql_tmp_config')
|
63
|
+
File.open(configfile, 'w') {|f| f.write(configtext) }
|
64
|
+
Mysql2psql::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 'mysql2psql/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 = Mysql2psql::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(Mysql2psql::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 'mysql2psql/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('mysql2psql_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 = Mysql2psql::Config.new(configfile_all_opts, false)
|
18
|
+
assert_not_nil value
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_config_file_not_found
|
22
|
+
assert_raise(Mysql2psql::ConfigurationFileNotFound) do
|
23
|
+
value = Mysql2psql::Config.new(configfile_not_found, false)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
def test_initialize_new_config_file
|
27
|
+
assert_raise(Mysql2psql::ConfigurationFileInitialized) do
|
28
|
+
value = Mysql2psql::Config.new(configfile_new, true)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
require 'mysql2psql'
|
4
|
+
|
5
|
+
class PostgresFileWriterTest < Test::Unit::TestCase
|
6
|
+
attr_accessor :destfile
|
7
|
+
def setup
|
8
|
+
begin
|
9
|
+
f = Tempfile.new('mysql2psql_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 = Mysql2psql::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
|
metadata
ADDED
@@ -0,0 +1,167 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mysql2psql
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Max Lapshin <max@maxidoors.ru>
|
14
|
+
- Anton Ageev <anton@ageev.name>
|
15
|
+
- Samuel Tribehou <cracoucax@gmail.com>
|
16
|
+
- Marco Nenciarini <marco.nenciarini@devise.it>
|
17
|
+
- James Nobis <jnobis@jnobis.controldocs.com>
|
18
|
+
- quel <github@quelrod.net>
|
19
|
+
- Holger Amann <keeney@fehu.org>
|
20
|
+
- Maxim Dobriakov <closer.main@gmail.com>
|
21
|
+
- Michael Kimsal <mgkimsal@gmail.com>
|
22
|
+
- Jacob Coby <jcoby@portallabs.com>
|
23
|
+
- Neszt Tibor <neszt@tvnetwork.hu>
|
24
|
+
- Miroslav Kratochvil <exa.exa@gmail.com>
|
25
|
+
- Paul Gallagher <gallagher.paul@gmail.com>
|
26
|
+
autorequire:
|
27
|
+
bindir: bin
|
28
|
+
cert_chain: []
|
29
|
+
|
30
|
+
date: 2010-09-19 00:00:00 +04:00
|
31
|
+
default_executable: mysql2psql
|
32
|
+
dependencies:
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: mysql
|
35
|
+
prerelease: false
|
36
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
37
|
+
none: false
|
38
|
+
requirements:
|
39
|
+
- - "="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
hash: 45
|
42
|
+
segments:
|
43
|
+
- 2
|
44
|
+
- 8
|
45
|
+
- 1
|
46
|
+
version: 2.8.1
|
47
|
+
type: :runtime
|
48
|
+
version_requirements: *id001
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
name: pg
|
51
|
+
prerelease: false
|
52
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - "="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
hash: 59
|
58
|
+
segments:
|
59
|
+
- 0
|
60
|
+
- 9
|
61
|
+
- 0
|
62
|
+
version: 0.9.0
|
63
|
+
type: :runtime
|
64
|
+
version_requirements: *id002
|
65
|
+
- !ruby/object:Gem::Dependency
|
66
|
+
name: test-unit
|
67
|
+
prerelease: false
|
68
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
69
|
+
none: false
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
hash: 9
|
74
|
+
segments:
|
75
|
+
- 2
|
76
|
+
- 1
|
77
|
+
- 1
|
78
|
+
version: 2.1.1
|
79
|
+
type: :development
|
80
|
+
version_requirements: *id003
|
81
|
+
description: |-
|
82
|
+
It can create postgresql dump from mysql database or directly load data from mysql to
|
83
|
+
postgresql (at about 100 000 records per minute). Translates most data types and indexes.
|
84
|
+
email: gallagher.paul@gmail.com
|
85
|
+
executables:
|
86
|
+
- mysql2psql
|
87
|
+
extensions: []
|
88
|
+
|
89
|
+
extra_rdoc_files:
|
90
|
+
- README.rdoc
|
91
|
+
files:
|
92
|
+
- .gitignore
|
93
|
+
- MIT-LICENSE
|
94
|
+
- README.rdoc
|
95
|
+
- Rakefile
|
96
|
+
- bin/mysql2psql
|
97
|
+
- lib/mysql2psql.rb
|
98
|
+
- lib/mysql2psql/config.rb
|
99
|
+
- lib/mysql2psql/config_base.rb
|
100
|
+
- lib/mysql2psql/converter.rb
|
101
|
+
- lib/mysql2psql/errors.rb
|
102
|
+
- lib/mysql2psql/mysql_reader.rb
|
103
|
+
- lib/mysql2psql/postgres_db_writer.rb
|
104
|
+
- lib/mysql2psql/postgres_file_writer.rb
|
105
|
+
- lib/mysql2psql/postgres_writer.rb
|
106
|
+
- lib/mysql2psql/version.rb
|
107
|
+
- lib/mysql2psql/writer.rb
|
108
|
+
- mysql2psql.gemspec
|
109
|
+
- test/fixtures/config_all_options.yml
|
110
|
+
- test/fixtures/seed_integration_tests.sql
|
111
|
+
- test/integration/convert_to_db_test.rb
|
112
|
+
- test/integration/convert_to_file_test.rb
|
113
|
+
- test/integration/converter_test.rb
|
114
|
+
- test/integration/mysql_reader_base_test.rb
|
115
|
+
- test/integration/mysql_reader_test.rb
|
116
|
+
- test/integration/postgres_db_writer_base_test.rb
|
117
|
+
- test/lib/ext_test_unit.rb
|
118
|
+
- test/lib/test_helper.rb
|
119
|
+
- test/units/config_base_test.rb
|
120
|
+
- test/units/config_test.rb
|
121
|
+
- test/units/postgres_file_writer_test.rb
|
122
|
+
has_rdoc: true
|
123
|
+
homepage: http://github.com/tardate/mysql2postgresql
|
124
|
+
licenses: []
|
125
|
+
|
126
|
+
post_install_message:
|
127
|
+
rdoc_options:
|
128
|
+
- --charset=UTF-8
|
129
|
+
require_paths:
|
130
|
+
- lib
|
131
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
132
|
+
none: false
|
133
|
+
requirements:
|
134
|
+
- - ">="
|
135
|
+
- !ruby/object:Gem::Version
|
136
|
+
hash: 3
|
137
|
+
segments:
|
138
|
+
- 0
|
139
|
+
version: "0"
|
140
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
141
|
+
none: false
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
hash: 3
|
146
|
+
segments:
|
147
|
+
- 0
|
148
|
+
version: "0"
|
149
|
+
requirements: []
|
150
|
+
|
151
|
+
rubyforge_project:
|
152
|
+
rubygems_version: 1.3.7
|
153
|
+
signing_key:
|
154
|
+
specification_version: 3
|
155
|
+
summary: Tool for converting mysql database to postgresql
|
156
|
+
test_files:
|
157
|
+
- test/integration/convert_to_db_test.rb
|
158
|
+
- test/integration/convert_to_file_test.rb
|
159
|
+
- test/integration/converter_test.rb
|
160
|
+
- test/integration/mysql_reader_base_test.rb
|
161
|
+
- test/integration/mysql_reader_test.rb
|
162
|
+
- test/integration/postgres_db_writer_base_test.rb
|
163
|
+
- test/lib/ext_test_unit.rb
|
164
|
+
- test/lib/test_helper.rb
|
165
|
+
- test/units/config_base_test.rb
|
166
|
+
- test/units/config_test.rb
|
167
|
+
- test/units/postgres_file_writer_test.rb
|