convert_memory_engine 1.0.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 +7 -0
- data/.gitignore +23 -0
- data/.rspec +1 -0
- data/Gemfile +10 -0
- data/Guardfile +16 -0
- data/LICENSE.txt +22 -0
- data/README.md +30 -0
- data/Rakefile +1 -0
- data/convert_memory_engine.gemspec +26 -0
- data/lib/convert_memory_engine.rb +5 -0
- data/lib/convert_memory_engine/version.rb +3 -0
- data/lib/railtie.rb +10 -0
- data/lib/tasks/convert_memory_engine.rake +25 -0
- data/spec/config/database.yml +10 -0
- data/spec/convert_spec.rb +42 -0
- metadata +91 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 01d475d1b9a92645b10ac5658588955312bbc5eb
|
4
|
+
data.tar.gz: 184bb2980a697b1ab590aa314c363ff542992703
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c3d666970838927fb0828b12f832283c1d3d6db638cf8bc45bdddc4030a48e150e1811ad5709a588c905ecd8d3426fd0688a79375ebebc7bbb2c8516611e302c
|
7
|
+
data.tar.gz: 694372da9d04f59f1e65205c8c74b425817dbceae207e3e6b4f962fe934f118e0246d903e6e1c94f6edbb1a350e3d299ab212b3c87409bd7e10351e70f4554ec
|
data/.gitignore
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
23
|
+
*.swp
|
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color --format doc
|
data/Gemfile
ADDED
data/Guardfile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# A sample Guardfile
|
2
|
+
# More info at https://github.com/guard/guard#readme
|
3
|
+
|
4
|
+
# Note: The cmd option is now required due to the increasing number of ways
|
5
|
+
# rspec may be run, below are examples of the most common uses.
|
6
|
+
# * bundler: 'bundle exec rspec'
|
7
|
+
# * bundler binstubs: 'bin/rspec'
|
8
|
+
# * spring: 'bin/rsspec' (This will use spring if running and you have
|
9
|
+
# installed the spring binstubs per the docs)
|
10
|
+
# * zeus: 'zeus rspec' (requires the server to be started separetly)
|
11
|
+
# * 'just' rspec: 'rspec'
|
12
|
+
guard :rspec, cmd: 'bundle exec rspec' do
|
13
|
+
watch(%r{^spec/.+_spec\.rb$})
|
14
|
+
watch(%r{^tasks/(.+)\.task$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
|
15
|
+
end
|
16
|
+
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 wangfan
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# ConvertMemoryEngine
|
2
|
+
|
3
|
+
When i use rspec to do a lot of test, each time database is inserted data and truncate table, when tables grows the speed grow down too much. At first i convert the db engine from innodb to memory in db/seed.rb file. After that i write this gem to do the job for more app.
|
4
|
+
Notice: Tables those contain text col can not convert to memory engine, so i convert those colums to string first. So if there are test case use too long string to insert, there would be trouble.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
gem 'convert_memory_engine'
|
11
|
+
|
12
|
+
And then execute:
|
13
|
+
|
14
|
+
$ bundle
|
15
|
+
|
16
|
+
Or install it yourself as:
|
17
|
+
|
18
|
+
$ gem install convert_memory_engine
|
19
|
+
|
20
|
+
## Usage
|
21
|
+
|
22
|
+
rake convert_memory_engine RAILS_ENV=test
|
23
|
+
|
24
|
+
## Contributing
|
25
|
+
|
26
|
+
1. Fork it ( https://github.com/superwf/convert_memory_engine/fork )
|
27
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
28
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
29
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
30
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'convert_memory_engine/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "convert_memory_engine"
|
8
|
+
spec.version = ConvertMemoryEngine::VERSION
|
9
|
+
spec.authors = ["wangfan"]
|
10
|
+
spec.email = ["wangfan@chgb.org.cn"]
|
11
|
+
spec.summary = %q{speed up rails test by mysql.}
|
12
|
+
spec.description = %q{
|
13
|
+
When i use rspec to do a lot of test, each time database is inserted data and truncate table, when tables grows the speed grow down too much. At first i convert the db engine from innodb to memory in db/seed.rb file. After that i write this gem to do the job for more app.
|
14
|
+
Notice: Tables those contain text col can not convert to memory engine, so i convert those colums to string first. So if there are test case use too long string to insert, there would be trouble.
|
15
|
+
}
|
16
|
+
spec.homepage = "http://wangfan.bj.cn"
|
17
|
+
spec.license = "MIT"
|
18
|
+
|
19
|
+
spec.files = `git ls-files -z`.split("\x0")
|
20
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
21
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
22
|
+
spec.require_paths = ["lib"]
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
25
|
+
spec.add_development_dependency "rake"
|
26
|
+
end
|
data/lib/railtie.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'rails'
|
2
|
+
env_file = File.join(Rails.root, 'config/environment')
|
3
|
+
require env_file if File.exists?("#{env_file}.rb")
|
4
|
+
desc 'convert mysql tables engine to memory in test database'
|
5
|
+
task :convert_memory_engine do
|
6
|
+
db = ::ActiveRecord::Base.connection
|
7
|
+
if ::Rails.env.test?
|
8
|
+
tables = db.tables
|
9
|
+
tables.delete 'schema_migrations'
|
10
|
+
tables.each do |t|
|
11
|
+
begin
|
12
|
+
model_class = eval(t.classify)
|
13
|
+
model_class.columns.each do |c|
|
14
|
+
db.execute "ALTER TABLE #{t} CHANGE #{c.name} #{c.name} VARCHAR(255)" if c.type == :text
|
15
|
+
end
|
16
|
+
rescue
|
17
|
+
puts "table #{t} not converted, because no model for table #{t}"
|
18
|
+
end
|
19
|
+
db.execute "ALTER TABLE #{t} ENGINE = MEMORY"
|
20
|
+
puts "table #{t} converts success"
|
21
|
+
end
|
22
|
+
else
|
23
|
+
raise "only in test mode"
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'rspec'
|
2
|
+
require 'rails'
|
3
|
+
require 'active_record'
|
4
|
+
require 'rake'
|
5
|
+
require 'yaml'
|
6
|
+
|
7
|
+
class Testmodel < ActiveRecord::Base
|
8
|
+
end
|
9
|
+
|
10
|
+
describe 'test convert task' do
|
11
|
+
before :all do
|
12
|
+
config = YAML.load_file(File.join(Dir.pwd, 'spec/config/database.yml'))
|
13
|
+
ActiveRecord::Base.establish_connection config['test']
|
14
|
+
@db = ActiveRecord::Base.connection
|
15
|
+
@table_name = Testmodel.table_name
|
16
|
+
@db.execute %Q{
|
17
|
+
CREATE TABLE `test`.`#{@table_name}` (
|
18
|
+
`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
|
19
|
+
`name` VARCHAR( 255 ) NOT NULL,
|
20
|
+
`profile` text NULL
|
21
|
+
) ENGINE = InnoDB;
|
22
|
+
}
|
23
|
+
end
|
24
|
+
|
25
|
+
after :all do
|
26
|
+
@db.execute %Q{DROP TABLE `test`.`#{@table_name}`}
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'test the engine' do
|
30
|
+
table_info = @db.exec_query "SHOW TABLE STATUS WHERE name = '#{@table_name}'"
|
31
|
+
expect(table_info.rows[0][1]).to eq('InnoDB')
|
32
|
+
app = Rake.application
|
33
|
+
allow(Rails).to receive(:root).and_return('spec')
|
34
|
+
env = double('env')
|
35
|
+
allow(env).to receive(:test?).and_return(true)
|
36
|
+
allow(Rails).to receive(:env).and_return(env)
|
37
|
+
load File.join(Dir.pwd, 'lib/tasks/convert_memory_engine.rake')
|
38
|
+
app['convert_memory_engine'].invoke
|
39
|
+
table_info = @db.exec_query "SHOW TABLE STATUS WHERE name = '#{@table_name}'"
|
40
|
+
expect(table_info.rows[0][1]).to eq('MEMORY')
|
41
|
+
end
|
42
|
+
end
|
metadata
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: convert_memory_engine
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- wangfan
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-08-19 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.6'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: |2
|
42
|
+
|
43
|
+
When i use rspec to do a lot of test, each time database is inserted data and truncate table, when tables grows the speed grow down too much. At first i convert the db engine from innodb to memory in db/seed.rb file. After that i write this gem to do the job for more app.
|
44
|
+
Notice: Tables those contain text col can not convert to memory engine, so i convert those colums to string first. So if there are test case use too long string to insert, there would be trouble.
|
45
|
+
email:
|
46
|
+
- wangfan@chgb.org.cn
|
47
|
+
executables: []
|
48
|
+
extensions: []
|
49
|
+
extra_rdoc_files: []
|
50
|
+
files:
|
51
|
+
- ".gitignore"
|
52
|
+
- ".rspec"
|
53
|
+
- Gemfile
|
54
|
+
- Guardfile
|
55
|
+
- LICENSE.txt
|
56
|
+
- README.md
|
57
|
+
- Rakefile
|
58
|
+
- convert_memory_engine.gemspec
|
59
|
+
- lib/convert_memory_engine.rb
|
60
|
+
- lib/convert_memory_engine/version.rb
|
61
|
+
- lib/railtie.rb
|
62
|
+
- lib/tasks/convert_memory_engine.rake
|
63
|
+
- spec/config/database.yml
|
64
|
+
- spec/convert_spec.rb
|
65
|
+
homepage: http://wangfan.bj.cn
|
66
|
+
licenses:
|
67
|
+
- MIT
|
68
|
+
metadata: {}
|
69
|
+
post_install_message:
|
70
|
+
rdoc_options: []
|
71
|
+
require_paths:
|
72
|
+
- lib
|
73
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
requirements: []
|
84
|
+
rubyforge_project:
|
85
|
+
rubygems_version: 2.2.2
|
86
|
+
signing_key:
|
87
|
+
specification_version: 4
|
88
|
+
summary: speed up rails test by mysql.
|
89
|
+
test_files:
|
90
|
+
- spec/config/database.yml
|
91
|
+
- spec/convert_spec.rb
|