sqlite2mysql 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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e4abd7634da6d7d4924ac5440ca84a74328e64e0
4
+ data.tar.gz: 673c82ad3762793877b8d8b9671439b80e51bd47
5
+ SHA512:
6
+ metadata.gz: 0a7bf80a0be02f3032275bffbf3510328f9618f6d88b08b294ba9a0277d1c3128ba6bd34ae056386ba487845d2f93cd20dfdb3574eb5c57d3cb37c0dc86971b3
7
+ data.tar.gz: b36b4cd35cdd4cb184fa16bb238ee4b221769d51e76d8969f8e95407711a43b0ca9573556002699b4e023a47de35dc0da34df238493c14fbed3a70ab45c37a71
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.gem
11
+ *.db
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.5
4
+ before_install: gem install bundler -v 1.10.6
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in sqlite2mysql.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Alexander Standke
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "sqlite2mysql"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/exe/sqlite2mysql ADDED
@@ -0,0 +1,78 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'mysql2'
4
+ require 'sqlite3'
5
+
6
+ puts 'Usage: sqlite2mysql sqlite_file.db [mysql_db_name]' if ARGV.size < 1
7
+
8
+ DATABASE = ARGV.first
9
+ SQL_DB_NAME = ARGV[1] || DATABASE.gsub(/[^0-9a-z]/i, '')
10
+
11
+ puts 'Collecting Sqlit3 Info' # ===============================================
12
+
13
+ db = SQLite3::Database.new DATABASE
14
+
15
+ schema = {}
16
+
17
+ tables = db.execute 'SELECT name FROM sqlite_master WHERE type="table"'
18
+
19
+ tables.flatten.each do |t|
20
+ columns = db.execute("pragma table_info(#{t})")
21
+
22
+ formatted_columns = []
23
+ columns.each do |col|
24
+ formatted_columns << { name: col[1],
25
+ type: col[2],
26
+ notnull: col[3],
27
+ default: col[4] }
28
+ end
29
+
30
+ schema[t] = formatted_columns
31
+ end
32
+
33
+ puts "Creating MySQL DB: #{SQL_DB_NAME}" # ====================================
34
+
35
+ RESERVED_WORDS = %w(key int)
36
+
37
+ def create_table_query(table, columns)
38
+ query = "CREATE TABLE #{table} ("
39
+ cols = []
40
+ columns.each do |col|
41
+ col[:name] += '_1' if RESERVED_WORDS.include?(col[:name])
42
+ if col[:type] == ''
43
+ col[:type] = 'varchar(255)'
44
+ elsif col[:type].start_with?('float')
45
+ col[:type] = 'float'
46
+ end
47
+ cols << "#{col[:name]} #{col[:type]} #{'NOT NULL' if col[:notnull]}"
48
+ end
49
+ query + "#{cols.join(', ')})"
50
+ end
51
+
52
+ client = Mysql2::Client.new(host: 'localhost', username: 'root')
53
+
54
+ client.query("DROP DATABASE IF EXISTS #{SQL_DB_NAME}")
55
+ client.query("CREATE DATABASE #{SQL_DB_NAME}")
56
+ client.query("USE #{SQL_DB_NAME}")
57
+
58
+ schema.keys.each do |table|
59
+ puts "Creating table: #{table}"
60
+ client.query(create_table_query(table, schema[table]))
61
+ end
62
+
63
+ print 'Grab a ☕' # ============================================================
64
+
65
+ schema.keys.each do |table|
66
+ puts "\nInserting data: #{table}"
67
+ data = db.execute("select * from #{table}")
68
+ data.each_slice(1000) do |slice|
69
+ slice.each do |row|
70
+ cleaned_row = row.map do |val|
71
+ val.is_a?(String) ? client.escape(val) : val
72
+ end
73
+ client.query("INSERT INTO #{table} VALUES (\"#{cleaned_row.join('", "')}\")")
74
+ end
75
+ print '.'
76
+ end
77
+ end
78
+ puts ''
@@ -0,0 +1,3 @@
1
+ module Sqlite2mysql
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,3 @@
1
+ require 'sqlite2mysql/version'
2
+
3
+ puts 'WARNING: Including sqlite2mysql does nothing, run it from the terminal.'
data/readme.md ADDED
File without changes
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'sqlite2mysql/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'sqlite2mysql'
8
+ spec.version = Sqlite2mysql::VERSION
9
+ spec.authors = ['Alexander Standke']
10
+ spec.email = ['xanderstrike@gmail.com']
11
+
12
+ spec.summary = 'Simple tool to convert sqlite3 to mysql'
13
+ spec.description = "Call `sqlite2mysql sqlite_file.db [mysqlname]`\nIf not specified, mysqlname will be the sqlite filename"
14
+ spec.homepage = 'https://github.com/XanderStrike/sqlite2mysql'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = 'exe'
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ['lib']
21
+
22
+ spec.add_development_dependency 'bundler', '~> 1.10'
23
+ spec.add_development_dependency 'rake', '~> 10.0'
24
+ spec.add_development_dependency 'rspec', '~> 3.0'
25
+ spec.add_runtime_dependency 'mysql2', '~> 0'
26
+ spec.add_runtime_dependency 'sqlite3', '~> 1'
27
+ end
metadata ADDED
@@ -0,0 +1,130 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sqlite2mysql
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Alexander Standke
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-09-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: mysql2
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: sqlite3
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1'
83
+ description: |-
84
+ Call `sqlite2mysql sqlite_file.db [mysqlname]`
85
+ If not specified, mysqlname will be the sqlite filename
86
+ email:
87
+ - xanderstrike@gmail.com
88
+ executables:
89
+ - sqlite2mysql
90
+ extensions: []
91
+ extra_rdoc_files: []
92
+ files:
93
+ - ".gitignore"
94
+ - ".rspec"
95
+ - ".travis.yml"
96
+ - Gemfile
97
+ - LICENSE.txt
98
+ - Rakefile
99
+ - bin/console
100
+ - bin/setup
101
+ - exe/sqlite2mysql
102
+ - lib/sqlite2mysql.rb
103
+ - lib/sqlite2mysql/version.rb
104
+ - readme.md
105
+ - sqlite2mysql.gemspec
106
+ homepage: https://github.com/XanderStrike/sqlite2mysql
107
+ licenses:
108
+ - MIT
109
+ metadata: {}
110
+ post_install_message:
111
+ rdoc_options: []
112
+ require_paths:
113
+ - lib
114
+ required_ruby_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ required_rubygems_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ requirements: []
125
+ rubyforge_project:
126
+ rubygems_version: 2.4.3
127
+ signing_key:
128
+ specification_version: 4
129
+ summary: Simple tool to convert sqlite3 to mysql
130
+ test_files: []