travis-backup 0.2.1 → 0.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/.gitignore +1 -0
- data/README.md +14 -4
- data/lib/backup/load_from_files.rb +245 -0
- data/lib/backup/remove_orphans.rb +81 -50
- data/lib/backup/remove_specified/remove_heavy_data.rb +99 -0
- data/lib/backup/remove_specified/remove_with_all_dependencies.rb +51 -0
- data/lib/backup/remove_specified/shared.rb +20 -0
- data/lib/backup/remove_specified.rb +68 -0
- data/lib/backup/save_file.rb +43 -0
- data/lib/backup/save_id_hash_to_file.rb +33 -0
- data/lib/backup/save_nullified_rels_to_file.rb +29 -0
- data/lib/config.rb +37 -7
- data/lib/dry_run_reporter.rb +18 -4
- data/lib/id_hash.rb +97 -0
- data/lib/ids_of_all_dependencies.rb +330 -0
- data/lib/model.rb +77 -0
- data/lib/models/abuse.rb +9 -0
- data/lib/models/annotation.rb +8 -0
- data/lib/models/branch.rb +9 -1
- data/lib/models/broadcast.rb +8 -0
- data/lib/models/build.rb +23 -3
- data/lib/models/commit.rb +8 -1
- data/lib/models/cron.rb +2 -1
- data/lib/models/email.rb +8 -0
- data/lib/models/invoice.rb +8 -0
- data/lib/models/job.rb +10 -2
- data/lib/models/log.rb +1 -1
- data/lib/models/membership.rb +9 -0
- data/lib/models/message.rb +8 -0
- data/lib/models/organization.rb +15 -1
- data/lib/models/owner_group.rb +8 -0
- data/lib/models/permission.rb +9 -0
- data/lib/models/pull_request.rb +5 -1
- data/lib/models/queueable_job.rb +8 -0
- data/lib/models/repository.rb +16 -3
- data/lib/models/request.rb +11 -1
- data/lib/models/ssl_key.rb +2 -1
- data/lib/models/stage.rb +4 -1
- data/lib/models/star.rb +9 -0
- data/lib/models/subscription.rb +9 -0
- data/lib/models/tag.rb +7 -1
- data/lib/models/token.rb +8 -0
- data/lib/models/trial.rb +9 -0
- data/lib/models/trial_allowance.rb +9 -0
- data/lib/models/user.rb +33 -1
- data/lib/models/user_beta_feature.rb +8 -0
- data/lib/nullify_dependencies.rb +42 -0
- data/lib/travis-backup.rb +29 -5
- data/travis-backup.gemspec +1 -1
- metadata +35 -9
- data/lib/backup/remove_old.rb +0 -204
- data/lib/models/model.rb +0 -8
@@ -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,77 @@
|
|
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 removed?
|
66
|
+
begin
|
67
|
+
reload
|
68
|
+
false
|
69
|
+
rescue ActiveRecord::RecordNotFound => e
|
70
|
+
true
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
ActiveSupport::Inflector.inflections(:en) do |inflect|
|
76
|
+
inflect.irregular 'abuse', 'abuses'
|
77
|
+
end
|
data/lib/models/abuse.rb
ADDED
data/lib/models/branch.rb
CHANGED
@@ -1,7 +1,15 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require '
|
3
|
+
require 'model'
|
4
4
|
|
5
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
|
+
|
6
14
|
self.table_name = 'branches'
|
7
15
|
end
|
data/lib/models/build.rb
CHANGED
@@ -1,14 +1,34 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'models/job'
|
4
|
-
require '
|
4
|
+
require 'model'
|
5
5
|
require 'models/repository'
|
6
6
|
|
7
7
|
# Build model
|
8
8
|
class Build < Model
|
9
9
|
belongs_to :repository
|
10
|
-
|
11
|
-
|
10
|
+
belongs_to :owner, polymorphic: true
|
11
|
+
belongs_to :sender, polymorphic: true
|
12
|
+
belongs_to :related_branch, foreign_key: :branch_id, class_name: 'Branch'
|
13
|
+
belongs_to :commit
|
14
|
+
belongs_to :pull_request
|
15
|
+
belongs_to :tag
|
16
|
+
belongs_to :request
|
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
|
12
23
|
|
13
24
|
self.table_name = 'builds'
|
25
|
+
|
26
|
+
def self.default_dependencies_symbols_to_nullify
|
27
|
+
[
|
28
|
+
:repos_for_that_this_build_is_current,
|
29
|
+
:repos_for_that_this_build_is_last,
|
30
|
+
:tags_for_that_this_build_is_last,
|
31
|
+
:branches_for_that_this_build_is_last
|
32
|
+
]
|
33
|
+
end
|
14
34
|
end
|
data/lib/models/commit.rb
CHANGED
@@ -1,7 +1,14 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require '
|
3
|
+
require 'model'
|
4
4
|
|
5
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
|
+
|
6
13
|
self.table_name = 'commits'
|
7
14
|
end
|
data/lib/models/cron.rb
CHANGED
data/lib/models/email.rb
ADDED
data/lib/models/job.rb
CHANGED
@@ -1,15 +1,23 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require '
|
3
|
+
require 'model'
|
4
4
|
require 'models/repository'
|
5
5
|
require 'models/log'
|
6
|
+
require 'models/annotation'
|
7
|
+
require 'models/queueable_job'
|
6
8
|
|
7
9
|
# Job model
|
8
10
|
class Job < Model
|
9
11
|
self.inheritance_column = :_type_disabled
|
10
12
|
|
13
|
+
belongs_to :source, polymorphic: true
|
14
|
+
belongs_to :owner, polymorphic: true
|
11
15
|
belongs_to :repository
|
12
|
-
|
16
|
+
belongs_to :commit
|
17
|
+
belongs_to :stage
|
18
|
+
has_many :logs, -> { order('id') }, dependent: :destroy
|
19
|
+
has_many :annotations
|
20
|
+
has_many :queueable_jobs
|
13
21
|
|
14
22
|
self.table_name = 'jobs'
|
15
23
|
end
|
data/lib/models/log.rb
CHANGED
data/lib/models/organization.rb
CHANGED
@@ -1,7 +1,21 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require '
|
3
|
+
require 'model'
|
4
4
|
|
5
5
|
class Organization < Model
|
6
|
+
has_many :builds_for_that_this_organization_is_owner, as: :owner, class_name: 'Build'
|
7
|
+
has_many :builds_for_that_this_organization_is_sender, as: :sender, class_name: 'Build'
|
8
|
+
has_many :repositories, as: :owner
|
9
|
+
has_many :jobs, as: :owner
|
10
|
+
has_many :requests_for_that_this_organization_is_owner, as: :owner, class_name: 'Request'
|
11
|
+
has_many :abuses, as: :owner
|
12
|
+
has_many :subscriptions, as: :owner
|
13
|
+
has_many :owner_groups, as: :owner
|
14
|
+
has_many :trials, as: :owner
|
15
|
+
has_many :trial_allowances, as: :creator
|
16
|
+
has_many :broadcasts, as: :recipient
|
17
|
+
has_many :requests_for_that_this_organization_is_sender, as: :sender, class_name: 'Request'
|
18
|
+
has_many :memberships
|
19
|
+
|
6
20
|
self.table_name = 'organizations'
|
7
21
|
end
|
data/lib/models/pull_request.rb
CHANGED
data/lib/models/repository.rb
CHANGED
@@ -1,13 +1,26 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require '
|
3
|
+
require 'model'
|
4
4
|
require 'models/build'
|
5
5
|
require 'models/request'
|
6
|
+
require 'models/permission'
|
7
|
+
require 'models/star'
|
6
8
|
|
7
9
|
# Repository model
|
8
10
|
class Repository < Model
|
9
|
-
|
10
|
-
|
11
|
+
belongs_to :owner, polymorphic: true
|
12
|
+
belongs_to :current_build, foreign_key: :current_build_id, class_name: 'Build'
|
13
|
+
belongs_to :last_build, foreign_key: :last_build_id, class_name: 'Build'
|
14
|
+
has_many :builds, -> { order('id') }
|
15
|
+
has_many :requests, -> { order('id') }, dependent: :destroy
|
16
|
+
has_many :jobs
|
17
|
+
has_many :branches
|
18
|
+
has_many :ssl_keys
|
19
|
+
has_many :commits
|
20
|
+
has_many :permissions
|
21
|
+
has_many :stars
|
22
|
+
has_many :pull_requests
|
23
|
+
has_many :tags
|
11
24
|
|
12
25
|
self.table_name = 'repositories'
|
13
26
|
end
|