mysql2postgres 0.3.2
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.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/MIT-LICENSE +20 -0
- data/README.md +45 -0
- data/Rakefile +50 -0
- data/bin/mysql2psql +26 -0
- data/lib/mysql2psql/connection.rb +129 -0
- data/lib/mysql2psql/converter.rb +95 -0
- data/lib/mysql2psql/mysql_reader.rb +234 -0
- data/lib/mysql2psql/postgres_db_writer.rb +26 -0
- data/lib/mysql2psql/postgres_file_writer.rb +143 -0
- data/lib/mysql2psql/postgres_writer.rb +133 -0
- data/lib/mysql2psql/version.rb +5 -0
- data/lib/mysql2psql/writer.rb +9 -0
- data/lib/mysql2psql.rb +59 -0
- data/mysql2postgres.gemspec +80 -0
- data/test/fixtures/config_all_options.yml +39 -0
- data/test/fixtures/seed_integration_tests.sql +24 -0
- data/test/integration/convert_to_db_test.rb +23 -0
- data/test/integration/convert_to_file_test.rb +68 -0
- data/test/integration/converter_test.rb +21 -0
- data/test/integration/mysql_reader_base_test.rb +33 -0
- data/test/integration/mysql_reader_test.rb +40 -0
- data/test/integration/postgres_db_writer_base_test.rb +18 -0
- data/test/test_helper.rb +92 -0
- data/test/units/option_test.rb +17 -0
- data/test/units/postgres_file_writer_test.rb +25 -0
- metadata +199 -0
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require File.expand_path '../test_helper', __dir__
|
4
|
+
|
5
|
+
class PostgresDbWriterBaseTest < Test::Unit::TestCase
|
6
|
+
class << self
|
7
|
+
def startup
|
8
|
+
seed_test_database
|
9
|
+
@options = get_test_config_by_label :localmysql_to_db_convert_nothing
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_pg_connection
|
14
|
+
assert_nothing_raised do
|
15
|
+
Mysql2psql::PostgresDbWriter.new Tempfile.new('mysql2psql_test_').path, @options
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'test/unit'
|
5
|
+
require 'debug' if ENV.fetch('ENABLE_DEBUG', nil) == '1'
|
6
|
+
|
7
|
+
require File.expand_path('../lib/mysql2psql/version', __dir__)
|
8
|
+
require File.expand_path('../lib/mysql2psql/converter', __dir__)
|
9
|
+
require File.expand_path('../lib/mysql2psql/mysql_reader', __dir__)
|
10
|
+
require File.expand_path('../lib/mysql2psql/writer', __dir__)
|
11
|
+
require File.expand_path('../lib/mysql2psql/postgres_writer', __dir__)
|
12
|
+
require File.expand_path('../lib/mysql2psql/postgres_file_writer', __dir__)
|
13
|
+
require File.expand_path('../lib/mysql2psql/postgres_db_writer', __dir__)
|
14
|
+
|
15
|
+
def seed_test_database
|
16
|
+
options = get_test_config_by_label :localmysql_to_file_convert_nothing
|
17
|
+
seedfilepath = "#{__dir__}/../fixtures/seed_integration_tests.sql"
|
18
|
+
rc = system "mysql -u#{options[:mysql][:username]} #{options[:mysql][:database]} < #{seedfilepath}"
|
19
|
+
raise StandardError unless rc
|
20
|
+
|
21
|
+
true
|
22
|
+
rescue StandardError
|
23
|
+
raise 'Failed to seed integration test db. See README for setup requirements.'
|
24
|
+
end
|
25
|
+
|
26
|
+
def get_test_reader(options)
|
27
|
+
require 'mysql2psql/mysql_reader'
|
28
|
+
Mysql2psql::MysqlReader.new options
|
29
|
+
rescue StandardError
|
30
|
+
raise 'Failed to initialize integration test db. See README for setup requirements.'
|
31
|
+
end
|
32
|
+
|
33
|
+
def get_test_file_writer(options)
|
34
|
+
require 'mysql2psql/postgres_file_writer'
|
35
|
+
Mysql2psql::PostgresFileWriter.new options[:destfile]
|
36
|
+
rescue StandardError => e
|
37
|
+
puts e.inspect
|
38
|
+
raise "Failed to initialize file writer from #{options.inspect}. See README for setup requirements."
|
39
|
+
end
|
40
|
+
|
41
|
+
def get_test_converter(options)
|
42
|
+
require 'mysql2psql/converter'
|
43
|
+
reader = get_test_reader options
|
44
|
+
writer = get_test_file_writer options
|
45
|
+
Mysql2psql::Converter.new reader, writer, options
|
46
|
+
rescue StandardError
|
47
|
+
raise "Failed to initialize converter from #{options.inspect}. See README for setup requirements."
|
48
|
+
end
|
49
|
+
|
50
|
+
def get_temp_file(basename)
|
51
|
+
require 'tempfile'
|
52
|
+
f = Tempfile.new basename
|
53
|
+
path = f.path
|
54
|
+
f.close!
|
55
|
+
path
|
56
|
+
end
|
57
|
+
|
58
|
+
def get_new_test_config(include_tables: [], exclude_tables: [], to_file: false,
|
59
|
+
suppress_data: false, suppress_ddl: false, force_truncate: false)
|
60
|
+
|
61
|
+
to_filename = to_file ? get_temp_file(['mysql2psql_tmp_output_', '.yml']) : nil
|
62
|
+
binding.break
|
63
|
+
configtext = Mysql2psql::Config.template to_filename, include_tables, exclude_tables, suppress_data, suppress_ddl, force_truncate
|
64
|
+
configfile = get_temp_file 'mysql2psql_tmp_config'
|
65
|
+
File.open(configfile, 'w:UTF-8') { |f| f.write(configtext) }
|
66
|
+
yaml = YAML.load_file configfile
|
67
|
+
Mysql2psql::ConfigBase.new yaml
|
68
|
+
rescue StandardError
|
69
|
+
raise "Failed to initialize options from #{configfile}. See README for setup requirements."
|
70
|
+
end
|
71
|
+
|
72
|
+
def get_test_config_by_label(name)
|
73
|
+
case name
|
74
|
+
when :localmysql_to_file_convert_nothing
|
75
|
+
get_new_test_config to_file: true,
|
76
|
+
tables: ['unobtainium'],
|
77
|
+
exclude_tables: ['kryptonite'],
|
78
|
+
suppress_data: true,
|
79
|
+
suppress_ddl: true
|
80
|
+
when :localmysql_to_file_convert_all
|
81
|
+
get_new_test_config to_file: true
|
82
|
+
when :localmysql_to_db_convert_all
|
83
|
+
get_new_test_config
|
84
|
+
when :localmysql_to_db_convert_nothing
|
85
|
+
get_new_test_config tables: ['unobtainium'],
|
86
|
+
exclude_tables: ['kryptonite'],
|
87
|
+
suppress_data: true,
|
88
|
+
suppress_ddl: true
|
89
|
+
else
|
90
|
+
raise "Invalid label: #{name}"
|
91
|
+
end
|
92
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require File.expand_path '../test_helper', __dir__
|
4
|
+
require 'yaml'
|
5
|
+
|
6
|
+
class SettingTest < Test::Unit::TestCase
|
7
|
+
attr_reader :config_all_opts
|
8
|
+
|
9
|
+
def setup
|
10
|
+
@config_all_opts = YAML.load_file "#{__dir__}/../fixtures/config_all_options.yml"
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_options_loaded
|
14
|
+
instance = Mysql2psql.new @config_all_opts
|
15
|
+
assert_not_nil instance.options
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require File.expand_path '../test_helper', __dir__
|
4
|
+
|
5
|
+
class PostgresFileWriterTest < Test::Unit::TestCase
|
6
|
+
attr_accessor :destfile
|
7
|
+
|
8
|
+
def setup
|
9
|
+
@destfile = get_temp_file 'mysql2psql_test_destfile'
|
10
|
+
rescue StandardError
|
11
|
+
raise 'Failed to initialize integration test db. See README for setup requirements.'
|
12
|
+
end
|
13
|
+
|
14
|
+
def teardown
|
15
|
+
File.delete destfile
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_basic_write
|
19
|
+
writer = Mysql2psql::PostgresFileWriter.new destfile
|
20
|
+
writer.close
|
21
|
+
content = File.read destfile
|
22
|
+
assert_not_nil content.match("SET client_encoding = 'UTF8'")
|
23
|
+
assert_nil content.match('unobtanium')
|
24
|
+
end
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,199 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mysql2postgres
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.3.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Max Lapshin <max@maxidoors.ru>
|
8
|
+
- Anton Ageev <anton@ageev.name>
|
9
|
+
- Samuel Tribehou <cracoucax@gmail.com>
|
10
|
+
- Marco Nenciarini <marco.nenciarini@devise.it>
|
11
|
+
- James Nobis <jnobis@jnobis.controldocs.com>
|
12
|
+
- quel <github@quelrod.net>
|
13
|
+
- Holger Amann <keeney@fehu.org>
|
14
|
+
- Maxim Dobriakov <closer.main@gmail.com>
|
15
|
+
- Michael Kimsal <mgkimsal@gmail.com>
|
16
|
+
- Jacob Coby <jcoby@portallabs.com>
|
17
|
+
- Neszt Tibor <neszt@tvnetwork.hu>
|
18
|
+
- Miroslav Kratochvil <exa.exa@gmail.com>
|
19
|
+
- Paul Gallagher <gallagher.paul@gmail.com>
|
20
|
+
- Alex C Jokela <ajokela@umn.edu>
|
21
|
+
- Peter Clark <pclark@umn.edu>
|
22
|
+
- Juga Paazmaya <olavic@gmail.com>
|
23
|
+
- Alexander Meindl <a.meindl@alphanodes.com
|
24
|
+
autorequire:
|
25
|
+
bindir: bin
|
26
|
+
cert_chain: []
|
27
|
+
date: 2022-07-29 00:00:00.000000000 Z
|
28
|
+
dependencies:
|
29
|
+
- !ruby/object:Gem::Dependency
|
30
|
+
name: rake
|
31
|
+
requirement: !ruby/object:Gem::Requirement
|
32
|
+
requirements:
|
33
|
+
- - ">="
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: '0'
|
36
|
+
type: :runtime
|
37
|
+
prerelease: false
|
38
|
+
version_requirements: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '0'
|
43
|
+
- !ruby/object:Gem::Dependency
|
44
|
+
name: pg
|
45
|
+
requirement: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - "~>"
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: 1.2.2
|
50
|
+
type: :runtime
|
51
|
+
prerelease: false
|
52
|
+
version_requirements: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - "~>"
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: 1.2.2
|
57
|
+
- !ruby/object:Gem::Dependency
|
58
|
+
name: postgres-pr
|
59
|
+
requirement: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - "~>"
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0.7'
|
64
|
+
type: :runtime
|
65
|
+
prerelease: false
|
66
|
+
version_requirements: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - "~>"
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0.7'
|
71
|
+
- !ruby/object:Gem::Dependency
|
72
|
+
name: ruby-mysql
|
73
|
+
requirement: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - "~>"
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '3.0'
|
78
|
+
type: :runtime
|
79
|
+
prerelease: false
|
80
|
+
version_requirements: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - "~>"
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '3.0'
|
85
|
+
- !ruby/object:Gem::Dependency
|
86
|
+
name: debug
|
87
|
+
requirement: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
type: :development
|
93
|
+
prerelease: false
|
94
|
+
version_requirements: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - ">="
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
- !ruby/object:Gem::Dependency
|
100
|
+
name: rubocop-minitest
|
101
|
+
requirement: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - ">="
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '0'
|
106
|
+
type: :development
|
107
|
+
prerelease: false
|
108
|
+
version_requirements: !ruby/object:Gem::Requirement
|
109
|
+
requirements:
|
110
|
+
- - ">="
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: '0'
|
113
|
+
- !ruby/object:Gem::Dependency
|
114
|
+
name: rubocop-performance
|
115
|
+
requirement: !ruby/object:Gem::Requirement
|
116
|
+
requirements:
|
117
|
+
- - ">="
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: '0'
|
120
|
+
type: :development
|
121
|
+
prerelease: false
|
122
|
+
version_requirements: !ruby/object:Gem::Requirement
|
123
|
+
requirements:
|
124
|
+
- - ">="
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
version: '0'
|
127
|
+
- !ruby/object:Gem::Dependency
|
128
|
+
name: test-unit
|
129
|
+
requirement: !ruby/object:Gem::Requirement
|
130
|
+
requirements:
|
131
|
+
- - "~>"
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: 3.5.3
|
134
|
+
type: :development
|
135
|
+
prerelease: false
|
136
|
+
version_requirements: !ruby/object:Gem::Requirement
|
137
|
+
requirements:
|
138
|
+
- - "~>"
|
139
|
+
- !ruby/object:Gem::Version
|
140
|
+
version: 3.5.3
|
141
|
+
description: Translates MySQL -> PostgreSQL
|
142
|
+
email: a.meindl@alphanodes.com
|
143
|
+
executables:
|
144
|
+
- mysql2psql
|
145
|
+
extensions: []
|
146
|
+
extra_rdoc_files: []
|
147
|
+
files:
|
148
|
+
- ".gitignore"
|
149
|
+
- MIT-LICENSE
|
150
|
+
- README.md
|
151
|
+
- Rakefile
|
152
|
+
- bin/mysql2psql
|
153
|
+
- lib/mysql2psql.rb
|
154
|
+
- lib/mysql2psql/connection.rb
|
155
|
+
- lib/mysql2psql/converter.rb
|
156
|
+
- lib/mysql2psql/mysql_reader.rb
|
157
|
+
- lib/mysql2psql/postgres_db_writer.rb
|
158
|
+
- lib/mysql2psql/postgres_file_writer.rb
|
159
|
+
- lib/mysql2psql/postgres_writer.rb
|
160
|
+
- lib/mysql2psql/version.rb
|
161
|
+
- lib/mysql2psql/writer.rb
|
162
|
+
- mysql2postgres.gemspec
|
163
|
+
- test/fixtures/config_all_options.yml
|
164
|
+
- test/fixtures/seed_integration_tests.sql
|
165
|
+
- test/integration/convert_to_db_test.rb
|
166
|
+
- test/integration/convert_to_file_test.rb
|
167
|
+
- test/integration/converter_test.rb
|
168
|
+
- test/integration/mysql_reader_base_test.rb
|
169
|
+
- test/integration/mysql_reader_test.rb
|
170
|
+
- test/integration/postgres_db_writer_base_test.rb
|
171
|
+
- test/test_helper.rb
|
172
|
+
- test/units/option_test.rb
|
173
|
+
- test/units/postgres_file_writer_test.rb
|
174
|
+
homepage: https://code.alphanodes.com/alphanodes/mysql2psql
|
175
|
+
licenses:
|
176
|
+
- MIT
|
177
|
+
metadata:
|
178
|
+
rubygems_mfa_required: 'true'
|
179
|
+
post_install_message:
|
180
|
+
rdoc_options:
|
181
|
+
- "--charset=UTF-8"
|
182
|
+
require_paths:
|
183
|
+
- lib
|
184
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
185
|
+
requirements:
|
186
|
+
- - ">="
|
187
|
+
- !ruby/object:Gem::Version
|
188
|
+
version: '2.7'
|
189
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
190
|
+
requirements:
|
191
|
+
- - ">="
|
192
|
+
- !ruby/object:Gem::Version
|
193
|
+
version: '0'
|
194
|
+
requirements: []
|
195
|
+
rubygems_version: 3.3.7
|
196
|
+
signing_key:
|
197
|
+
specification_version: 4
|
198
|
+
summary: MySQL to PostgreSQL Data Translation
|
199
|
+
test_files: []
|