dump 1.2.2 → 1.3.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 +4 -4
- data/.github/dependabot.yml +6 -0
- data/.github/workflows/check.yml +102 -0
- data/.github/workflows/rubocop.yml +16 -0
- data/.rubocop.yml +24 -1
- data/.rubocop_todo.yml +27 -29
- data/Appraisals +59 -21
- data/Gemfile +6 -4
- data/LICENSE.txt +1 -1
- data/README.markdown +6 -6
- data/dump.gemspec +7 -4
- data/lib/dump/capistrano/v2.rb +21 -23
- data/lib/dump/continious_timeout.rb +4 -6
- data/lib/dump/env/filter.rb +1 -0
- data/lib/dump/env.rb +7 -7
- data/lib/dump/reader.rb +3 -5
- data/lib/dump/snapshot.rb +24 -31
- data/lib/dump/table_manipulation.rb +7 -7
- data/lib/dump/writer.rb +40 -27
- data/lib/tasks/assets.rake +1 -1
- data/lib/tasks/dump.rake +5 -5
- data/spec/.gitignore +2 -0
- data/spec/cycle_spec.rb +14 -22
- data/spec/dummy-2.3/config/initializers/abstract_mysql2_adapter.rb +4 -0
- data/spec/dummy-3.1/config/initializers/abstract_mysql2_adapter.rb +4 -0
- data/spec/dummy-3.2/config/initializers/abstract_mysql2_adapter.rb +4 -0
- data/spec/dummy-4.0/config/initializers/abstract_mysql2_adapter.rb +4 -0
- data/spec/dummy-4.1/config/initializers/abstract_mysql2_adapter.rb +4 -0
- data/spec/dummy-4.2/config/initializers/abstract_mysql2_adapter.rb +4 -0
- data/spec/dummy-6.0/.gitignore +28 -0
- data/spec/dummy-6.0/config/application.rb +35 -0
- data/spec/dummy-6.0/config/boot.rb +5 -0
- data/spec/dummy-6.0/config/cable.yml +10 -0
- data/spec/{dummy-3.0 → dummy-6.0}/config/database.yml +13 -10
- data/spec/dummy-6.0/config/environment.rb +5 -0
- data/spec/dummy-6.0/config/environments/development.rb +55 -0
- data/spec/dummy-6.0/config/environments/production.rb +106 -0
- data/spec/dummy-6.0/config/environments/test.rb +48 -0
- data/spec/dummy-6.0/config/initializers/application_controller_renderer.rb +8 -0
- data/spec/dummy-6.0/config/initializers/content_security_policy.rb +28 -0
- data/spec/dummy-6.0/config/initializers/cookies_serializer.rb +5 -0
- data/spec/dummy-6.0/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/dummy-6.0/config/initializers/inflections.rb +16 -0
- data/spec/{dummy-3.0 → dummy-6.0}/config/initializers/mime_types.rb +0 -1
- data/spec/dummy-6.0/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy-6.0/config/locales/en.yml +33 -0
- data/spec/dummy-6.0/config/puma.rb +38 -0
- data/spec/dummy-6.0/config/routes.rb +3 -0
- data/spec/dummy-6.0/config/spring.rb +6 -0
- data/spec/dummy-6.0/config/storage.yml +34 -0
- data/spec/dummy-6.0/config.ru +5 -0
- data/spec/dummy-6.0/db/seeds.rb +7 -0
- data/spec/dummy-6.0/log/.keep +0 -0
- data/spec/dummy-6.0/storage/.keep +0 -0
- data/spec/dummy-6.1/.gitattributes +8 -0
- data/spec/dummy-6.1/.gitignore +33 -0
- data/spec/dummy-6.1/config/application.rb +38 -0
- data/spec/dummy-6.1/config/boot.rb +5 -0
- data/spec/dummy-6.1/config/cable.yml +10 -0
- data/spec/dummy-6.1/config/database.yml +25 -0
- data/spec/dummy-6.1/config/environment.rb +5 -0
- data/spec/dummy-6.1/config/environments/development.rb +69 -0
- data/spec/dummy-6.1/config/environments/production.rb +114 -0
- data/spec/dummy-6.1/config/environments/test.rb +60 -0
- data/spec/dummy-6.1/config/initializers/application_controller_renderer.rb +8 -0
- data/spec/dummy-6.1/config/initializers/backtrace_silencers.rb +8 -0
- data/spec/dummy-6.1/config/initializers/content_security_policy.rb +28 -0
- data/spec/dummy-6.1/config/initializers/cookies_serializer.rb +5 -0
- data/spec/dummy-6.1/config/initializers/filter_parameter_logging.rb +6 -0
- data/spec/dummy-6.1/config/initializers/inflections.rb +16 -0
- data/spec/dummy-6.1/config/initializers/mime_types.rb +4 -0
- data/spec/dummy-6.1/config/initializers/permissions_policy.rb +11 -0
- data/spec/dummy-6.1/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy-6.1/config/locales/en.yml +33 -0
- data/spec/dummy-6.1/config/puma.rb +43 -0
- data/spec/dummy-6.1/config/routes.rb +3 -0
- data/spec/dummy-6.1/config/spring.rb +6 -0
- data/spec/dummy-6.1/config/storage.yml +34 -0
- data/spec/dummy-6.1/config.ru +6 -0
- data/spec/dummy-6.1/db/seeds.rb +7 -0
- data/spec/dummy-6.1/log/.keep +0 -0
- data/spec/dummy-6.1/storage/.keep +0 -0
- data/spec/dummy-7.0/.gitattributes +7 -0
- data/spec/dummy-7.0/.gitignore +35 -0
- data/spec/dummy-7.0/config/application.rb +37 -0
- data/spec/dummy-7.0/config/boot.rb +3 -0
- data/spec/dummy-7.0/config/cable.yml +10 -0
- data/spec/dummy-7.0/config/database.yml +25 -0
- data/spec/dummy-7.0/config/environment.rb +5 -0
- data/spec/dummy-7.0/config/environments/development.rb +70 -0
- data/spec/dummy-7.0/config/environments/production.rb +93 -0
- data/spec/dummy-7.0/config/environments/test.rb +60 -0
- data/spec/dummy-7.0/config/initializers/assets.rb +12 -0
- data/spec/dummy-7.0/config/initializers/content_security_policy.rb +25 -0
- data/spec/dummy-7.0/config/initializers/filter_parameter_logging.rb +8 -0
- data/spec/dummy-7.0/config/initializers/inflections.rb +16 -0
- data/spec/dummy-7.0/config/initializers/permissions_policy.rb +11 -0
- data/spec/dummy-7.0/config/locales/en.yml +33 -0
- data/spec/dummy-7.0/config/puma.rb +43 -0
- data/spec/dummy-7.0/config/routes.rb +6 -0
- data/spec/dummy-7.0/config/storage.yml +34 -0
- data/spec/dummy-7.0/config.ru +6 -0
- data/spec/dummy-7.0/db/seeds.rb +7 -0
- data/spec/dummy-7.0/log/.keep +0 -0
- data/spec/dummy-7.0/storage/.keep +0 -0
- data/spec/dummy-7.1/.gitattributes +9 -0
- data/spec/dummy-7.1/.gitignore +35 -0
- data/spec/dummy-7.1/Dockerfile +58 -0
- data/spec/dummy-7.1/config/application.rb +42 -0
- data/spec/dummy-7.1/config/boot.rb +3 -0
- data/spec/dummy-7.1/config/cable.yml +10 -0
- data/spec/dummy-7.1/config/database.yml +25 -0
- data/spec/dummy-7.1/config/environment.rb +5 -0
- data/spec/dummy-7.1/config/environments/development.rb +76 -0
- data/spec/dummy-7.1/config/environments/production.rb +97 -0
- data/spec/dummy-7.1/config/environments/test.rb +64 -0
- data/spec/dummy-7.1/config/initializers/assets.rb +12 -0
- data/spec/dummy-7.1/config/initializers/content_security_policy.rb +25 -0
- data/spec/dummy-7.1/config/initializers/filter_parameter_logging.rb +8 -0
- data/spec/dummy-7.1/config/initializers/inflections.rb +16 -0
- data/spec/dummy-7.1/config/initializers/permissions_policy.rb +13 -0
- data/spec/dummy-7.1/config/locales/en.yml +31 -0
- data/spec/dummy-7.1/config/puma.rb +44 -0
- data/spec/dummy-7.1/config/routes.rb +10 -0
- data/spec/dummy-7.1/config/storage.yml +34 -0
- data/spec/dummy-7.1/config.ru +6 -0
- data/spec/dummy-7.1/db/seeds.rb +9 -0
- data/spec/dummy-7.1/log/.keep +0 -0
- data/spec/dummy-7.1/storage/.keep +0 -0
- data/spec/dummy-7.2/.gitattributes +9 -0
- data/spec/dummy-7.2/.gitignore +35 -0
- data/spec/dummy-7.2/.rubocop.yml +8 -0
- data/spec/dummy-7.2/Dockerfile +65 -0
- data/spec/dummy-7.2/config/application.rb +42 -0
- data/spec/dummy-7.2/config/boot.rb +3 -0
- data/spec/dummy-7.2/config/cable.yml +10 -0
- data/spec/dummy-7.2/config/database.yml +32 -0
- data/spec/dummy-7.2/config/environment.rb +5 -0
- data/spec/dummy-7.2/config/environments/development.rb +81 -0
- data/spec/dummy-7.2/config/environments/production.rb +105 -0
- data/spec/dummy-7.2/config/environments/test.rb +67 -0
- data/spec/dummy-7.2/config/initializers/assets.rb +12 -0
- data/spec/dummy-7.2/config/initializers/content_security_policy.rb +25 -0
- data/spec/dummy-7.2/config/initializers/filter_parameter_logging.rb +8 -0
- data/spec/dummy-7.2/config/initializers/inflections.rb +16 -0
- data/spec/dummy-7.2/config/initializers/permissions_policy.rb +13 -0
- data/spec/dummy-7.2/config/locales/en.yml +31 -0
- data/spec/dummy-7.2/config/puma.rb +34 -0
- data/spec/dummy-7.2/config/routes.rb +14 -0
- data/spec/dummy-7.2/config/storage.yml +34 -0
- data/spec/dummy-7.2/config.ru +6 -0
- data/spec/dummy-7.2/db/seeds.rb +9 -0
- data/spec/dummy-7.2/log/.keep +0 -0
- data/spec/dummy-7.2/storage/.keep +0 -0
- data/spec/dummy-8.0/.gitattributes +9 -0
- data/spec/dummy-8.0/.gitignore +34 -0
- data/spec/dummy-8.0/.rubocop.yml +8 -0
- data/spec/dummy-8.0/Dockerfile +68 -0
- data/spec/dummy-8.0/config/application.rb +42 -0
- data/spec/dummy-8.0/config/boot.rb +3 -0
- data/spec/dummy-8.0/config/cable.yml +10 -0
- data/spec/dummy-8.0/config/database.yml +41 -0
- data/spec/dummy-8.0/config/environment.rb +5 -0
- data/spec/dummy-8.0/config/environments/development.rb +72 -0
- data/spec/dummy-8.0/config/environments/production.rb +89 -0
- data/spec/dummy-8.0/config/environments/test.rb +53 -0
- data/spec/dummy-8.0/config/initializers/assets.rb +7 -0
- data/spec/dummy-8.0/config/initializers/content_security_policy.rb +25 -0
- data/spec/dummy-8.0/config/initializers/filter_parameter_logging.rb +8 -0
- data/spec/dummy-8.0/config/initializers/inflections.rb +16 -0
- data/spec/dummy-8.0/config/locales/en.yml +31 -0
- data/spec/dummy-8.0/config/puma.rb +41 -0
- data/spec/dummy-8.0/config/routes.rb +14 -0
- data/spec/dummy-8.0/config/storage.yml +34 -0
- data/spec/dummy-8.0/config.ru +6 -0
- data/spec/dummy-8.0/db/seeds.rb +9 -0
- data/spec/dummy-8.0/log/.keep +0 -0
- data/spec/dummy-8.0/storage/.keep +0 -0
- data/spec/dummy-8.1/.gitattributes +9 -0
- data/spec/dummy-8.1/.gitignore +35 -0
- data/spec/dummy-8.1/.rubocop.yml +8 -0
- data/spec/dummy-8.1/Dockerfile +71 -0
- data/spec/dummy-8.1/config/application.rb +42 -0
- data/spec/dummy-8.1/config/boot.rb +3 -0
- data/spec/dummy-8.1/config/bundler-audit.yml +5 -0
- data/spec/dummy-8.1/config/cable.yml +10 -0
- data/spec/dummy-8.1/config/ci.rb +19 -0
- data/spec/dummy-8.1/config/database.yml +40 -0
- data/spec/dummy-8.1/config/environment.rb +5 -0
- data/spec/dummy-8.1/config/environments/development.rb +78 -0
- data/spec/dummy-8.1/config/environments/production.rb +89 -0
- data/spec/dummy-8.1/config/environments/test.rb +53 -0
- data/spec/dummy-8.1/config/initializers/assets.rb +7 -0
- data/spec/dummy-8.1/config/initializers/content_security_policy.rb +29 -0
- data/spec/dummy-8.1/config/initializers/filter_parameter_logging.rb +8 -0
- data/spec/dummy-8.1/config/initializers/inflections.rb +16 -0
- data/spec/dummy-8.1/config/locales/en.yml +31 -0
- data/spec/dummy-8.1/config/puma.rb +42 -0
- data/spec/dummy-8.1/config/routes.rb +14 -0
- data/spec/dummy-8.1/config/storage.yml +27 -0
- data/spec/dummy-8.1/config.ru +6 -0
- data/spec/dummy-8.1/db/seeds.rb +9 -0
- data/spec/dummy-8.1/log/.keep +0 -0
- data/spec/dummy-8.1/storage/.keep +0 -0
- data/spec/dummy_rails_app.rb +1 -1
- data/spec/dump/env_spec.rb +8 -23
- data/spec/dump/reader_spec.rb +12 -14
- data/spec/dump/snapshot_spec.rb +9 -13
- data/spec/dump/table_manipulation_spec.rb +3 -3
- data/spec/dump/writer_spec.rb +7 -4
- data/spec/dump_spec.rb +5 -5
- data/spec/recipes/dump_spec.rb +40 -38
- data/spec/tasks/assets_spec.rb +3 -3
- metadata +395 -50
- data/.travis.database.yml +0 -14
- data/.travis.yml +0 -34
- data/.travis_check_rubies.yml +0 -1
- data/spec/dummy-3.0/.gitignore +0 -4
- data/spec/dummy-3.0/config/application.rb +0 -42
- data/spec/dummy-3.0/config/boot.rb +0 -6
- data/spec/dummy-3.0/config/environment.rb +0 -5
- data/spec/dummy-3.0/config/environments/development.rb +0 -26
- data/spec/dummy-3.0/config/environments/production.rb +0 -49
- data/spec/dummy-3.0/config/environments/test.rb +0 -35
- data/spec/dummy-3.0/config/initializers/inflections.rb +0 -10
- data/spec/dummy-3.0/config/initializers/secret_token.rb +0 -7
- data/spec/dummy-3.0/config/initializers/session_store.rb +0 -8
- data/spec/dummy-3.0/config/locales/en.yml +0 -5
- data/spec/dummy-3.0/config/routes.rb +0 -58
- data/spec/dummy-3.0/config.ru +0 -4
- data/spec/dummy-3.0/db/seeds.rb +0 -7
- /data/spec/{dummy-3.0 → dummy-6.0}/config/initializers/backtrace_silencers.rb +0 -0
|
@@ -23,12 +23,10 @@ module Dump
|
|
|
23
23
|
def self.timeout(sec)
|
|
24
24
|
x = Thread.current
|
|
25
25
|
y = Thread.start do
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
retry
|
|
31
|
-
end
|
|
26
|
+
begin
|
|
27
|
+
sleep sec
|
|
28
|
+
rescue RestartException
|
|
29
|
+
retry
|
|
32
30
|
end
|
|
33
31
|
x.raise TimeoutException, 'execution expired' if x.alive?
|
|
34
32
|
end
|
data/lib/dump/env/filter.rb
CHANGED
data/lib/dump/env.rb
CHANGED
|
@@ -44,7 +44,7 @@ module Dump
|
|
|
44
44
|
old = {}
|
|
45
45
|
hash.each do |key, value|
|
|
46
46
|
key = DICTIONARY[key].first if DICTIONARY[key]
|
|
47
|
-
old[key] = ENV
|
|
47
|
+
old[key] = ENV.fetch(key, nil)
|
|
48
48
|
ENV[key] = value
|
|
49
49
|
end
|
|
50
50
|
begin
|
|
@@ -58,7 +58,7 @@ module Dump
|
|
|
58
58
|
|
|
59
59
|
def with_clean_env(hash = {}, &block)
|
|
60
60
|
empty_env = {}
|
|
61
|
-
DICTIONARY.
|
|
61
|
+
DICTIONARY.each_key{ |key| empty_env[key] = nil }
|
|
62
62
|
with_env(empty_env.merge(hash), &block)
|
|
63
63
|
end
|
|
64
64
|
|
|
@@ -66,7 +66,7 @@ module Dump
|
|
|
66
66
|
if DICTIONARY[key]
|
|
67
67
|
ENV.values_at(*DICTIONARY[key]).compact.first
|
|
68
68
|
else
|
|
69
|
-
ENV
|
|
69
|
+
ENV.fetch(key, nil)
|
|
70
70
|
end
|
|
71
71
|
end
|
|
72
72
|
|
|
@@ -126,10 +126,10 @@ module Dump
|
|
|
126
126
|
end
|
|
127
127
|
|
|
128
128
|
def explain_variables_for_command(command)
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
129
|
+
lines = variable_names_for_command(command).map do |variable_name|
|
|
130
|
+
" #{DICTIONARY[variable_name].join(', ')} — #{EXPLANATIONS[variable_name]}\n"
|
|
131
|
+
end
|
|
132
|
+
".\n#{lines.join('')}"
|
|
133
133
|
end
|
|
134
134
|
|
|
135
135
|
private
|
data/lib/dump/reader.rb
CHANGED
|
@@ -89,11 +89,9 @@ module Dump
|
|
|
89
89
|
end
|
|
90
90
|
|
|
91
91
|
def open
|
|
92
|
-
Zlib::GzipReader.open(path) do |
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
yield(self)
|
|
96
|
-
end
|
|
92
|
+
Archive::Tar::Minitar.open(Zlib::GzipReader.open(path), 'r') do |stream|
|
|
93
|
+
@stream = stream
|
|
94
|
+
yield(self)
|
|
97
95
|
end
|
|
98
96
|
end
|
|
99
97
|
|
data/lib/dump/snapshot.rb
CHANGED
|
@@ -9,14 +9,15 @@ module Dump
|
|
|
9
9
|
# Base class for dump
|
|
10
10
|
class Snapshot
|
|
11
11
|
include TableManipulation
|
|
12
|
+
|
|
12
13
|
def self.list(options = {})
|
|
13
14
|
dumps = Dir[File.join(Dump.rails_root, 'dump', options[:all] ? '*.*' : '*.tgz')].sort.select{ |path| File.file?(path) }.map{ |path| new(path) }
|
|
14
15
|
dumps = dumps.select{ |dump| dump.name[options[:like]] } if options[:like]
|
|
15
16
|
if options[:tags]
|
|
16
17
|
tags = get_filter_tags(options[:tags])
|
|
17
|
-
dumps = dumps.select{ |dump|
|
|
18
|
-
dumps = dumps.select{ |dump| (dump.tags
|
|
19
|
-
dumps = dumps.reject{ |dump|
|
|
18
|
+
dumps = dumps.select{ |dump| tags[:any].intersect?(dump.tags.to_set) } if tags[:any].present?
|
|
19
|
+
dumps = dumps.select{ |dump| tags[:all].subset?(dump.tags.to_set) } if tags[:all].present?
|
|
20
|
+
dumps = dumps.reject{ |dump| tags[:none].intersect?(dump.tags.to_set) } if tags[:none].present?
|
|
20
21
|
end
|
|
21
22
|
dumps
|
|
22
23
|
end
|
|
@@ -57,17 +58,15 @@ module Dump
|
|
|
57
58
|
end
|
|
58
59
|
|
|
59
60
|
def parts
|
|
60
|
-
@parts ||=
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
{}
|
|
70
|
-
end
|
|
61
|
+
@parts ||= if (m = name.match(/^(\d{#{4 + 2 + 2 + 2 + 2 + 2}})(-[^@]+)?((?:@[^@]+)+)?\.(tmp|tgz)$/))
|
|
62
|
+
{
|
|
63
|
+
:time => m[1],
|
|
64
|
+
:desc => m[2] && m[2][1, m[2].length],
|
|
65
|
+
:tags => m[3] && m[3][1, m[3].length],
|
|
66
|
+
:ext => m[4],
|
|
67
|
+
}
|
|
68
|
+
else
|
|
69
|
+
{}
|
|
71
70
|
end
|
|
72
71
|
end
|
|
73
72
|
|
|
@@ -92,7 +91,7 @@ module Dump
|
|
|
92
91
|
end
|
|
93
92
|
alias_method :to_s, :name
|
|
94
93
|
|
|
95
|
-
def size
|
|
94
|
+
def size # rubocop:disable Naming/PredicateMethod
|
|
96
95
|
File.size?(path)
|
|
97
96
|
end
|
|
98
97
|
|
|
@@ -114,14 +113,8 @@ module Dump
|
|
|
114
113
|
end
|
|
115
114
|
|
|
116
115
|
def lock
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
if lock.flock(File::LOCK_EX | File::LOCK_NB)
|
|
120
|
-
yield
|
|
121
|
-
end
|
|
122
|
-
ensure
|
|
123
|
-
lock.flock(File::LOCK_UN)
|
|
124
|
-
lock.close
|
|
116
|
+
File.open(path, 'r') do |lock|
|
|
117
|
+
yield if lock.flock(File::LOCK_EX | File::LOCK_NB)
|
|
125
118
|
end
|
|
126
119
|
rescue Errno::ENOENT
|
|
127
120
|
nil
|
|
@@ -162,7 +155,7 @@ module Dump
|
|
|
162
155
|
end
|
|
163
156
|
|
|
164
157
|
def clean_tag(tag)
|
|
165
|
-
clean_str(tag).downcase.sub(
|
|
158
|
+
clean_str(tag).downcase.sub(/^-+/, '')[0, 20].strip
|
|
166
159
|
end
|
|
167
160
|
|
|
168
161
|
def clean_tags(tags)
|
|
@@ -170,21 +163,21 @@ module Dump
|
|
|
170
163
|
end
|
|
171
164
|
|
|
172
165
|
def get_filter_tags(tags)
|
|
173
|
-
groups = Hash.new{ |hash, key| hash[key] =
|
|
166
|
+
groups = Hash.new{ |hash, key| hash[key] = Set.new }
|
|
174
167
|
tags.to_s.split(',').each do |tag|
|
|
175
|
-
next unless (m = tag.strip.match(/^(
|
|
168
|
+
next unless (m = tag.strip.match(/^(-|\+)?(.*)$/))
|
|
176
169
|
|
|
177
|
-
type = {'+' => :
|
|
170
|
+
type = {'+' => :all, '-' => :none}[m[1]] || :any
|
|
178
171
|
next unless (cleaned_tag = clean_tag(m[2])).present?
|
|
179
172
|
|
|
180
173
|
groups[type] << cleaned_tag
|
|
181
174
|
end
|
|
182
|
-
[:
|
|
183
|
-
if (clashing = (groups[type] & groups[:
|
|
184
|
-
fail ArgumentError, "#{type} tags clashes with
|
|
175
|
+
[:any, :all].each do |type|
|
|
176
|
+
if (clashing = (groups[type] & groups[:none])).present?
|
|
177
|
+
fail ArgumentError, "#{type} tags clashes with none ones: #{clashing}"
|
|
185
178
|
end
|
|
186
179
|
end
|
|
187
|
-
groups
|
|
180
|
+
groups
|
|
188
181
|
end
|
|
189
182
|
end
|
|
190
183
|
include CleanNParse
|
|
@@ -153,14 +153,14 @@ module Dump
|
|
|
153
153
|
"#{quote_table_name(table)}.#{quote_column_name(primary_key)}"
|
|
154
154
|
case connection.adapter_name.downcase
|
|
155
155
|
when 'sqlserver'
|
|
156
|
-
"SELECT TOP #{chunk_size} * FROM #{quote_table_name(table)}" \
|
|
157
|
-
|
|
158
|
-
|
|
156
|
+
"SELECT TOP #{chunk_size} * FROM #{quote_table_name(table)} " \
|
|
157
|
+
"WHERE #{quoted_primary_key} %s " \
|
|
158
|
+
"ORDER BY #{quoted_primary_key} ASC"
|
|
159
159
|
else
|
|
160
|
-
"SELECT * FROM #{quote_table_name(table)}" \
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
160
|
+
"SELECT * FROM #{quote_table_name(table)} " \
|
|
161
|
+
"WHERE #{quoted_primary_key} %s " \
|
|
162
|
+
"ORDER BY #{quoted_primary_key} ASC " \
|
|
163
|
+
"LIMIT #{chunk_size}"
|
|
164
164
|
end
|
|
165
165
|
end
|
|
166
166
|
end
|
data/lib/dump/writer.rb
CHANGED
|
@@ -28,14 +28,13 @@ module Dump
|
|
|
28
28
|
|
|
29
29
|
def open
|
|
30
30
|
Pathname.new(path).dirname.mkpath
|
|
31
|
-
Zlib::GzipWriter.open(path)
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
end
|
|
31
|
+
gzip = Zlib::GzipWriter.open(path)
|
|
32
|
+
gzip.mtime = Time.utc(2000)
|
|
33
|
+
lock do
|
|
34
|
+
Archive::Tar::Minitar.open(gzip, 'w') do |stream|
|
|
35
|
+
@stream = stream
|
|
36
|
+
@config = {:tables => {}}
|
|
37
|
+
yield(self)
|
|
39
38
|
end
|
|
40
39
|
end
|
|
41
40
|
end
|
|
@@ -68,32 +67,15 @@ module Dump
|
|
|
68
67
|
def write_table(table)
|
|
69
68
|
row_count = table_row_count(table)
|
|
70
69
|
config[:tables][table] = row_count
|
|
71
|
-
Progress.start(table,
|
|
70
|
+
Progress.start(table, row_count + 1) do
|
|
72
71
|
create_file("#{table}.dump") do |f|
|
|
73
72
|
columns = table_columns(table)
|
|
74
73
|
column_names = columns.map(&:name).sort
|
|
75
|
-
|
|
74
|
+
type_cast = type_caster(columns)
|
|
76
75
|
|
|
77
76
|
Marshal.dump(column_names, f)
|
|
78
77
|
Progress.step
|
|
79
78
|
|
|
80
|
-
type_cast = case
|
|
81
|
-
when columns.first.respond_to?(:type_cast_from_database)
|
|
82
|
-
proc do |column_name, value|
|
|
83
|
-
columns_by_name[column_name].type_cast_from_database(value)
|
|
84
|
-
end
|
|
85
|
-
when columns.first.respond_to?(:type_cast)
|
|
86
|
-
proc do |column_name, value|
|
|
87
|
-
columns_by_name[column_name].type_cast(value)
|
|
88
|
-
end
|
|
89
|
-
when connection.respond_to?(:lookup_cast_type_from_column)
|
|
90
|
-
proc do |column_name, value|
|
|
91
|
-
connection.lookup_cast_type_from_column(columns_by_name[column_name]).deserialize(value)
|
|
92
|
-
end
|
|
93
|
-
else
|
|
94
|
-
fail 'Failed to determine the way to convert values from database input to the appropriate ruby type'
|
|
95
|
-
end
|
|
96
|
-
|
|
97
79
|
each_table_row(table, row_count) do |row|
|
|
98
80
|
values = column_names.map do |column_name|
|
|
99
81
|
type_cast.call(column_name, row[column_name])
|
|
@@ -141,5 +123,36 @@ module Dump
|
|
|
141
123
|
rescue
|
|
142
124
|
[]
|
|
143
125
|
end
|
|
126
|
+
|
|
127
|
+
private
|
|
128
|
+
|
|
129
|
+
def type_caster(columns)
|
|
130
|
+
columns_by_name = columns.index_by(&:name)
|
|
131
|
+
|
|
132
|
+
case
|
|
133
|
+
when columns.first.respond_to?(:type_cast_from_database)
|
|
134
|
+
proc do |column_name, value|
|
|
135
|
+
columns_by_name[column_name].type_cast_from_database(value)
|
|
136
|
+
end
|
|
137
|
+
when columns.first.respond_to?(:type_cast)
|
|
138
|
+
proc do |column_name, value|
|
|
139
|
+
columns_by_name[column_name].type_cast(value)
|
|
140
|
+
end
|
|
141
|
+
when connection.respond_to?(:lookup_cast_type_from_column)
|
|
142
|
+
proc do |column_name, value|
|
|
143
|
+
connection.lookup_cast_type_from_column(columns_by_name[column_name]).deserialize(value)
|
|
144
|
+
end
|
|
145
|
+
when columns.first.respond_to?(:fetch_cast_type)
|
|
146
|
+
proc do |column_name, value|
|
|
147
|
+
columns_by_name[column_name].fetch_cast_type(connection).deserialize(value)
|
|
148
|
+
end
|
|
149
|
+
when columns.first.respond_to?(:cast_type)
|
|
150
|
+
proc do |column_name, value|
|
|
151
|
+
columns_by_name[column_name].cast_type.deserialize(value)
|
|
152
|
+
end
|
|
153
|
+
else
|
|
154
|
+
fail 'Failed to determine the way to convert values from database input to the appropriate ruby type'
|
|
155
|
+
end
|
|
156
|
+
end
|
|
144
157
|
end
|
|
145
158
|
end
|
data/lib/tasks/assets.rake
CHANGED
|
@@ -7,7 +7,7 @@ task :assets do
|
|
|
7
7
|
end
|
|
8
8
|
|
|
9
9
|
namespace :assets do
|
|
10
|
-
desc
|
|
10
|
+
desc "Delete assets#{Dump::Env.explain_variables_for_command(:assets)}"
|
|
11
11
|
task :delete => :assets do
|
|
12
12
|
ENV['ASSETS'].split(':').each do |asset|
|
|
13
13
|
Dump::Assets.glob_asset_children(asset, '*').each do |child|
|
data/lib/tasks/dump.rake
CHANGED
|
@@ -2,26 +2,26 @@
|
|
|
2
2
|
|
|
3
3
|
require 'dump'
|
|
4
4
|
|
|
5
|
-
desc
|
|
5
|
+
desc "Short for dump:create#{Dump::Env.explain_variables_for_command(:create)}"
|
|
6
6
|
task :dump => 'dump:create'
|
|
7
7
|
|
|
8
8
|
namespace :dump do
|
|
9
|
-
desc
|
|
9
|
+
desc "Show avaliable versions#{Dump::Env.explain_variables_for_command(:versions)}"
|
|
10
10
|
task :versions => :environment do
|
|
11
11
|
Dump.versions(Dump::Env.for_command(:versions))
|
|
12
12
|
end
|
|
13
13
|
|
|
14
|
-
desc
|
|
14
|
+
desc "Create dump#{Dump::Env.explain_variables_for_command(:create)}"
|
|
15
15
|
task :create => :environment do
|
|
16
16
|
Dump.create(Dump::Env.for_command(:create))
|
|
17
17
|
end
|
|
18
18
|
|
|
19
|
-
desc
|
|
19
|
+
desc "Restore dump#{Dump::Env.explain_variables_for_command(:restore)}"
|
|
20
20
|
task :restore => :environment do
|
|
21
21
|
Dump.restore(Dump::Env.for_command(:restore))
|
|
22
22
|
end
|
|
23
23
|
|
|
24
|
-
desc
|
|
24
|
+
desc "Cleanup dumps#{Dump::Env.explain_variables_for_command(:cleanup)}"
|
|
25
25
|
task :cleanup => :environment do
|
|
26
26
|
Dump.cleanup(Dump::Env.for_command(:cleanup))
|
|
27
27
|
end
|
data/spec/.gitignore
CHANGED
data/spec/cycle_spec.rb
CHANGED
|
@@ -10,7 +10,7 @@ end
|
|
|
10
10
|
ActiveRecord::Base.logger = Logger.new(File.join(Dump.rails_root, 'log/dump.log'))
|
|
11
11
|
|
|
12
12
|
def database_configs
|
|
13
|
-
YAML.
|
|
13
|
+
YAML.load_file(File.expand_path('../db/database.yml', __FILE__))
|
|
14
14
|
end
|
|
15
15
|
|
|
16
16
|
def adapters
|
|
@@ -24,7 +24,7 @@ def use_adapter(adapter)
|
|
|
24
24
|
when /^mysql/
|
|
25
25
|
ActiveRecord::Base.establish_connection(config.merge('database' => nil))
|
|
26
26
|
ActiveRecord::Base.connection.drop_database config['database']
|
|
27
|
-
ActiveRecord::Base.connection.create_database(config['database'])
|
|
27
|
+
ActiveRecord::Base.connection.create_database(config['database'], :charset => 'utf8')
|
|
28
28
|
when /^postgresql/
|
|
29
29
|
ActiveRecord::Base.establish_connection(config.merge('database' => 'postgres', 'schema_search_path' => 'public'))
|
|
30
30
|
ActiveRecord::Base.connection.drop_database config['database']
|
|
@@ -102,22 +102,18 @@ def reset_rake!
|
|
|
102
102
|
Rake::Task.define_task('db:schema:dump') do
|
|
103
103
|
File.open(schema_path, 'r') do |r|
|
|
104
104
|
if ENV['SCHEMA']
|
|
105
|
-
File.
|
|
106
|
-
w.write(r.read)
|
|
107
|
-
end
|
|
105
|
+
File.write(ENV.fetch('SCHEMA', nil), r.read)
|
|
108
106
|
end
|
|
109
107
|
end
|
|
110
108
|
end
|
|
111
109
|
Rake::Task.define_task('db:schema:load') do
|
|
112
|
-
load(ENV
|
|
110
|
+
load(ENV.fetch('SCHEMA', nil))
|
|
113
111
|
end
|
|
114
112
|
end
|
|
115
113
|
|
|
116
|
-
def call_rake
|
|
114
|
+
def call_rake(&block)
|
|
117
115
|
reset_rake!
|
|
118
|
-
grab_output
|
|
119
|
-
yield
|
|
120
|
-
end
|
|
116
|
+
grab_output(&block)
|
|
121
117
|
end
|
|
122
118
|
|
|
123
119
|
def call_rake_create(*args)
|
|
@@ -171,9 +167,7 @@ describe 'full cycle' do
|
|
|
171
167
|
expect(chicken_data).to eq(saved_chicken_data)
|
|
172
168
|
end
|
|
173
169
|
end
|
|
174
|
-
end
|
|
175
170
|
|
|
176
|
-
adapters.each do |adapter|
|
|
177
171
|
it "does not break id incrementing using #{adapter}" do
|
|
178
172
|
use_adapter(adapter) do
|
|
179
173
|
create_chickens!(:random => 100)
|
|
@@ -185,7 +179,7 @@ describe 'full cycle' do
|
|
|
185
179
|
end
|
|
186
180
|
end
|
|
187
181
|
|
|
188
|
-
adapters.
|
|
182
|
+
adapters.permutation(2) do |adapter_src, adapter_dst|
|
|
189
183
|
it "dumps using #{adapter_src} and restores using #{adapter_dst}" do
|
|
190
184
|
saved_chicken_data = nil
|
|
191
185
|
use_adapter(adapter_src) do
|
|
@@ -213,16 +207,14 @@ describe 'full cycle' do
|
|
|
213
207
|
dump_path = File.join(Dump.rails_root, 'dump', dump_name)
|
|
214
208
|
|
|
215
209
|
data = []
|
|
216
|
-
Zlib::GzipReader.open(dump_path) do |
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
Marshal.load(entry.read)
|
|
223
|
-
end
|
|
224
|
-
data << [entry.full_name, entry_data]
|
|
210
|
+
Archive::Tar::Minitar.open(Zlib::GzipReader.open(dump_path), 'r') do |stream|
|
|
211
|
+
stream.each do |entry|
|
|
212
|
+
entry_data = if entry.full_name == 'schema.rb'
|
|
213
|
+
entry.read
|
|
214
|
+
else
|
|
215
|
+
Marshal.load(entry.read)
|
|
225
216
|
end
|
|
217
|
+
data << [entry.full_name, entry_data]
|
|
226
218
|
end
|
|
227
219
|
end
|
|
228
220
|
dumps << {:path => dump_path, :data => data.sort}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# See https://help.github.com/articles/ignoring-files for more about ignoring files.
|
|
2
|
+
#
|
|
3
|
+
# If you find yourself ignoring temporary files generated by your text editor
|
|
4
|
+
# or operating system, you probably want to add a global ignore instead:
|
|
5
|
+
# git config --global core.excludesfile '~/.gitignore_global'
|
|
6
|
+
|
|
7
|
+
# Ignore bundler config.
|
|
8
|
+
/.bundle
|
|
9
|
+
|
|
10
|
+
# Ignore the default SQLite database.
|
|
11
|
+
/db/*.sqlite3
|
|
12
|
+
/db/*.sqlite3-journal
|
|
13
|
+
|
|
14
|
+
# Ignore all logfiles and tempfiles.
|
|
15
|
+
/log/*
|
|
16
|
+
/tmp/*
|
|
17
|
+
!/log/.keep
|
|
18
|
+
!/tmp/.keep
|
|
19
|
+
|
|
20
|
+
# Ignore uploaded files in development.
|
|
21
|
+
/storage/*
|
|
22
|
+
!/storage/.keep
|
|
23
|
+
|
|
24
|
+
/public/assets
|
|
25
|
+
.byebug_history
|
|
26
|
+
|
|
27
|
+
# Ignore master key for decrypting credentials and more.
|
|
28
|
+
/config/master.key
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
require_relative 'boot'
|
|
2
|
+
|
|
3
|
+
require "rails"
|
|
4
|
+
# Pick the frameworks you want:
|
|
5
|
+
require "active_model/railtie"
|
|
6
|
+
require "active_job/railtie"
|
|
7
|
+
require "active_record/railtie"
|
|
8
|
+
require "active_storage/engine"
|
|
9
|
+
require "action_controller/railtie"
|
|
10
|
+
require "action_mailer/railtie"
|
|
11
|
+
require "action_mailbox/engine"
|
|
12
|
+
require "action_text/engine"
|
|
13
|
+
require "action_view/railtie"
|
|
14
|
+
require "action_cable/engine"
|
|
15
|
+
# require "sprockets/railtie"
|
|
16
|
+
# require "rails/test_unit/railtie"
|
|
17
|
+
|
|
18
|
+
# Require the gems listed in Gemfile, including any gems
|
|
19
|
+
# you've limited to :test, :development, or :production.
|
|
20
|
+
Bundler.require(*Rails.groups)
|
|
21
|
+
|
|
22
|
+
module Dummy60
|
|
23
|
+
class Application < Rails::Application
|
|
24
|
+
# Initialize configuration defaults for originally generated Rails version.
|
|
25
|
+
config.load_defaults 6.0
|
|
26
|
+
|
|
27
|
+
# Settings in config/environments/* take precedence over those specified here.
|
|
28
|
+
# Application configuration can go into files in config/initializers
|
|
29
|
+
# -- all .rb files in that directory are automatically loaded after loading
|
|
30
|
+
# the framework and any gems in your application.
|
|
31
|
+
|
|
32
|
+
# Don't generate system test files.
|
|
33
|
+
config.generators.system_tests = nil
|
|
34
|
+
end
|
|
35
|
+
end
|
|
@@ -1,22 +1,25 @@
|
|
|
1
|
-
# SQLite
|
|
1
|
+
# SQLite. Versions 3.8.0 and up are supported.
|
|
2
2
|
# gem install sqlite3
|
|
3
|
-
|
|
3
|
+
#
|
|
4
|
+
# Ensure the SQLite 3 gem is defined in your Gemfile
|
|
5
|
+
# gem 'sqlite3'
|
|
6
|
+
#
|
|
7
|
+
default: &default
|
|
4
8
|
adapter: sqlite3
|
|
5
|
-
|
|
6
|
-
pool: 5
|
|
9
|
+
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
|
|
7
10
|
timeout: 5000
|
|
8
11
|
|
|
12
|
+
development:
|
|
13
|
+
<<: *default
|
|
14
|
+
database: db/development.sqlite3
|
|
15
|
+
|
|
9
16
|
# Warning: The database defined as "test" will be erased and
|
|
10
17
|
# re-generated from your development database when you run "rake".
|
|
11
18
|
# Do not set this db to the same as development or production.
|
|
12
19
|
test:
|
|
13
|
-
|
|
20
|
+
<<: *default
|
|
14
21
|
database: db/test.sqlite3
|
|
15
|
-
pool: 5
|
|
16
|
-
timeout: 5000
|
|
17
22
|
|
|
18
23
|
production:
|
|
19
|
-
|
|
24
|
+
<<: *default
|
|
20
25
|
database: db/production.sqlite3
|
|
21
|
-
pool: 5
|
|
22
|
-
timeout: 5000
|