Skip to content

Commit f2afecd

Browse files
committed
DestroyStackJob: also delete commits
Also use `dependent: :delete` rather than destroy for models that don't have an `after_destroy` callback.
1 parent 50ab00a commit f2afecd

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

app/jobs/shipit/destroy_stack_job.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ def perform(stack)
3232

3333
delete(Shipit::OutputChunk.joins(:task).where(task: { stack_id: stack.id }))
3434
delete(Shipit::Task.where(stack_id: stack.id))
35+
36+
delete(Shipit::Commit.where(stack_id: stack.id))
37+
3538
stack.destroy!
3639
end
3740

app/models/shipit/stack.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,19 @@ def blank?
2626
ENVIRONMENT_MAX_SIZE = 50
2727
REQUIRED_HOOKS = %i(push status).freeze
2828

29-
has_many :commits, dependent: :destroy
30-
has_many :merge_requests, dependent: :destroy
31-
has_many :tasks, dependent: :destroy
29+
has_many :commits, dependent: :delete_all
30+
has_many :merge_requests, dependent: :delete_all
31+
has_many :tasks, dependent: :delete_all
3232
has_many :deploys
3333
has_many :rollbacks
3434
has_many :deploys_and_rollbacks,
3535
-> { where(type: %w(Shipit::Deploy Shipit::Rollback)) },
3636
class_name: 'Task',
3737
inverse_of: :stack
38-
has_many :github_hooks, dependent: :destroy, class_name: 'Shipit::GithubHook::Repo'
39-
has_many :hooks, dependent: :destroy
40-
has_many :api_clients, dependent: :destroy
41-
has_one :continuous_delivery_schedule
38+
has_many :github_hooks, dependent: :delete_all, class_name: 'Shipit::GithubHook::Repo'
39+
has_many :hooks, dependent: :delete_all
40+
has_many :api_clients, dependent: :delete_all
41+
has_one :continuous_delivery_schedule, dependent: :delete_all
4242
belongs_to :lock_author, class_name: :User, optional: true
4343
belongs_to :repository
4444
validates_associated :repository

0 commit comments

Comments
 (0)