dump 1.2.1 → 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.
Files changed (232) hide show
  1. checksums.yaml +4 -4
  2. data/.github/dependabot.yml +6 -0
  3. data/.github/workflows/check.yml +102 -0
  4. data/.github/workflows/rubocop.yml +16 -0
  5. data/.rubocop.yml +24 -1
  6. data/.rubocop_todo.yml +27 -29
  7. data/Appraisals +59 -21
  8. data/Gemfile +6 -4
  9. data/LICENSE.txt +1 -1
  10. data/README.markdown +6 -6
  11. data/dump.gemspec +8 -5
  12. data/lib/dump/capistrano/v2.rb +21 -23
  13. data/lib/dump/continious_timeout.rb +4 -6
  14. data/lib/dump/env/filter.rb +1 -0
  15. data/lib/dump/env.rb +7 -7
  16. data/lib/dump/reader.rb +3 -5
  17. data/lib/dump/snapshot.rb +24 -31
  18. data/lib/dump/table_manipulation.rb +8 -8
  19. data/lib/dump/writer.rb +40 -27
  20. data/lib/tasks/assets.rake +1 -1
  21. data/lib/tasks/dump.rake +5 -5
  22. data/spec/.gitignore +2 -0
  23. data/spec/cycle_spec.rb +14 -22
  24. data/spec/dummy-2.3/config/initializers/abstract_mysql2_adapter.rb +4 -0
  25. data/spec/dummy-3.1/config/initializers/abstract_mysql2_adapter.rb +4 -0
  26. data/spec/dummy-3.2/config/initializers/abstract_mysql2_adapter.rb +4 -0
  27. data/spec/dummy-4.0/config/initializers/abstract_mysql2_adapter.rb +4 -0
  28. data/spec/dummy-4.1/config/initializers/abstract_mysql2_adapter.rb +4 -0
  29. data/spec/dummy-4.2/config/initializers/abstract_mysql2_adapter.rb +4 -0
  30. data/spec/dummy-6.0/.gitignore +28 -0
  31. data/spec/dummy-6.0/config/application.rb +35 -0
  32. data/spec/dummy-6.0/config/boot.rb +5 -0
  33. data/spec/dummy-6.0/config/cable.yml +10 -0
  34. data/spec/{dummy-3.0 → dummy-6.0}/config/database.yml +13 -10
  35. data/spec/dummy-6.0/config/environment.rb +5 -0
  36. data/spec/dummy-6.0/config/environments/development.rb +55 -0
  37. data/spec/dummy-6.0/config/environments/production.rb +106 -0
  38. data/spec/dummy-6.0/config/environments/test.rb +48 -0
  39. data/spec/dummy-6.0/config/initializers/application_controller_renderer.rb +8 -0
  40. data/spec/dummy-6.0/config/initializers/content_security_policy.rb +28 -0
  41. data/spec/dummy-6.0/config/initializers/cookies_serializer.rb +5 -0
  42. data/spec/dummy-6.0/config/initializers/filter_parameter_logging.rb +4 -0
  43. data/spec/dummy-6.0/config/initializers/inflections.rb +16 -0
  44. data/spec/{dummy-3.0 → dummy-6.0}/config/initializers/mime_types.rb +0 -1
  45. data/spec/dummy-6.0/config/initializers/wrap_parameters.rb +14 -0
  46. data/spec/dummy-6.0/config/locales/en.yml +33 -0
  47. data/spec/dummy-6.0/config/puma.rb +38 -0
  48. data/spec/dummy-6.0/config/routes.rb +3 -0
  49. data/spec/dummy-6.0/config/spring.rb +6 -0
  50. data/spec/dummy-6.0/config/storage.yml +34 -0
  51. data/spec/dummy-6.0/config.ru +5 -0
  52. data/spec/dummy-6.0/db/seeds.rb +7 -0
  53. data/spec/dummy-6.0/log/.keep +0 -0
  54. data/spec/dummy-6.0/storage/.keep +0 -0
  55. data/spec/dummy-6.1/.gitattributes +8 -0
  56. data/spec/dummy-6.1/.gitignore +33 -0
  57. data/spec/dummy-6.1/config/application.rb +38 -0
  58. data/spec/dummy-6.1/config/boot.rb +5 -0
  59. data/spec/dummy-6.1/config/cable.yml +10 -0
  60. data/spec/dummy-6.1/config/database.yml +25 -0
  61. data/spec/dummy-6.1/config/environment.rb +5 -0
  62. data/spec/dummy-6.1/config/environments/development.rb +69 -0
  63. data/spec/dummy-6.1/config/environments/production.rb +114 -0
  64. data/spec/dummy-6.1/config/environments/test.rb +60 -0
  65. data/spec/dummy-6.1/config/initializers/application_controller_renderer.rb +8 -0
  66. data/spec/dummy-6.1/config/initializers/backtrace_silencers.rb +8 -0
  67. data/spec/dummy-6.1/config/initializers/content_security_policy.rb +28 -0
  68. data/spec/dummy-6.1/config/initializers/cookies_serializer.rb +5 -0
  69. data/spec/dummy-6.1/config/initializers/filter_parameter_logging.rb +6 -0
  70. data/spec/dummy-6.1/config/initializers/inflections.rb +16 -0
  71. data/spec/dummy-6.1/config/initializers/mime_types.rb +4 -0
  72. data/spec/dummy-6.1/config/initializers/permissions_policy.rb +11 -0
  73. data/spec/dummy-6.1/config/initializers/wrap_parameters.rb +14 -0
  74. data/spec/dummy-6.1/config/locales/en.yml +33 -0
  75. data/spec/dummy-6.1/config/puma.rb +43 -0
  76. data/spec/dummy-6.1/config/routes.rb +3 -0
  77. data/spec/dummy-6.1/config/spring.rb +6 -0
  78. data/spec/dummy-6.1/config/storage.yml +34 -0
  79. data/spec/dummy-6.1/config.ru +6 -0
  80. data/spec/dummy-6.1/db/seeds.rb +7 -0
  81. data/spec/dummy-6.1/log/.keep +0 -0
  82. data/spec/dummy-6.1/storage/.keep +0 -0
  83. data/spec/dummy-7.0/.gitattributes +7 -0
  84. data/spec/dummy-7.0/.gitignore +35 -0
  85. data/spec/dummy-7.0/config/application.rb +37 -0
  86. data/spec/dummy-7.0/config/boot.rb +3 -0
  87. data/spec/dummy-7.0/config/cable.yml +10 -0
  88. data/spec/dummy-7.0/config/database.yml +25 -0
  89. data/spec/dummy-7.0/config/environment.rb +5 -0
  90. data/spec/dummy-7.0/config/environments/development.rb +70 -0
  91. data/spec/dummy-7.0/config/environments/production.rb +93 -0
  92. data/spec/dummy-7.0/config/environments/test.rb +60 -0
  93. data/spec/dummy-7.0/config/initializers/assets.rb +12 -0
  94. data/spec/dummy-7.0/config/initializers/content_security_policy.rb +25 -0
  95. data/spec/dummy-7.0/config/initializers/filter_parameter_logging.rb +8 -0
  96. data/spec/dummy-7.0/config/initializers/inflections.rb +16 -0
  97. data/spec/dummy-7.0/config/initializers/permissions_policy.rb +11 -0
  98. data/spec/dummy-7.0/config/locales/en.yml +33 -0
  99. data/spec/dummy-7.0/config/puma.rb +43 -0
  100. data/spec/dummy-7.0/config/routes.rb +6 -0
  101. data/spec/dummy-7.0/config/storage.yml +34 -0
  102. data/spec/dummy-7.0/config.ru +6 -0
  103. data/spec/dummy-7.0/db/seeds.rb +7 -0
  104. data/spec/dummy-7.0/log/.keep +0 -0
  105. data/spec/dummy-7.0/storage/.keep +0 -0
  106. data/spec/dummy-7.1/.gitattributes +9 -0
  107. data/spec/dummy-7.1/.gitignore +35 -0
  108. data/spec/dummy-7.1/Dockerfile +58 -0
  109. data/spec/dummy-7.1/config/application.rb +42 -0
  110. data/spec/dummy-7.1/config/boot.rb +3 -0
  111. data/spec/dummy-7.1/config/cable.yml +10 -0
  112. data/spec/dummy-7.1/config/database.yml +25 -0
  113. data/spec/dummy-7.1/config/environment.rb +5 -0
  114. data/spec/dummy-7.1/config/environments/development.rb +76 -0
  115. data/spec/dummy-7.1/config/environments/production.rb +97 -0
  116. data/spec/dummy-7.1/config/environments/test.rb +64 -0
  117. data/spec/dummy-7.1/config/initializers/assets.rb +12 -0
  118. data/spec/dummy-7.1/config/initializers/content_security_policy.rb +25 -0
  119. data/spec/dummy-7.1/config/initializers/filter_parameter_logging.rb +8 -0
  120. data/spec/dummy-7.1/config/initializers/inflections.rb +16 -0
  121. data/spec/dummy-7.1/config/initializers/permissions_policy.rb +13 -0
  122. data/spec/dummy-7.1/config/locales/en.yml +31 -0
  123. data/spec/dummy-7.1/config/puma.rb +44 -0
  124. data/spec/dummy-7.1/config/routes.rb +10 -0
  125. data/spec/dummy-7.1/config/storage.yml +34 -0
  126. data/spec/dummy-7.1/config.ru +6 -0
  127. data/spec/dummy-7.1/db/seeds.rb +9 -0
  128. data/spec/dummy-7.1/log/.keep +0 -0
  129. data/spec/dummy-7.1/storage/.keep +0 -0
  130. data/spec/dummy-7.2/.gitattributes +9 -0
  131. data/spec/dummy-7.2/.gitignore +35 -0
  132. data/spec/dummy-7.2/.rubocop.yml +8 -0
  133. data/spec/dummy-7.2/Dockerfile +65 -0
  134. data/spec/dummy-7.2/config/application.rb +42 -0
  135. data/spec/dummy-7.2/config/boot.rb +3 -0
  136. data/spec/dummy-7.2/config/cable.yml +10 -0
  137. data/spec/dummy-7.2/config/database.yml +32 -0
  138. data/spec/dummy-7.2/config/environment.rb +5 -0
  139. data/spec/dummy-7.2/config/environments/development.rb +81 -0
  140. data/spec/dummy-7.2/config/environments/production.rb +105 -0
  141. data/spec/dummy-7.2/config/environments/test.rb +67 -0
  142. data/spec/dummy-7.2/config/initializers/assets.rb +12 -0
  143. data/spec/dummy-7.2/config/initializers/content_security_policy.rb +25 -0
  144. data/spec/dummy-7.2/config/initializers/filter_parameter_logging.rb +8 -0
  145. data/spec/dummy-7.2/config/initializers/inflections.rb +16 -0
  146. data/spec/dummy-7.2/config/initializers/permissions_policy.rb +13 -0
  147. data/spec/dummy-7.2/config/locales/en.yml +31 -0
  148. data/spec/dummy-7.2/config/puma.rb +34 -0
  149. data/spec/dummy-7.2/config/routes.rb +14 -0
  150. data/spec/dummy-7.2/config/storage.yml +34 -0
  151. data/spec/dummy-7.2/config.ru +6 -0
  152. data/spec/dummy-7.2/db/seeds.rb +9 -0
  153. data/spec/dummy-7.2/log/.keep +0 -0
  154. data/spec/dummy-7.2/storage/.keep +0 -0
  155. data/spec/dummy-8.0/.gitattributes +9 -0
  156. data/spec/dummy-8.0/.gitignore +34 -0
  157. data/spec/dummy-8.0/.rubocop.yml +8 -0
  158. data/spec/dummy-8.0/Dockerfile +68 -0
  159. data/spec/dummy-8.0/config/application.rb +42 -0
  160. data/spec/dummy-8.0/config/boot.rb +3 -0
  161. data/spec/dummy-8.0/config/cable.yml +10 -0
  162. data/spec/dummy-8.0/config/database.yml +41 -0
  163. data/spec/dummy-8.0/config/environment.rb +5 -0
  164. data/spec/dummy-8.0/config/environments/development.rb +72 -0
  165. data/spec/dummy-8.0/config/environments/production.rb +89 -0
  166. data/spec/dummy-8.0/config/environments/test.rb +53 -0
  167. data/spec/dummy-8.0/config/initializers/assets.rb +7 -0
  168. data/spec/dummy-8.0/config/initializers/content_security_policy.rb +25 -0
  169. data/spec/dummy-8.0/config/initializers/filter_parameter_logging.rb +8 -0
  170. data/spec/dummy-8.0/config/initializers/inflections.rb +16 -0
  171. data/spec/dummy-8.0/config/locales/en.yml +31 -0
  172. data/spec/dummy-8.0/config/puma.rb +41 -0
  173. data/spec/dummy-8.0/config/routes.rb +14 -0
  174. data/spec/dummy-8.0/config/storage.yml +34 -0
  175. data/spec/dummy-8.0/config.ru +6 -0
  176. data/spec/dummy-8.0/db/seeds.rb +9 -0
  177. data/spec/dummy-8.0/log/.keep +0 -0
  178. data/spec/dummy-8.0/storage/.keep +0 -0
  179. data/spec/dummy-8.1/.gitattributes +9 -0
  180. data/spec/dummy-8.1/.gitignore +35 -0
  181. data/spec/dummy-8.1/.rubocop.yml +8 -0
  182. data/spec/dummy-8.1/Dockerfile +71 -0
  183. data/spec/dummy-8.1/config/application.rb +42 -0
  184. data/spec/dummy-8.1/config/boot.rb +3 -0
  185. data/spec/dummy-8.1/config/bundler-audit.yml +5 -0
  186. data/spec/dummy-8.1/config/cable.yml +10 -0
  187. data/spec/dummy-8.1/config/ci.rb +19 -0
  188. data/spec/dummy-8.1/config/database.yml +40 -0
  189. data/spec/dummy-8.1/config/environment.rb +5 -0
  190. data/spec/dummy-8.1/config/environments/development.rb +78 -0
  191. data/spec/dummy-8.1/config/environments/production.rb +89 -0
  192. data/spec/dummy-8.1/config/environments/test.rb +53 -0
  193. data/spec/dummy-8.1/config/initializers/assets.rb +7 -0
  194. data/spec/dummy-8.1/config/initializers/content_security_policy.rb +29 -0
  195. data/spec/dummy-8.1/config/initializers/filter_parameter_logging.rb +8 -0
  196. data/spec/dummy-8.1/config/initializers/inflections.rb +16 -0
  197. data/spec/dummy-8.1/config/locales/en.yml +31 -0
  198. data/spec/dummy-8.1/config/puma.rb +42 -0
  199. data/spec/dummy-8.1/config/routes.rb +14 -0
  200. data/spec/dummy-8.1/config/storage.yml +27 -0
  201. data/spec/dummy-8.1/config.ru +6 -0
  202. data/spec/dummy-8.1/db/seeds.rb +9 -0
  203. data/spec/dummy-8.1/log/.keep +0 -0
  204. data/spec/dummy-8.1/storage/.keep +0 -0
  205. data/spec/dummy_rails_app.rb +1 -1
  206. data/spec/dump/env_spec.rb +8 -23
  207. data/spec/dump/reader_spec.rb +12 -14
  208. data/spec/dump/snapshot_spec.rb +9 -13
  209. data/spec/dump/table_manipulation_spec.rb +3 -3
  210. data/spec/dump/writer_spec.rb +7 -4
  211. data/spec/dump_spec.rb +5 -5
  212. data/spec/recipes/dump_spec.rb +40 -38
  213. data/spec/tasks/assets_spec.rb +3 -3
  214. metadata +400 -55
  215. data/.travis.database.yml +0 -14
  216. data/.travis.yml +0 -33
  217. data/.travis_check_rubies.yml +0 -1
  218. data/spec/dummy-3.0/.gitignore +0 -4
  219. data/spec/dummy-3.0/config/application.rb +0 -42
  220. data/spec/dummy-3.0/config/boot.rb +0 -6
  221. data/spec/dummy-3.0/config/environment.rb +0 -5
  222. data/spec/dummy-3.0/config/environments/development.rb +0 -26
  223. data/spec/dummy-3.0/config/environments/production.rb +0 -49
  224. data/spec/dummy-3.0/config/environments/test.rb +0 -35
  225. data/spec/dummy-3.0/config/initializers/inflections.rb +0 -10
  226. data/spec/dummy-3.0/config/initializers/secret_token.rb +0 -7
  227. data/spec/dummy-3.0/config/initializers/session_store.rb +0 -8
  228. data/spec/dummy-3.0/config/locales/en.yml +0 -5
  229. data/spec/dummy-3.0/config/routes.rb +0 -58
  230. data/spec/dummy-3.0/config.ru +0 -4
  231. data/spec/dummy-3.0/db/seeds.rb +0 -7
  232. /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
- 1.times do
27
- begin
28
- sleep sec
29
- rescue RestartException
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
@@ -8,6 +8,7 @@ module Dump
8
8
  # '-a,b,c' will pass everything except 'a', 'b' and 'c'
9
9
  class Filter
10
10
  attr_reader :invert, :values, :transparent
11
+
11
12
  def initialize(string, splitter = nil)
12
13
  if string
13
14
  string = string.dup
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[key]
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.keys.each{ |key| empty_env[key] = nil }
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[key]
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
- ".\n" +
130
- variable_names_for_command(command).map do |variable_name|
131
- " #{DICTIONARY[variable_name].join(', ')} — #{EXPLANATIONS[variable_name]}\n"
132
- end.join('')
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 |gzip|
93
- Archive::Tar::Minitar.open(gzip, 'r') do |stream|
94
- @stream = stream
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| (dump.tags & tags[:simple]).present? } if tags[:simple].present?
18
- dumps = dumps.select{ |dump| (dump.tags & tags[:mandatory]) == tags[:mandatory] } if tags[:mandatory].present?
19
- dumps = dumps.reject{ |dump| (dump.tags & tags[:forbidden]).present? } if tags[:forbidden].present?
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 ||= begin
61
- 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
- {}
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
- lock = File.open(path, 'r')
118
- begin
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(/^\-+/, '')[0, 20].strip
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] = SortedSet.new }
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 = {'+' => :mandatory, '-' => :forbidden}[m[1]] || :simple
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
- [:simple, :mandatory].each do |type|
183
- if (clashing = (groups[type] & groups[:forbidden])).present?
184
- fail ArgumentError, "#{type} tags clashes with forbidden ones: #{clashing}"
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.each_with_object({}){ |(key, value), hsh| hsh[key] = value.to_a }
180
+ groups
188
181
  end
189
182
  end
190
183
  include CleanNParse
@@ -5,7 +5,7 @@ require 'dump/env'
5
5
  module Dump
6
6
  # Methods to work with db using ActiveRecord
7
7
  module TableManipulation
8
- protected # rubocop:disable Layout/IndentationWidth
8
+ protected
9
9
 
10
10
  def schema_tables
11
11
  %w[schema_info schema_migrations]
@@ -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
- " WHERE #{quoted_primary_key} %s" \
158
- " ORDER BY #{quoted_primary_key} ASC"
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
- " WHERE #{quoted_primary_key} %s" \
162
- " ORDER BY #{quoted_primary_key} ASC" \
163
- " LIMIT #{chunk_size}"
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) do |gzip|
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)
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, 1 + row_count) do
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
- columns_by_name = columns.index_by(&:name)
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
@@ -7,7 +7,7 @@ task :assets do
7
7
  end
8
8
 
9
9
  namespace :assets do
10
- desc 'Delete assets' + Dump::Env.explain_variables_for_command(:assets)
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 'Short for dump:create' + Dump::Env.explain_variables_for_command(:create)
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 'Show avaliable versions' + Dump::Env.explain_variables_for_command(:versions)
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 'Create dump' + Dump::Env.explain_variables_for_command(:create)
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 'Restore dump' + Dump::Env.explain_variables_for_command(:restore)
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 'Cleanup dumps' + Dump::Env.explain_variables_for_command(:cleanup)
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
@@ -1,6 +1,8 @@
1
1
  /db/database.yml
2
2
 
3
3
  /dummy-*/.bundle/
4
+ /dummy-*/.dockerignore
5
+ /dummy-*/.github/
4
6
  /dummy-*/.ruby-version
5
7
  /dummy-*/config/credentials.yml.enc
6
8
  /dummy-*/db/*.sqlite3
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.load(IO.read(File.expand_path('../db/database.yml', __FILE__)))
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.open(ENV['SCHEMA'], 'w') do |w|
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['SCHEMA'])
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 do
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.combination(2) do |adapter_src, adapter_dst|
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 |gzip|
217
- Archive::Tar::Minitar.open(gzip, 'r') do |stream|
218
- stream.each do |entry|
219
- entry_data = if entry.full_name == 'schema.rb'
220
- entry.read
221
- else
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,4 @@
1
+ # https://stackoverflow.com/a/40758542/96823
2
+ require 'active_record/connection_adapters/mysql2_adapter'
3
+
4
+ ActiveRecord::ConnectionAdapters::Mysql2Adapter::NATIVE_DATABASE_TYPES[:primary_key] = 'int(11) auto_increment PRIMARY KEY'
@@ -0,0 +1,4 @@
1
+ # https://stackoverflow.com/a/40758542/96823
2
+ require 'active_record/connection_adapters/mysql2_adapter'
3
+
4
+ ActiveRecord::ConnectionAdapters::Mysql2Adapter::NATIVE_DATABASE_TYPES[:primary_key] = 'int(11) auto_increment PRIMARY KEY'
@@ -0,0 +1,4 @@
1
+ # https://stackoverflow.com/a/40758542/96823
2
+ require 'active_record/connection_adapters/mysql2_adapter'
3
+
4
+ ActiveRecord::ConnectionAdapters::Mysql2Adapter::NATIVE_DATABASE_TYPES[:primary_key] = 'int(11) auto_increment PRIMARY KEY'
@@ -0,0 +1,4 @@
1
+ # https://stackoverflow.com/a/40758542/96823
2
+ require 'active_record/connection_adapters/mysql2_adapter'
3
+
4
+ ActiveRecord::ConnectionAdapters::Mysql2Adapter::NATIVE_DATABASE_TYPES[:primary_key] = 'int(11) auto_increment PRIMARY KEY'
@@ -0,0 +1,4 @@
1
+ # https://stackoverflow.com/a/40758542/96823
2
+ require 'active_record/connection_adapters/mysql2_adapter'
3
+
4
+ ActiveRecord::ConnectionAdapters::Mysql2Adapter::NATIVE_DATABASE_TYPES[:primary_key] = 'int(11) auto_increment PRIMARY KEY'
@@ -0,0 +1,4 @@
1
+ # https://stackoverflow.com/a/40758542/96823
2
+ require 'active_record/connection_adapters/mysql2_adapter'
3
+
4
+ ActiveRecord::ConnectionAdapters::Mysql2Adapter::NATIVE_DATABASE_TYPES[:primary_key] = 'int(11) auto_increment PRIMARY KEY'
@@ -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
@@ -0,0 +1,5 @@
1
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
2
+
3
+ require 'bundler/setup' # Set up gems listed in the Gemfile.
4
+
5
+ require 'logger' # fix rails relying on concurrent-ruby < 1.3.5 to require logger?
@@ -0,0 +1,10 @@
1
+ development:
2
+ adapter: async
3
+
4
+ test:
5
+ adapter: test
6
+
7
+ production:
8
+ adapter: redis
9
+ url: <%= ENV.fetch("REDIS_URL") { "redis://localhost:6379/1" } %>
10
+ channel_prefix: dummy_6_0_production
@@ -1,22 +1,25 @@
1
- # SQLite version 3.x
1
+ # SQLite. Versions 3.8.0 and up are supported.
2
2
  # gem install sqlite3
3
- development:
3
+ #
4
+ # Ensure the SQLite 3 gem is defined in your Gemfile
5
+ # gem 'sqlite3'
6
+ #
7
+ default: &default
4
8
  adapter: sqlite3
5
- database: db/development.sqlite3
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
- adapter: sqlite3
20
+ <<: *default
14
21
  database: db/test.sqlite3
15
- pool: 5
16
- timeout: 5000
17
22
 
18
23
  production:
19
- adapter: sqlite3
24
+ <<: *default
20
25
  database: db/production.sqlite3
21
- pool: 5
22
- timeout: 5000
@@ -0,0 +1,5 @@
1
+ # Load the Rails application.
2
+ require_relative 'application'
3
+
4
+ # Initialize the Rails application.
5
+ Rails.application.initialize!