fast_innodb_import 0.0.1
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/History.txt +4 -0
- data/Manifest.txt +14 -0
- data/PostInstall.txt +7 -0
- data/README.rdoc +40 -0
- data/Rakefile +26 -0
- data/bin/fast_innodb_import +4 -0
- data/lib/fast_innodb_import.rb +122 -0
- data/script/console +10 -0
- data/script/destroy +14 -0
- data/script/generate +14 -0
- data/spec/fast_innodb_import_spec.rb +11 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +10 -0
- data/tasks/rspec.rake +21 -0
- metadata +125 -0
data/History.txt
ADDED
data/Manifest.txt
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
History.txt
|
2
|
+
Manifest.txt
|
3
|
+
PostInstall.txt
|
4
|
+
README.rdoc
|
5
|
+
Rakefile
|
6
|
+
lib/fast_innodb_import.rb
|
7
|
+
script/console
|
8
|
+
script/destroy
|
9
|
+
script/generate
|
10
|
+
spec/fast_innodb_import_spec.rb
|
11
|
+
spec/spec.opts
|
12
|
+
spec/spec_helper.rb
|
13
|
+
tasks/rspec.rake
|
14
|
+
bin/fast_innodb_import
|
data/PostInstall.txt
ADDED
data/README.rdoc
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
= fast_innodb_import
|
2
|
+
|
3
|
+
* http://github.com/dynport/fast_innodb_import
|
4
|
+
|
5
|
+
== DESCRIPTION:
|
6
|
+
|
7
|
+
Script to import mysqldumps (<table_name>.txt files created with option -T) with "disabled" keys (like DISABLE KEYS for MyISAM Tables)
|
8
|
+
|
9
|
+
== SYNOPSIS:
|
10
|
+
|
11
|
+
fast_innodb_import -u <username> -d <database_name> tracks.txt
|
12
|
+
|
13
|
+
== INSTALL:
|
14
|
+
|
15
|
+
* gem install fast_innodb_import
|
16
|
+
|
17
|
+
== LICENSE:
|
18
|
+
|
19
|
+
(The MIT License)
|
20
|
+
|
21
|
+
Copyright (c) 2010 Tobias Schwab
|
22
|
+
|
23
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
24
|
+
a copy of this software and associated documentation files (the
|
25
|
+
'Software'), to deal in the Software without restriction, including
|
26
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
27
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
28
|
+
permit persons to whom the Software is furnished to do so, subject to
|
29
|
+
the following conditions:
|
30
|
+
|
31
|
+
The above copyright notice and this permission notice shall be
|
32
|
+
included in all copies or substantial portions of the Software.
|
33
|
+
|
34
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
35
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
36
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
37
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
38
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
39
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
40
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
gem 'hoe', '>= 2.1.0'
|
3
|
+
require 'hoe'
|
4
|
+
require 'fileutils'
|
5
|
+
require './lib/fast_innodb_import'
|
6
|
+
|
7
|
+
Hoe.plugin :newgem
|
8
|
+
# Hoe.plugin :website
|
9
|
+
# Hoe.plugin :cucumberfeatures
|
10
|
+
|
11
|
+
# Generate all the Rake tasks
|
12
|
+
# Run 'rake -T' to see list of generated tasks (from gem root directory)
|
13
|
+
$hoe = Hoe.spec 'fast_innodb_import' do
|
14
|
+
self.developer 'Tobias Schwab', 'tobias.schwab@dynport.de'
|
15
|
+
self.post_install_message = 'PostInstall.txt' # TODO remove if post-install message not required
|
16
|
+
self.rubyforge_name = self.name # TODO this is default value
|
17
|
+
self.extra_deps = [['mysql2','>= 0.1.9']]
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
require 'newgem/tasks'
|
22
|
+
Dir['tasks/**/*.rake'].each { |t| load t }
|
23
|
+
|
24
|
+
# TODO - want other tests/tasks run by default? Add them to the list
|
25
|
+
# remove_task :default
|
26
|
+
# task :default => [:spec, :features]
|
@@ -0,0 +1,122 @@
|
|
1
|
+
$:.unshift(File.dirname(__FILE__)) unless
|
2
|
+
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
3
|
+
|
4
|
+
require "mysql2"
|
5
|
+
class FastInnodbImport
|
6
|
+
VERSION = '0.0.1'
|
7
|
+
CMD_MAPPING = { "u" => :username, "h" => :host, "d" => :database, "p" => "password" }
|
8
|
+
|
9
|
+
def initialize(argv = {})
|
10
|
+
@options = options_from_argv(argv)
|
11
|
+
end
|
12
|
+
|
13
|
+
def execute
|
14
|
+
print_usage_and_exit if missing_options?
|
15
|
+
file_paths.each do |path|
|
16
|
+
import_data_from_file_path(path)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
def index_definitions_from_table(table)
|
22
|
+
query("SHOW CREATE TABLE #{table}").to_a.first["Create Table"].split("\n").map do |line|
|
23
|
+
if line.match(/^\s*KEY \`(.*?)\` \((.*?)\)/)
|
24
|
+
{ :name => $1, :columns => $2 }
|
25
|
+
end
|
26
|
+
end.compact
|
27
|
+
end
|
28
|
+
|
29
|
+
def index_drop_statement_for_table(table_name)
|
30
|
+
"ALTER TABLE #{table_name} " + index_definitions_from_table(table_name).map { |config| "\nDROP INDEX #{config[:name]}" }.join(", ")
|
31
|
+
end
|
32
|
+
|
33
|
+
def index_create_statement_for_table(table_name)
|
34
|
+
"ALTER TABLE #{table_name} " + index_definitions_from_table(table_name).map { |config| "\nADD INDEX #{config[:name]} (#{config[:columns]})" }.join(", ")
|
35
|
+
end
|
36
|
+
|
37
|
+
def import_data_from_file_path(path)
|
38
|
+
file_path = File.expand_path(path)
|
39
|
+
return if !File.exists?(file_path)
|
40
|
+
table_name = table_name_from_file_path(file_path)
|
41
|
+
wc = `wc -l #{file_path}`.strip.to_i
|
42
|
+
started = Time.now
|
43
|
+
print "import %d rows from %s: " % [wc, file_path]
|
44
|
+
$stdout.flush
|
45
|
+
|
46
|
+
# create drop and create statements as long as we can
|
47
|
+
drop_statement = index_drop_statement_for_table(table_name)
|
48
|
+
create_statement = index_create_statement_for_table(table_name)
|
49
|
+
|
50
|
+
query("TRUNCATE `#{table_name}`")
|
51
|
+
|
52
|
+
# drop keys if asked
|
53
|
+
if drop_keys?
|
54
|
+
query(drop_statement)
|
55
|
+
end
|
56
|
+
|
57
|
+
query("LOAD DATA INFILE '#{file_path}' INTO TABLE `#{table_name}`")
|
58
|
+
|
59
|
+
# recreate keys if asked
|
60
|
+
if drop_keys?
|
61
|
+
query(create_statement)
|
62
|
+
end
|
63
|
+
|
64
|
+
# print stats
|
65
|
+
diff = Time.now - started
|
66
|
+
per_sec = wc / diff
|
67
|
+
puts "%d (%d/sec)" % [diff, per_sec]
|
68
|
+
end
|
69
|
+
|
70
|
+
def missing_options?
|
71
|
+
!file_paths.respond_to?(:empty?) || file_paths.empty?
|
72
|
+
end
|
73
|
+
|
74
|
+
def db_options
|
75
|
+
@options[:db] if @options
|
76
|
+
end
|
77
|
+
|
78
|
+
def table_name_from_file_path(path)
|
79
|
+
File.basename(path).gsub(".txt", "")
|
80
|
+
end
|
81
|
+
|
82
|
+
def file_paths
|
83
|
+
@options[:file_paths] if @options
|
84
|
+
end
|
85
|
+
|
86
|
+
def drop_keys?
|
87
|
+
@options[:drop_keys] if @options
|
88
|
+
end
|
89
|
+
|
90
|
+
def print_usage_and_exit
|
91
|
+
puts "Usage: #{File.basename(__FILE__)} [OPTIONS] [dumpfile]"
|
92
|
+
puts " -h Database Host"
|
93
|
+
puts " -u Database User"
|
94
|
+
puts " -d Database Schema Name"
|
95
|
+
puts " -p Database Password"
|
96
|
+
puts " --without-drop-keys Do not drop indexes before import"
|
97
|
+
exit
|
98
|
+
end
|
99
|
+
|
100
|
+
def options_from_argv(argv)
|
101
|
+
options = { :db => {} }
|
102
|
+
%w(u h d p).each do |key|
|
103
|
+
if idx = argv.index("-#{key}")
|
104
|
+
value = argv.at(idx + 1)
|
105
|
+
options[:db][CMD_MAPPING[key]] = value if !value.match(/^\-/)
|
106
|
+
argv.delete_at(idx)
|
107
|
+
argv.delete_at(idx)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
options[:drop_keys] = argv.delete("--without-drop-keys").nil?
|
111
|
+
options[:file_paths] = argv
|
112
|
+
options
|
113
|
+
end
|
114
|
+
|
115
|
+
def client
|
116
|
+
@client ||= Mysql2::Client.new(db_options || {})
|
117
|
+
end
|
118
|
+
|
119
|
+
def query(query)
|
120
|
+
client.query(query)
|
121
|
+
end
|
122
|
+
end
|
data/script/console
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# File: script/console
|
3
|
+
irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
|
4
|
+
|
5
|
+
libs = " -r irb/completion"
|
6
|
+
# Perhaps use a console_lib to store any extra methods I may want available in the cosole
|
7
|
+
# libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
|
8
|
+
libs << " -r #{File.dirname(__FILE__) + '/../lib/fast_innodb_import.rb'}"
|
9
|
+
puts "Loading fast_innodb_import gem"
|
10
|
+
exec "#{irb} #{libs} --simple-prompt"
|
data/script/destroy
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'rubigen'
|
6
|
+
rescue LoadError
|
7
|
+
require 'rubygems'
|
8
|
+
require 'rubigen'
|
9
|
+
end
|
10
|
+
require 'rubigen/scripts/destroy'
|
11
|
+
|
12
|
+
ARGV.shift if ['--help', '-h'].include?(ARGV[0])
|
13
|
+
RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
|
14
|
+
RubiGen::Scripts::Destroy.new.run(ARGV)
|
data/script/generate
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'rubigen'
|
6
|
+
rescue LoadError
|
7
|
+
require 'rubygems'
|
8
|
+
require 'rubigen'
|
9
|
+
end
|
10
|
+
require 'rubigen/scripts/generate'
|
11
|
+
|
12
|
+
ARGV.shift if ['--help', '-h'].include?(ARGV[0])
|
13
|
+
RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
|
14
|
+
RubiGen::Scripts::Generate.new.run(ARGV)
|
data/spec/spec.opts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--colour
|
data/spec/spec_helper.rb
ADDED
data/tasks/rspec.rake
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
begin
|
2
|
+
require 'spec'
|
3
|
+
rescue LoadError
|
4
|
+
require 'rubygems' unless ENV['NO_RUBYGEMS']
|
5
|
+
require 'spec'
|
6
|
+
end
|
7
|
+
begin
|
8
|
+
require 'spec/rake/spectask'
|
9
|
+
rescue LoadError
|
10
|
+
puts <<-EOS
|
11
|
+
To use rspec for testing you must install rspec gem:
|
12
|
+
gem install rspec
|
13
|
+
EOS
|
14
|
+
exit(0)
|
15
|
+
end
|
16
|
+
|
17
|
+
desc "Run the specs under spec/models"
|
18
|
+
Spec::Rake::SpecTask.new do |t|
|
19
|
+
t.spec_opts = ['--options', "spec/spec.opts"]
|
20
|
+
t.spec_files = FileList['spec/**/*_spec.rb']
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,125 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fast_innodb_import
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
version: 0.0.1
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Tobias Schwab
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-09-22 00:00:00 +02:00
|
18
|
+
default_executable: fast_innodb_import
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: mysql2
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
segments:
|
29
|
+
- 0
|
30
|
+
- 1
|
31
|
+
- 9
|
32
|
+
version: 0.1.9
|
33
|
+
type: :runtime
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: rubyforge
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
segments:
|
44
|
+
- 2
|
45
|
+
- 0
|
46
|
+
- 4
|
47
|
+
version: 2.0.4
|
48
|
+
type: :development
|
49
|
+
version_requirements: *id002
|
50
|
+
- !ruby/object:Gem::Dependency
|
51
|
+
name: hoe
|
52
|
+
prerelease: false
|
53
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
54
|
+
none: false
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
segments:
|
59
|
+
- 2
|
60
|
+
- 6
|
61
|
+
- 2
|
62
|
+
version: 2.6.2
|
63
|
+
type: :development
|
64
|
+
version_requirements: *id003
|
65
|
+
description: Script to import mysqldumps (<table_name>.txt files created with option -T) with "disabled" keys (like DISABLE KEYS for MyISAM Tables)
|
66
|
+
email:
|
67
|
+
- tobias.schwab@dynport.de
|
68
|
+
executables:
|
69
|
+
- fast_innodb_import
|
70
|
+
extensions: []
|
71
|
+
|
72
|
+
extra_rdoc_files:
|
73
|
+
- History.txt
|
74
|
+
- Manifest.txt
|
75
|
+
- PostInstall.txt
|
76
|
+
files:
|
77
|
+
- History.txt
|
78
|
+
- Manifest.txt
|
79
|
+
- PostInstall.txt
|
80
|
+
- README.rdoc
|
81
|
+
- Rakefile
|
82
|
+
- lib/fast_innodb_import.rb
|
83
|
+
- script/console
|
84
|
+
- script/destroy
|
85
|
+
- script/generate
|
86
|
+
- spec/fast_innodb_import_spec.rb
|
87
|
+
- spec/spec.opts
|
88
|
+
- spec/spec_helper.rb
|
89
|
+
- tasks/rspec.rake
|
90
|
+
- bin/fast_innodb_import
|
91
|
+
has_rdoc: true
|
92
|
+
homepage: http://github.com/dynport/fast_innodb_import
|
93
|
+
licenses: []
|
94
|
+
|
95
|
+
post_install_message: PostInstall.txt
|
96
|
+
rdoc_options:
|
97
|
+
- --main
|
98
|
+
- README.rdoc
|
99
|
+
require_paths:
|
100
|
+
- lib
|
101
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
102
|
+
none: false
|
103
|
+
requirements:
|
104
|
+
- - ">="
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
segments:
|
107
|
+
- 0
|
108
|
+
version: "0"
|
109
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
110
|
+
none: false
|
111
|
+
requirements:
|
112
|
+
- - ">="
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
segments:
|
115
|
+
- 0
|
116
|
+
version: "0"
|
117
|
+
requirements: []
|
118
|
+
|
119
|
+
rubyforge_project: fast_innodb_import
|
120
|
+
rubygems_version: 1.3.7
|
121
|
+
signing_key:
|
122
|
+
specification_version: 3
|
123
|
+
summary: Script to import mysqldumps (<table_name>.txt files created with option -T) with "disabled" keys (like DISABLE KEYS for MyISAM Tables)
|
124
|
+
test_files: []
|
125
|
+
|