mysql2postgres 0.3.2 → 0.3.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +10 -10
- data/Rakefile +2 -2
- data/bin/{mysql2psql → mysql2postgres} +3 -2
- data/lib/{mysql2psql → mysql2postgres}/connection.rb +1 -1
- data/lib/{mysql2psql → mysql2postgres}/converter.rb +2 -2
- data/lib/{mysql2psql → mysql2postgres}/mysql_reader.rb +1 -1
- data/lib/{mysql2psql → mysql2postgres}/postgres_db_writer.rb +3 -3
- data/lib/{mysql2psql → mysql2postgres}/postgres_file_writer.rb +2 -2
- data/lib/{mysql2psql → mysql2postgres}/postgres_writer.rb +2 -2
- data/lib/mysql2postgres/version.rb +5 -0
- data/lib/{mysql2psql → mysql2postgres}/writer.rb +1 -1
- data/lib/{mysql2psql.rb → mysql2postgres.rb} +10 -8
- data/mysql2postgres.gemspec +15 -15
- data/test/integration/convert_to_db_test.rb +5 -5
- data/test/integration/convert_to_file_test.rb +3 -3
- data/test/integration/converter_test.rb +1 -1
- data/test/integration/mysql_reader_base_test.rb +3 -3
- data/test/integration/postgres_db_writer_base_test.rb +1 -1
- data/test/test_helper.rb +17 -18
- data/test/units/option_test.rb +1 -1
- data/test/units/postgres_file_writer_test.rb +2 -2
- metadata +13 -13
- data/lib/mysql2psql/version.rb +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 44c431dce8b1d09c5ebef95e6f1a56dbc2d7b79e67b594821d9a33c287d5d2b5
|
4
|
+
data.tar.gz: cf5352e91abcd255f2286a95a5a0c3c1dadae5cd3804f0914ea8dee999e27f4d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 34cce30cf4cffd22bc21e0be57267da80f5806ebeebfcd2934acb6f306af79ba5da512065a8acd5367964a5af00265cea9b3c5cfbacc1f6e7425412300613420
|
7
|
+
data.tar.gz: 72c40e74f83546cac80b33e8b22ecb7f8035ec15ace7a572d95373c83ce4055fde7809f52f7a0608fb7a426197d4c6a71cb39f815f3719f1a52adaf1ade266a2
|
data/README.md
CHANGED
@@ -1,20 +1,20 @@
|
|
1
|
-
#
|
1
|
+
# mysql2postgres - MySQL to PostgreSQL Data Translation
|
2
2
|
|
3
|
-
[![Run Linters](https://github.com/AlphaNodes/
|
3
|
+
[![Run Linters](https://github.com/AlphaNodes/mysql2postgres/workflows/Run%20Rubocop/badge.svg)](https://github.com/AlphaNodes/mysql2postgres/actions/workflows/rubocop.yml) [![Run Tests](https://github.com/AlphaNodes/mysql2postgres/workflows/Tests/badge.svg)](https://github.com/AlphaNodes/mysql2postgres/actions/workflows/tests.yml)
|
4
4
|
|
5
5
|
The minimum Ruby version supported in `main` branch is `2.7`,
|
6
6
|
and the next release will have the same requirement.
|
7
7
|
|
8
|
-
|
8
|
+
## Requirements
|
9
|
+
|
10
|
+
- Ruby `>= 2.7` (only maintained ruby versions are supported)
|
9
11
|
|
10
12
|
## Installation
|
11
13
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
gem build mysql2postgres.gemspec
|
17
|
-
sudo gem install mysql2postgres-0.3.2.gem
|
14
|
+
Add Gem to your Gemfile:
|
15
|
+
|
16
|
+
```ruby
|
17
|
+
gem 'mysql2postgres'
|
18
18
|
```
|
19
19
|
|
20
20
|
## Configuration
|
@@ -31,7 +31,7 @@ After providing settings, start migration with
|
|
31
31
|
|
32
32
|
```sh
|
33
33
|
|
34
|
-
bundle exec
|
34
|
+
bundle exec mysql2postgres
|
35
35
|
```
|
36
36
|
|
37
37
|
## Tests
|
data/Rakefile
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
require 'rubygems'
|
4
4
|
require 'rake'
|
5
5
|
|
6
|
-
require_relative 'lib/
|
6
|
+
require_relative 'lib/mysql2postgres/version'
|
7
7
|
|
8
8
|
require 'rake/testtask'
|
9
9
|
namespace :test do
|
@@ -44,7 +44,7 @@ task default: :test
|
|
44
44
|
require 'rdoc/task'
|
45
45
|
Rake::RDocTask.new do |rdoc|
|
46
46
|
rdoc.rdoc_dir = 'rdoc'
|
47
|
-
rdoc.title = "
|
47
|
+
rdoc.title = "Mysql2postgres #{Mysql2postgres::VERSION}"
|
48
48
|
rdoc.rdoc_files.include 'README*'
|
49
49
|
rdoc.rdoc_files.include 'lib/**/*.rb'
|
50
50
|
end
|
@@ -5,7 +5,7 @@ $LOAD_PATH.unshift File.join(File.dirname(__dir__), 'lib')
|
|
5
5
|
|
6
6
|
require 'rubygems'
|
7
7
|
require 'bundler/setup'
|
8
|
-
require '
|
8
|
+
require 'mysql2postgres'
|
9
9
|
|
10
10
|
CONFIG_FILE = File.join File.dirname(__dir__), 'config', 'database.yml'
|
11
11
|
|
@@ -20,7 +20,8 @@ unless FileTest.exist?(CONFIG_FILE) || (ARGV.length.positive? && FileTest.exist?
|
|
20
20
|
end
|
21
21
|
|
22
22
|
db_yaml = YAML.safe_load File.read(file)
|
23
|
+
|
23
24
|
raise "'#{file}' does not contain a mysql configuration directive for conversion" unless db_yaml.key? 'mysql'
|
24
25
|
raise "'#{file}' does not contain a destination configuration directive for conversion" unless db_yaml.key? 'destination'
|
25
26
|
|
26
|
-
|
27
|
+
Mysql2postgres.new(db_yaml).convert
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
class
|
3
|
+
class Mysql2postgres
|
4
4
|
class Converter
|
5
5
|
attr_reader :reader,
|
6
6
|
:writer,
|
@@ -86,7 +86,7 @@ class Mysql2psql
|
|
86
86
|
writer.inload
|
87
87
|
0
|
88
88
|
rescue StandardError => e
|
89
|
-
warn "
|
89
|
+
warn "mysql2postgres: Conversion failed: #{e}"
|
90
90
|
warn e
|
91
91
|
warn e.backtrace[0, 3].join("\n")
|
92
92
|
-1
|
@@ -1,9 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require '
|
4
|
-
require '
|
3
|
+
require 'mysql2postgres/postgres_writer'
|
4
|
+
require 'mysql2postgres/connection'
|
5
5
|
|
6
|
-
class
|
6
|
+
class Mysql2postgres
|
7
7
|
class PostgresDbWriter < PostgresFileWriter
|
8
8
|
attr_reader :connection, :filename
|
9
9
|
|
@@ -1,9 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'zlib'
|
4
|
-
require '
|
4
|
+
require 'mysql2postgres/writer'
|
5
5
|
|
6
|
-
class
|
6
|
+
class Mysql2postgres
|
7
7
|
class PostgresWriter < Writer
|
8
8
|
def column_description(column)
|
9
9
|
"#{PG::Connection.quote_ident column[:name]} #{column_type_info column}"
|
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'yaml'
|
4
|
+
|
3
5
|
require 'pg'
|
4
6
|
require 'pg_ext'
|
5
7
|
require 'pg/exceptions'
|
@@ -7,17 +9,17 @@ require 'pg/constants'
|
|
7
9
|
require 'pg/connection'
|
8
10
|
require 'pg/result'
|
9
11
|
|
10
|
-
require '
|
11
|
-
require '
|
12
|
-
require '
|
13
|
-
require '
|
14
|
-
require '
|
15
|
-
require '
|
16
|
-
require '
|
12
|
+
require 'mysql2postgres/version'
|
13
|
+
require 'mysql2postgres/converter'
|
14
|
+
require 'mysql2postgres/mysql_reader'
|
15
|
+
require 'mysql2postgres/writer'
|
16
|
+
require 'mysql2postgres/postgres_writer'
|
17
|
+
require 'mysql2postgres/postgres_file_writer'
|
18
|
+
require 'mysql2postgres/postgres_db_writer'
|
17
19
|
|
18
20
|
require 'debug' if ENV.fetch('ENABLE_DEBUG', nil) == '1'
|
19
21
|
|
20
|
-
class
|
22
|
+
class Mysql2postgres
|
21
23
|
attr_reader :options, :reader, :writer
|
22
24
|
|
23
25
|
def initialize(yaml)
|
data/mysql2postgres.gemspec
CHANGED
@@ -3,11 +3,11 @@
|
|
3
3
|
lib = File.expand_path '../lib', __FILE__
|
4
4
|
puts lib
|
5
5
|
$LOAD_PATH.unshift lib unless $LOAD_PATH.include? lib
|
6
|
-
require '
|
6
|
+
require 'mysql2postgres/version'
|
7
7
|
|
8
8
|
Gem::Specification.new do |s|
|
9
9
|
s.name = 'mysql2postgres'
|
10
|
-
s.version =
|
10
|
+
s.version = Mysql2postgres::VERSION
|
11
11
|
s.licenses = ['MIT']
|
12
12
|
|
13
13
|
s.authors = [
|
@@ -32,7 +32,7 @@ Gem::Specification.new do |s|
|
|
32
32
|
s.description = 'Translates MySQL -> PostgreSQL'
|
33
33
|
s.email = 'a.meindl@alphanodes.com'
|
34
34
|
s.metadata = { 'rubygems_mfa_required' => 'true' }
|
35
|
-
s.executables = ['
|
35
|
+
s.executables = ['mysql2postgres']
|
36
36
|
s.required_ruby_version = '>= 2.7'
|
37
37
|
|
38
38
|
s.files = [
|
@@ -40,17 +40,17 @@ Gem::Specification.new do |s|
|
|
40
40
|
'MIT-LICENSE',
|
41
41
|
'README.md',
|
42
42
|
'Rakefile',
|
43
|
-
'bin/
|
44
|
-
'lib/
|
45
|
-
'lib/
|
46
|
-
'lib/
|
47
|
-
'lib/
|
48
|
-
'lib/
|
49
|
-
'lib/
|
50
|
-
'lib/
|
51
|
-
'lib/
|
52
|
-
'lib/
|
53
|
-
'lib/
|
43
|
+
'bin/mysql2postgres',
|
44
|
+
'lib/mysql2postgres.rb',
|
45
|
+
'lib/mysql2postgres/converter.rb',
|
46
|
+
'lib/mysql2postgres/connection.rb',
|
47
|
+
'lib/mysql2postgres/mysql_reader.rb',
|
48
|
+
'lib/mysql2postgres/postgres_db_writer.rb',
|
49
|
+
'lib/mysql2postgres/postgres_file_writer.rb',
|
50
|
+
'lib/mysql2postgres/postgres_db_writer.rb',
|
51
|
+
'lib/mysql2postgres/postgres_writer.rb',
|
52
|
+
'lib/mysql2postgres/version.rb',
|
53
|
+
'lib/mysql2postgres/writer.rb',
|
54
54
|
'mysql2postgres.gemspec',
|
55
55
|
'test/fixtures/config_all_options.yml',
|
56
56
|
'test/fixtures/seed_integration_tests.sql',
|
@@ -64,7 +64,7 @@ Gem::Specification.new do |s|
|
|
64
64
|
'test/units/postgres_file_writer_test.rb',
|
65
65
|
'test/test_helper.rb'
|
66
66
|
]
|
67
|
-
s.homepage = 'https://code.alphanodes.com/alphanodes/
|
67
|
+
s.homepage = 'https://code.alphanodes.com/alphanodes/mysql2postgres'
|
68
68
|
s.rdoc_options = ['--charset=UTF-8']
|
69
69
|
s.require_paths = ['lib']
|
70
70
|
s.summary = 'MySQL to PostgreSQL Data Translation'
|
@@ -7,17 +7,17 @@ class ConvertToDbTest < Test::Unit::TestCase
|
|
7
7
|
def startup
|
8
8
|
seed_test_database
|
9
9
|
@options = get_test_config_by_label :localmysql_to_db_convert_all
|
10
|
-
@
|
11
|
-
@
|
12
|
-
@
|
10
|
+
@mysql2postgres = Mysql2postgres.new @options
|
11
|
+
@mysql2postgres.convert
|
12
|
+
@mysql2postgres.writer.open
|
13
13
|
end
|
14
14
|
|
15
15
|
def shutdown
|
16
|
-
@@
|
16
|
+
@@mysql2postgres.writer.close
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
20
|
def test_table_creation
|
21
|
-
assert_true @
|
21
|
+
assert_true @mysql2postgres.writer.exists?('numeric_types_basics')
|
22
22
|
end
|
23
23
|
end
|
@@ -7,9 +7,9 @@ class ConvertToFileTest < Test::Unit::TestCase
|
|
7
7
|
def startup
|
8
8
|
seed_test_database
|
9
9
|
@options = get_test_config_by_label :localmysql_to_file_convert_all
|
10
|
-
@
|
11
|
-
@
|
12
|
-
@content = File.read @
|
10
|
+
@mysql2postgres = Mysql2postgres.new @options
|
11
|
+
@mysql2postgres.convert
|
12
|
+
@content = File.read @mysql2postgres.options[:destfile]
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
@@ -14,7 +14,7 @@ class ConverterTest < Test::Unit::TestCase
|
|
14
14
|
assert_nothing_raised do
|
15
15
|
reader = get_test_reader @options
|
16
16
|
writer = get_test_file_writer @options
|
17
|
-
converter =
|
17
|
+
converter = Mysql2postgres::Converter.new reader, writer, @options
|
18
18
|
assert_equal 0, converter.convert
|
19
19
|
end
|
20
20
|
end
|
@@ -12,13 +12,13 @@ class MysqlReaderBaseTest < Test::Unit::TestCase
|
|
12
12
|
|
13
13
|
def test_mysql_connection
|
14
14
|
assert_nothing_raised do
|
15
|
-
|
15
|
+
mysql2postgres::MysqlReader.new @options
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
19
|
def test_mysql_reconnect
|
20
20
|
assert_nothing_raised do
|
21
|
-
reader =
|
21
|
+
reader = mysql2postgres::MysqlReader.new @options
|
22
22
|
reader.reconnect
|
23
23
|
end
|
24
24
|
end
|
@@ -27,7 +27,7 @@ class MysqlReaderBaseTest < Test::Unit::TestCase
|
|
27
27
|
assert_nothing_raised do
|
28
28
|
@options[:mysql][:port] = ''
|
29
29
|
@options[:mysql][:socket] = ''
|
30
|
-
|
30
|
+
mysql2postgres::MysqlReader.new @options
|
31
31
|
end
|
32
32
|
end
|
33
33
|
end
|
@@ -12,7 +12,7 @@ class PostgresDbWriterBaseTest < Test::Unit::TestCase
|
|
12
12
|
|
13
13
|
def test_pg_connection
|
14
14
|
assert_nothing_raised do
|
15
|
-
|
15
|
+
mysql2postgres::PostgresDbWriter.new Tempfile.new('mysql2postgres_test_').path, @options
|
16
16
|
end
|
17
17
|
end
|
18
18
|
end
|
data/test/test_helper.rb
CHANGED
@@ -4,13 +4,13 @@ require 'rubygems'
|
|
4
4
|
require 'test/unit'
|
5
5
|
require 'debug' if ENV.fetch('ENABLE_DEBUG', nil) == '1'
|
6
6
|
|
7
|
-
require File.expand_path('../lib/
|
8
|
-
require File.expand_path('../lib/
|
9
|
-
require File.expand_path('../lib/
|
10
|
-
require File.expand_path('../lib/
|
11
|
-
require File.expand_path('../lib/
|
12
|
-
require File.expand_path('../lib/
|
13
|
-
require File.expand_path('../lib/
|
7
|
+
require File.expand_path('../lib/mysql2postgres/version', __dir__)
|
8
|
+
require File.expand_path('../lib/mysql2postgres/converter', __dir__)
|
9
|
+
require File.expand_path('../lib/mysql2postgres/mysql_reader', __dir__)
|
10
|
+
require File.expand_path('../lib/mysql2postgres/writer', __dir__)
|
11
|
+
require File.expand_path('../lib/mysql2postgres/postgres_writer', __dir__)
|
12
|
+
require File.expand_path('../lib/mysql2postgres/postgres_file_writer', __dir__)
|
13
|
+
require File.expand_path('../lib/mysql2postgres/postgres_db_writer', __dir__)
|
14
14
|
|
15
15
|
def seed_test_database
|
16
16
|
options = get_test_config_by_label :localmysql_to_file_convert_nothing
|
@@ -24,25 +24,25 @@ rescue StandardError
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def get_test_reader(options)
|
27
|
-
require '
|
28
|
-
|
27
|
+
require 'mysql2postgres/mysql_reader'
|
28
|
+
mysql2postgres::MysqlReader.new options
|
29
29
|
rescue StandardError
|
30
30
|
raise 'Failed to initialize integration test db. See README for setup requirements.'
|
31
31
|
end
|
32
32
|
|
33
33
|
def get_test_file_writer(options)
|
34
|
-
require '
|
35
|
-
|
34
|
+
require 'mysql2postgres/postgres_file_writer'
|
35
|
+
mysql2postgres::PostgresFileWriter.new options[:destfile]
|
36
36
|
rescue StandardError => e
|
37
37
|
puts e.inspect
|
38
38
|
raise "Failed to initialize file writer from #{options.inspect}. See README for setup requirements."
|
39
39
|
end
|
40
40
|
|
41
41
|
def get_test_converter(options)
|
42
|
-
require '
|
42
|
+
require 'mysql2postgres/converter'
|
43
43
|
reader = get_test_reader options
|
44
44
|
writer = get_test_file_writer options
|
45
|
-
|
45
|
+
mysql2postgres::Converter.new reader, writer, options
|
46
46
|
rescue StandardError
|
47
47
|
raise "Failed to initialize converter from #{options.inspect}. See README for setup requirements."
|
48
48
|
end
|
@@ -58,13 +58,12 @@ end
|
|
58
58
|
def get_new_test_config(include_tables: [], exclude_tables: [], to_file: false,
|
59
59
|
suppress_data: false, suppress_ddl: false, force_truncate: false)
|
60
60
|
|
61
|
-
to_filename = to_file ? get_temp_file(['
|
62
|
-
|
63
|
-
|
64
|
-
configfile = get_temp_file 'mysql2psql_tmp_config'
|
61
|
+
to_filename = to_file ? get_temp_file(['mysql2postgres_tmp_output_', '.yml']) : nil
|
62
|
+
configtext = Mysql2postgres::Config.template to_filename, include_tables, exclude_tables, suppress_data, suppress_ddl, force_truncate
|
63
|
+
configfile = get_temp_file 'mysql2postgres_tmp_config'
|
65
64
|
File.open(configfile, 'w:UTF-8') { |f| f.write(configtext) }
|
66
65
|
yaml = YAML.load_file configfile
|
67
|
-
|
66
|
+
Mysql2postgres::ConfigBase.new yaml
|
68
67
|
rescue StandardError
|
69
68
|
raise "Failed to initialize options from #{configfile}. See README for setup requirements."
|
70
69
|
end
|
data/test/units/option_test.rb
CHANGED
@@ -6,7 +6,7 @@ class PostgresFileWriterTest < Test::Unit::TestCase
|
|
6
6
|
attr_accessor :destfile
|
7
7
|
|
8
8
|
def setup
|
9
|
-
@destfile = get_temp_file '
|
9
|
+
@destfile = get_temp_file 'mysql2postgres_test_destfile'
|
10
10
|
rescue StandardError
|
11
11
|
raise 'Failed to initialize integration test db. See README for setup requirements.'
|
12
12
|
end
|
@@ -16,7 +16,7 @@ class PostgresFileWriterTest < Test::Unit::TestCase
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def test_basic_write
|
19
|
-
writer =
|
19
|
+
writer = Mysql2postgres::PostgresFileWriter.new destfile
|
20
20
|
writer.close
|
21
21
|
content = File.read destfile
|
22
22
|
assert_not_nil content.match("SET client_encoding = 'UTF8'")
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mysql2postgres
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Max Lapshin <max@maxidoors.ru>
|
@@ -141,7 +141,7 @@ dependencies:
|
|
141
141
|
description: Translates MySQL -> PostgreSQL
|
142
142
|
email: a.meindl@alphanodes.com
|
143
143
|
executables:
|
144
|
-
-
|
144
|
+
- mysql2postgres
|
145
145
|
extensions: []
|
146
146
|
extra_rdoc_files: []
|
147
147
|
files:
|
@@ -149,16 +149,16 @@ files:
|
|
149
149
|
- MIT-LICENSE
|
150
150
|
- README.md
|
151
151
|
- Rakefile
|
152
|
-
- bin/
|
153
|
-
- lib/
|
154
|
-
- lib/
|
155
|
-
- lib/
|
156
|
-
- lib/
|
157
|
-
- lib/
|
158
|
-
- lib/
|
159
|
-
- lib/
|
160
|
-
- lib/
|
161
|
-
- lib/
|
152
|
+
- bin/mysql2postgres
|
153
|
+
- lib/mysql2postgres.rb
|
154
|
+
- lib/mysql2postgres/connection.rb
|
155
|
+
- lib/mysql2postgres/converter.rb
|
156
|
+
- lib/mysql2postgres/mysql_reader.rb
|
157
|
+
- lib/mysql2postgres/postgres_db_writer.rb
|
158
|
+
- lib/mysql2postgres/postgres_file_writer.rb
|
159
|
+
- lib/mysql2postgres/postgres_writer.rb
|
160
|
+
- lib/mysql2postgres/version.rb
|
161
|
+
- lib/mysql2postgres/writer.rb
|
162
162
|
- mysql2postgres.gemspec
|
163
163
|
- test/fixtures/config_all_options.yml
|
164
164
|
- test/fixtures/seed_integration_tests.sql
|
@@ -171,7 +171,7 @@ files:
|
|
171
171
|
- test/test_helper.rb
|
172
172
|
- test/units/option_test.rb
|
173
173
|
- test/units/postgres_file_writer_test.rb
|
174
|
-
homepage: https://code.alphanodes.com/alphanodes/
|
174
|
+
homepage: https://code.alphanodes.com/alphanodes/mysql2postgres
|
175
175
|
licenses:
|
176
176
|
- MIT
|
177
177
|
metadata:
|