travis-backup-for-v3 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (122) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +8 -0
  3. data/.travis.yml +36 -0
  4. data/Gemfile +6 -0
  5. data/Gemfile.lock +215 -0
  6. data/README.md +100 -0
  7. data/Rakefile +18 -0
  8. data/bin/bundle +114 -0
  9. data/bin/console +8 -0
  10. data/bin/rails +5 -0
  11. data/bin/rake +7 -0
  12. data/bin/setup +36 -0
  13. data/bin/spring +14 -0
  14. data/bin/travis_backup_for_v3 +7 -0
  15. data/bin/yarn +17 -0
  16. data/config/application.rb +22 -0
  17. data/config/boot.rb +4 -0
  18. data/config/cable.yml +10 -0
  19. data/config/credentials.yml.enc +1 -0
  20. data/config/database.yml +23 -0
  21. data/config/environment.rb +5 -0
  22. data/config/environments/development.rb +76 -0
  23. data/config/environments/production.rb +120 -0
  24. data/config/environments/test.rb +60 -0
  25. data/config/initializers/application_controller_renderer.rb +8 -0
  26. data/config/initializers/assets.rb +14 -0
  27. data/config/initializers/backtrace_silencers.rb +8 -0
  28. data/config/initializers/content_security_policy.rb +30 -0
  29. data/config/initializers/cookies_serializer.rb +5 -0
  30. data/config/initializers/filter_parameter_logging.rb +6 -0
  31. data/config/initializers/inflections.rb +16 -0
  32. data/config/initializers/mime_types.rb +4 -0
  33. data/config/initializers/permissions_policy.rb +11 -0
  34. data/config/initializers/wrap_parameters.rb +14 -0
  35. data/config/locales/en.yml +33 -0
  36. data/config/puma.rb +43 -0
  37. data/config/routes.rb +3 -0
  38. data/config/settings.yml +7 -0
  39. data/config/spring.rb +6 -0
  40. data/config.ru +5 -0
  41. data/db/schema.sql +5417 -0
  42. data/dump/.keep +0 -0
  43. data/lib/backup/remove_specified/remove_heavy_data.rb +99 -0
  44. data/lib/backup/remove_specified/remove_with_all_dependencies.rb +51 -0
  45. data/lib/backup/remove_specified/shared.rb +20 -0
  46. data/lib/backup/remove_specified.rb +68 -0
  47. data/lib/backup/save_file.rb +43 -0
  48. data/lib/backup/save_id_hash_to_file.rb +33 -0
  49. data/lib/backup/save_nullified_rels_to_file.rb +29 -0
  50. data/lib/config.rb +198 -0
  51. data/lib/db_helper.rb +27 -0
  52. data/lib/dry_run_reporter.rb +47 -0
  53. data/lib/id_hash.rb +97 -0
  54. data/lib/ids_of_all_dependencies.rb +330 -0
  55. data/lib/model.rb +86 -0
  56. data/lib/models/abuse.rb +8 -0
  57. data/lib/models/beta_migration_request.rb +8 -0
  58. data/lib/models/branch.rb +18 -0
  59. data/lib/models/broadcast.rb +7 -0
  60. data/lib/models/build.rb +36 -0
  61. data/lib/models/build_config.rb +9 -0
  62. data/lib/models/cancellation.rb +8 -0
  63. data/lib/models/commit.rb +16 -0
  64. data/lib/models/cron.rb +7 -0
  65. data/lib/models/deleted_build.rb +37 -0
  66. data/lib/models/deleted_build_config.rb +10 -0
  67. data/lib/models/deleted_commit.rb +17 -0
  68. data/lib/models/deleted_job.rb +15 -0
  69. data/lib/models/deleted_job_config.rb +10 -0
  70. data/lib/models/deleted_pull_request.rb +12 -0
  71. data/lib/models/deleted_request.rb +26 -0
  72. data/lib/models/deleted_request_config.rb +10 -0
  73. data/lib/models/deleted_request_payload.rb +8 -0
  74. data/lib/models/deleted_request_raw_config.rb +10 -0
  75. data/lib/models/deleted_request_raw_configuration.rb +9 -0
  76. data/lib/models/deleted_request_yaml_config.rb +10 -0
  77. data/lib/models/deleted_ssl_key.rb +8 -0
  78. data/lib/models/deleted_stage.rb +10 -0
  79. data/lib/models/deleted_tag.rb +15 -0
  80. data/lib/models/email.rb +7 -0
  81. data/lib/models/email_unsubscribe.rb +8 -0
  82. data/lib/models/installation.rb +7 -0
  83. data/lib/models/invoice.rb +7 -0
  84. data/lib/models/job.rb +16 -0
  85. data/lib/models/job_config.rb +9 -0
  86. data/lib/models/job_version.rb +7 -0
  87. data/lib/models/membership.rb +8 -0
  88. data/lib/models/message.rb +7 -0
  89. data/lib/models/organization.rb +26 -0
  90. data/lib/models/owner_group.rb +7 -0
  91. data/lib/models/permission.rb +8 -0
  92. data/lib/models/pull_request.rb +11 -0
  93. data/lib/models/queueable_job.rb +7 -0
  94. data/lib/models/repo_count.rb +8 -0
  95. data/lib/models/repository.rb +39 -0
  96. data/lib/models/request.rb +25 -0
  97. data/lib/models/request_config.rb +9 -0
  98. data/lib/models/request_payload.rb +7 -0
  99. data/lib/models/request_raw_config.rb +9 -0
  100. data/lib/models/request_raw_configuration.rb +8 -0
  101. data/lib/models/request_yaml_config.rb +9 -0
  102. data/lib/models/ssl_key.rb +7 -0
  103. data/lib/models/stage.rb +9 -0
  104. data/lib/models/star.rb +8 -0
  105. data/lib/models/subscription.rb +9 -0
  106. data/lib/models/tag.rb +14 -0
  107. data/lib/models/token.rb +7 -0
  108. data/lib/models/trial.rb +8 -0
  109. data/lib/models/trial_allowance.rb +8 -0
  110. data/lib/models/user.rb +34 -0
  111. data/lib/models/user_beta_feature.rb +7 -0
  112. data/lib/models/user_utm_param.rb +7 -0
  113. data/lib/models.rb +58 -0
  114. data/lib/nullify_dependencies.rb +42 -0
  115. data/lib/travis-backup.rb +33 -0
  116. data/log/.keep +0 -0
  117. data/package.json +11 -0
  118. data/tmp/.keep +0 -0
  119. data/travis-backup-for-v3.gemspec +30 -0
  120. data/vendor/.keep +0 -0
  121. data/workspace.code-workspace +8 -0
  122. metadata +366 -0
data/lib/id_hash.rb ADDED
@@ -0,0 +1,97 @@
1
+ require 'model'
2
+
3
+ class HashOfArrays < Hash
4
+ def initialize(hash = {})
5
+ hash.each do |key, array|
6
+ self[key] = hash[key].clone
7
+ end
8
+ end
9
+
10
+ def clone
11
+ self.class.new(self)
12
+ end
13
+
14
+ def subtract(hash)
15
+ result = self.clone
16
+ hash.each do |key, array|
17
+ next if result[key].nil?
18
+
19
+ array.each do |el|
20
+ result[key].delete(el)
21
+ end
22
+
23
+ result.delete(key) if result[key].empty?
24
+ end
25
+ result
26
+ end
27
+
28
+ def add(key, *values)
29
+ self[key] = [] if self[key].nil?
30
+ self[key].concat(values)
31
+ end
32
+
33
+ def self.join(*hashes)
34
+ result = self.new
35
+ result.join(*hashes)
36
+ end
37
+
38
+ def join(*hashes)
39
+ hashes.each do |hash|
40
+ hash.each do |key, array|
41
+ self.add(key, *array)
42
+ end
43
+ end
44
+ self
45
+ end
46
+
47
+ def sort_arrays!
48
+ self.each do |key, array|
49
+ array.sort!
50
+ end
51
+ end
52
+ end
53
+
54
+ class IdHash < HashOfArrays
55
+ def add(key, *values)
56
+ super(key, *values)
57
+ self[key].uniq!
58
+ self
59
+ end
60
+
61
+ def remove_entries_from_db(as_first: [], as_last: [])
62
+ exceptionals = as_first + as_last
63
+ remove_from_exceptional(as_first)
64
+
65
+ self.each do |name, ids|
66
+ next if exceptionals.include?(name)
67
+ remove_entries_from_array(name, ids)
68
+ end
69
+
70
+ remove_from_exceptional(as_last)
71
+ end
72
+
73
+ def with_table_symbols
74
+ result = HashOfArrays.new
75
+
76
+ self.each do |name, ids|
77
+ symbol = Model.get_model(name).table_name.to_sym
78
+ result[symbol] = ids
79
+ end
80
+
81
+ result
82
+ end
83
+
84
+ private
85
+
86
+ def remove_from_exceptional(array)
87
+ array.each do |name|
88
+ ids = self[name]
89
+ remove_entries_from_array(name, ids)
90
+ end
91
+ end
92
+
93
+ def remove_entries_from_array(model_name, ids)
94
+ model = Model.get_model(model_name)
95
+ model.delete(ids) if model.present?
96
+ end
97
+ end
@@ -0,0 +1,330 @@
1
+ require 'id_hash'
2
+
3
+ module SymbolsOfAllDirectDependencies
4
+ def symbols_of_all_direct_dependencies
5
+ self.class.reflect_on_all_associations.map do |association|
6
+ next if association.macro == :belongs_to
7
+
8
+ association.name
9
+ end.compact
10
+ end
11
+ end
12
+
13
+ module IdsOfAllDirectDependencies
14
+ include SymbolsOfAllDirectDependencies
15
+
16
+ def ids_of_all_direct_dependencies
17
+ result = IdHash.new
18
+
19
+ self.class.reflect_on_all_associations.map do |association|
20
+ next if association.macro == :belongs_to
21
+
22
+ symbol = association.klass.name.underscore.to_sym
23
+ self.send(association.name).map do |associated_object|
24
+ result.add(symbol, associated_object.id)
25
+ end
26
+ end
27
+
28
+ result
29
+ end
30
+ end
31
+
32
+ module IdsOfAllDependenciesNested
33
+ def ids_of_all_dependencies_nested(depth = Float::INFINITY)
34
+ result = depth > 0 ? get_associations(depth) : {}
35
+ result[:id] = id
36
+ result = result[:id] if result.size == 1
37
+ result
38
+ end
39
+
40
+ private
41
+
42
+ def get_associations(depth)
43
+ result = {}
44
+
45
+ self.class.reflect_on_all_associations.map do |association|
46
+ next if association.macro == :belongs_to
47
+
48
+ symbol = association.klass.name.underscore.to_sym
49
+ self.send(association.name).sort_by(&:id).map do |associated_object|
50
+ result[symbol] = [] if result[symbol].nil?
51
+ result[symbol] << associated_object.ids_of_all_dependencies_nested(depth - 1)
52
+ end
53
+ end
54
+
55
+ result
56
+ end
57
+ end
58
+
59
+ module DependencyTree
60
+ class Tree < Hash
61
+ def initialize(hash={})
62
+ hash.each do |key, value|
63
+ self[key] = value
64
+ end
65
+ end
66
+
67
+ def ids_tree
68
+ self_cloned = self.deep_tree_clone
69
+ self_cloned.delete_key_recursive(:instance)
70
+ end
71
+
72
+ def status_tree
73
+ self_cloned = self.deep_tree_clone
74
+
75
+ self_cloned.do_recursive do |tree|
76
+ begin
77
+ tree[:instance].reload
78
+ tree[:status] = 'present'
79
+ rescue ActiveRecord::RecordNotFound => e
80
+ tree[:status] = 'removed'
81
+ end
82
+
83
+ tree.delete(:instance)
84
+ end
85
+ end
86
+
87
+ def status_tree_condensed
88
+ result = status_tree.do_recursive do |tree|
89
+ tree.each do |name, array|
90
+ next unless array.class == Array
91
+
92
+ new_array = array.map do |subtree|
93
+ next subtree.root_duplicate_summary if subtree[:duplicate]
94
+ next subtree if subtree.class != Tree || subtree.size > 2
95
+
96
+ subtree.root_summary
97
+ end
98
+
99
+ array.clear
100
+ array.concat(new_array)
101
+ end
102
+ end
103
+
104
+ result.do_recursive do |tree|
105
+ tree[:_] = tree.root_summary
106
+ tree.delete(:id)
107
+ tree.delete(:status)
108
+ tree.last_to_beginning!
109
+ end
110
+ end
111
+
112
+ def last_to_beginning!
113
+ arr = self.to_a
114
+ arr.unshift(arr.pop)
115
+ self.clear
116
+ self.merge!(arr.to_h)
117
+ end
118
+
119
+ def root_summary
120
+ "id #{self[:id]}, #{self[:status]}"
121
+ end
122
+
123
+ def root_duplicate_summary
124
+ root_summary + ", duplicate"
125
+ end
126
+
127
+ def deep_tree_clone
128
+ hash = self.clone.map do |key, array|
129
+ next [key, array] unless array.class == Array
130
+
131
+ new_array = array.map do |subtree|
132
+ if subtree.class == Tree
133
+ subtree.deep_tree_clone
134
+ else
135
+ subtree
136
+ end
137
+ end
138
+
139
+ [key, new_array]
140
+ end
141
+
142
+ Tree.new(hash)
143
+ end
144
+
145
+ def delete_key_recursive(key)
146
+ call_method_recursive(:delete, key)
147
+ end
148
+
149
+ def call_method_recursive(method, *args, &block)
150
+ do_recursive do |tree|
151
+ tree.send(method, *args, &block)
152
+ end
153
+ end
154
+
155
+ def do_recursive(&block)
156
+ block.call(self)
157
+
158
+ self.each do |key, array|
159
+ next unless array.is_a? Array
160
+
161
+ array.each do |subtree|
162
+ subtree.do_recursive(&block) if subtree.is_a? Tree
163
+ end
164
+ end
165
+
166
+ self
167
+ end
168
+ end
169
+
170
+ def dependency_tree(depth = Float::INFINITY, hash_for_duplication_check = IdHash.new)
171
+ is_duplicate = hash_for_duplication_check[self.class]&.include?(id)
172
+ hash_for_duplication_check.add(self.class, id)
173
+ shoud_go_deeper = depth > 0 && !is_duplicate
174
+ result = shoud_go_deeper ? get_associations_for_tree(depth, hash_for_duplication_check) : Tree.new
175
+ result[:id] = id
176
+ result[:instance] = self
177
+ result[:duplicate] = true if is_duplicate
178
+ result
179
+ end
180
+
181
+ private
182
+
183
+ def get_associations_for_tree(depth, hash_for_duplication_check)
184
+ result = Tree.new
185
+
186
+ self.class.reflect_on_all_associations.map do |association|
187
+ next if association.macro == :belongs_to
188
+
189
+ symbol = association.klass.name.underscore.to_sym
190
+ self.send(association.name).sort_by(&:id).map do |associated_object|
191
+ result[symbol] = [] if result[symbol].nil?
192
+ result[symbol] << associated_object.dependency_tree(depth - 1, hash_for_duplication_check)
193
+ end
194
+ end
195
+
196
+ result
197
+ end
198
+ end
199
+
200
+ module IdsOfAllDependencies
201
+ include IdsOfAllDependenciesNested
202
+ include IdsOfAllDirectDependencies
203
+ include DependencyTree
204
+
205
+ def ids_of_all_dependencies(to_filter=nil, filtering_strategy=:with_parents)
206
+ ids_of_all_dependencies_with_filtered(to_filter, filtering_strategy)[:main]
207
+ end
208
+
209
+ def ids_of_all_dependencies_with_filtered(to_filter=nil, filtering_strategy=:with_parents)
210
+ id_hash = ids_of_all_dependencies_without_reflection(to_filter || {}, filtering_strategy)
211
+ move_wrongly_assigned_to_main(to_filter, id_hash) if to_filter && filtering_strategy == :with_parents
212
+ id_hash[:main].sort_arrays!
213
+ id_hash[:filtered_out].sort_arrays!
214
+ id_hash
215
+ end
216
+
217
+ def ids_of_all_dependencies_without_reflection(to_filter, filtering_strategy=:with_parents)
218
+ result = { main: IdHash.new, filtered_out: IdHash.new }
219
+ self_symbol = self.class.name.underscore.to_sym
220
+
221
+ self.class.reflect_on_all_associations.map do |association|
222
+ next if association.macro == :belongs_to
223
+ symbol = association.klass.name.underscore.to_sym
224
+ context = { to_filter: to_filter, self_symbol: self_symbol, association: association, strategy: filtering_strategy }
225
+
226
+ self.send(association.name).map do |associated_object|
227
+ hash_to_use = get_hash_to_use(result, **context, object: associated_object)
228
+ hash_to_use.add(symbol, associated_object.id)
229
+ end
230
+
231
+ result = get_result_with_grandchildren_hashes(result, context)
232
+ end
233
+
234
+ result
235
+ end
236
+
237
+ private
238
+
239
+ def get_result_with_grandchildren_hashes(result, context)
240
+ hashes = get_grandchildren_hashes(context)
241
+ main = hashes.map { |hash| hash[:main] }
242
+ filtered_out = hashes.map { |hash| hash[:filtered_out] }
243
+
244
+ result[:main] =result[:main].join(*main)
245
+ result[:filtered_out] = result[:filtered_out].join(*filtered_out)
246
+ result
247
+ end
248
+
249
+ def get_grandchildren_hashes(context)
250
+ association = context[:association]
251
+ to_filter = context[:to_filter]
252
+
253
+ self.send(association.name).map do |associated_object|
254
+ next if should_be_filtered?(**context, object: associated_object)
255
+ associated_object.ids_of_all_dependencies_without_reflection(to_filter, context[:strategy])
256
+ end.compact
257
+ end
258
+
259
+ def get_hash_to_use(result, context)
260
+ symbol = should_be_filtered?(**context) ? :filtered_out : :main
261
+ result[symbol]
262
+ end
263
+
264
+ def should_be_filtered?(context)
265
+ case context[:strategy]
266
+ when :with_parents
267
+ should_be_filtered_according_to_with_parents_strategy?(context)
268
+ when :without_parents
269
+ should_be_filtered_according_to_without_parents_strategy?(context)
270
+ end
271
+ end
272
+
273
+ def should_be_filtered_according_to_with_parents_strategy?(context)
274
+ to_filter = context[:to_filter]
275
+ object = context[:object]
276
+ association = context[:association]
277
+ symbol = association.klass.name.underscore.to_sym
278
+
279
+ association.klass.reflect_on_all_associations.each do |association2|
280
+ next if association2.macro == :belongs_to
281
+
282
+ context = { to_filter: to_filter, symbol: symbol, association: association2 }
283
+ return true if object.send(association2.name).any? && is_this_association_filtered?(**context)
284
+ end
285
+
286
+ false
287
+ end
288
+
289
+ def is_this_association_filtered?(to_filter:, symbol:, association:)
290
+ arr = to_filter[symbol]
291
+ arr.present? && arr.any? { |a| a == association.name }
292
+ end
293
+
294
+ def should_be_filtered_according_to_without_parents_strategy?(context)
295
+ is_this_association_filtered?(
296
+ to_filter: context[:to_filter],
297
+ symbol: context[:self_symbol],
298
+ association: context[:association]
299
+ )
300
+ end
301
+
302
+ def move_wrongly_assigned_to_main(to_filter, id_hash)
303
+ id_hash[:filtered_out].each do |model_symbol, array|
304
+ array.clone.each do |id|
305
+ object = Model.get_model(model_symbol).find(id)
306
+ move_object_to_main_if_necessary(to_filter[model_symbol], id_hash, object)
307
+ end
308
+ end
309
+ id_hash
310
+ end
311
+
312
+ def move_object_to_main_if_necessary(associations_to_filter, id_hash, object)
313
+ if should_object_be_moved?(associations_to_filter, id_hash, object)
314
+ symbol = object.class.name.underscore.to_sym
315
+ id_hash[:filtered_out][symbol].delete(object.id)
316
+ id_hash[:main].add(symbol, object.id)
317
+ end
318
+ end
319
+
320
+ def should_object_be_moved?(associations_to_filter, id_hash, object)
321
+ associations_to_filter.map do |association|
322
+ associated = object.send(association)
323
+
324
+ associated.to_a.empty? || associated.map do |associated_object|
325
+ class_symbol = associated_object.class.name.underscore.to_sym
326
+ id_hash[:main][class_symbol]&.include?(associated_object.id)
327
+ end.reduce(:&)
328
+ end.reduce(:&)
329
+ end
330
+ end
data/lib/model.rb ADDED
@@ -0,0 +1,86 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_record'
4
+ require 'ids_of_all_dependencies'
5
+ require 'nullify_dependencies'
6
+
7
+ class AssociationWithValue
8
+ delegate_missing_to :@association
9
+
10
+ def initialize(association, value)
11
+ @association = association
12
+ @value = value
13
+ end
14
+ end
15
+
16
+ class Model < ActiveRecord::Base
17
+ include IdsOfAllDependencies
18
+ include NullifyDependencies
19
+
20
+ self.abstract_class = true
21
+
22
+ def attributes_without_id
23
+ self.attributes.reject{|k, v| k == "id"}
24
+ end
25
+
26
+ def associations_hash
27
+ self.associations.map do |association|
28
+ [association.name, association]
29
+ end.to_h
30
+ end
31
+
32
+ def associations
33
+ self.class.reflect_on_all_associations.map do |association|
34
+ value = self.send(association.name)
35
+ AssociationWithValue.new(association, value)
36
+ end
37
+ end
38
+
39
+ def associations_without_belongs_to
40
+ self.associations.select { |a| a.macro != :belongs_to }
41
+ end
42
+
43
+ def self.get_model(name)
44
+ self.subclasses.find{ |m| m.name == name.to_s.camelcase }
45
+ end
46
+
47
+ def self.get_model_by_table_name(name)
48
+ self.subclasses.find{ |m| m.table_name == name.to_s }
49
+ end
50
+
51
+ def self.ids_of_subclasses_entries
52
+ self.subclasses.map do |subclass|
53
+ [subclass.name, subclass.all.map(&:id)] if subclass.any?
54
+ end.compact.to_h
55
+ end
56
+
57
+ def self.sum_of_subclasses_rows(except: [])
58
+ self.subclasses.map do |subclass|
59
+ next 0 if except.include?(subclass.table_name) || except.include?(subclass.name)
60
+
61
+ subclass.all.size
62
+ end.reduce(:+)
63
+ end
64
+
65
+ def self.subclasses_counts(except: [])
66
+ self.subclasses.map do |subclass|
67
+ next [subclass.name, 0] if except.include?(subclass.table_name) || except.include?(subclass.name)
68
+
69
+ [subclass.name, subclass.all.size]
70
+ end.to_h
71
+ end
72
+
73
+
74
+ def removed?
75
+ begin
76
+ reload
77
+ false
78
+ rescue ActiveRecord::RecordNotFound => e
79
+ true
80
+ end
81
+ end
82
+ end
83
+
84
+ ActiveSupport::Inflector.inflections(:en) do |inflect|
85
+ inflect.irregular 'abuse', 'abuses'
86
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'model'
4
+
5
+ class Abuse < Model
6
+ belongs_to :owner, polymorphic: true
7
+ belongs_to :request
8
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'model'
4
+
5
+ class BetaMigrationRequest < Model
6
+ belongs_to :owner, polymorphic: true
7
+ has_many :organizations
8
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'model'
4
+
5
+ class Branch < Model
6
+ belongs_to :last_build, foreign_key: :last_build_id, class_name: 'Build'
7
+ belongs_to :repository
8
+ has_many :builds
9
+ has_many :commits
10
+ has_many :crons
11
+ has_many :jobs, as: :source
12
+ has_many :requests
13
+
14
+ has_many :deleted_builds
15
+ has_many :deleted_commits
16
+ has_many :deleted_jobs, as: :source
17
+ has_many :deleted_requests
18
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'model'
4
+
5
+ class Broadcast < Model
6
+ belongs_to :recipient, polymorphic: true
7
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'model'
4
+
5
+ class Build < Model
6
+ belongs_to :repository
7
+ belongs_to :owner, polymorphic: true
8
+ belongs_to :sender, polymorphic: true
9
+ belongs_to :related_branch, foreign_key: :branch_id, class_name: 'Branch'
10
+ belongs_to :commit
11
+ belongs_to :pull_request
12
+ belongs_to :tag
13
+ belongs_to :request
14
+ belongs_to :build_config, foreign_key: :config_id, class_name: 'BuildConfig'
15
+
16
+ has_many :jobs, -> { order('id') }, as: :source, dependent: :destroy
17
+ has_many :repos_for_that_this_build_is_current, foreign_key: :current_build_id, dependent: :destroy, class_name: 'Repository'
18
+ has_many :repos_for_that_this_build_is_last, foreign_key: :last_build_id, class_name: 'Repository'
19
+ has_many :tags_for_that_this_build_is_last, foreign_key: :last_build_id, class_name: 'Tag'
20
+ has_many :branches_for_that_this_build_is_last, foreign_key: :last_build_id, class_name: 'Branch'
21
+ has_many :stages
22
+
23
+ has_many :deleted_jobs, -> { order('id') }, as: :source, dependent: :destroy
24
+ has_many :deleted_tags_for_that_this_build_is_last, foreign_key: :last_build_id, class_name: 'DeletedTag'
25
+ has_many :deleted_stages
26
+
27
+ def self.default_dependencies_symbols_to_nullify
28
+ [
29
+ :repos_for_that_this_build_is_current,
30
+ :repos_for_that_this_build_is_last,
31
+ :tags_for_that_this_build_is_last,
32
+ :deleted_tags_for_that_this_build_is_last,
33
+ :branches_for_that_this_build_is_last,
34
+ ]
35
+ end
36
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'model'
4
+
5
+ class BuildConfig < Model
6
+ belongs_to :repository
7
+ has_many :builds, foreign_key: :config_id, class_name: 'Build'
8
+ has_many :deleted_builds, foreign_key: :config_id, class_name: 'DeletedBuild'
9
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'model'
4
+
5
+ class Cancellation < Model
6
+ belongs_to :subscription
7
+ belongs_to :user
8
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'model'
4
+
5
+ class Commit < Model
6
+ belongs_to :related_branch, foreign_key: :branch_id, class_name: 'Branch'
7
+ belongs_to :repository
8
+ belongs_to :tag
9
+ has_many :builds
10
+ has_many :jobs
11
+ has_many :requests
12
+
13
+ has_many :deleted_builds
14
+ has_many :deleted_jobs
15
+ has_many :deleted_requests
16
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'model'
4
+
5
+ class Cron < Model
6
+ belongs_to :branch
7
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'model'
4
+
5
+ class DeletedBuild < Model
6
+ belongs_to :repository
7
+ belongs_to :owner, polymorphic: true
8
+ belongs_to :sender, polymorphic: true
9
+ belongs_to :related_branch, foreign_key: :branch_id, class_name: 'Branch'
10
+ belongs_to :commit
11
+ belongs_to :pull_request
12
+ belongs_to :tag
13
+ belongs_to :request
14
+ belongs_to :build_config, foreign_key: :config_id, class_name: 'BuildConfig'
15
+ self.primary_key = 'id'
16
+
17
+ # has_many :jobs, -> { order('id') }, as: :source, dependent: :destroy
18
+ # has_many :repos_for_that_this_build_is_current, foreign_key: :current_build_id, dependent: :destroy, class_name: 'Repository'
19
+ # has_many :repos_for_that_this_build_is_last, foreign_key: :last_build_id, class_name: 'Repository'
20
+ # has_many :tags_for_that_this_build_is_last, foreign_key: :last_build_id, class_name: 'Tag'
21
+ # has_many :branches_for_that_this_build_is_last, foreign_key: :last_build_id, class_name: 'Branch'
22
+ # has_many :stages
23
+
24
+ # has_many :deleted_jobs, -> { order('id') }, as: :source, dependent: :destroy
25
+ # has_many :deleted_tags_for_that_this_build_is_last, foreign_key: :last_build_id, class_name: 'DeletedTag'
26
+ # has_many :deleted_stages
27
+
28
+ # def self.default_dependencies_symbols_to_nullify
29
+ # [
30
+ # :repos_for_that_this_build_is_current,
31
+ # :repos_for_that_this_build_is_last,
32
+ # :tags_for_that_this_build_is_last,
33
+ # :deleted_tags_for_that_this_build_is_last,
34
+ # :branches_for_that_this_build_is_last,
35
+ # ]
36
+ # end
37
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'model'
4
+
5
+ class DeletedBuildConfig < Model
6
+ belongs_to :repository
7
+ self.primary_key = 'id'
8
+ # has_many :builds, foreign_key: :config_id, class_name: 'Build'
9
+ # has_many :deleted_builds, foreign_key: :config_id, class_name: 'DeletedBuild'
10
+ end