diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2015-04-15 15:26:51 +0000 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2015-04-15 15:26:51 +0000 |
commit | cca6ded9fd1874863a265ca4d96c243e637ec3de (patch) | |
tree | ca7bfbabeff3f8f8a3cd64ada78537be02d99445 | |
parent | c4124778c489b6d301f1349d4a726a009168207c (diff) | |
parent | 6f5904035606504f557616b3957598f2918587fa (diff) | |
download | gitlab-ci-cca6ded9fd1874863a265ca4d96c243e637ec3de.tar.gz |
Merge branch 'job_soft_deletion' into 'master'
Job soft deletion
Fixes https://dev.gitlab.org/gitlab/gitlab-ci/issues/200
See merge request !66
-rw-r--r-- | Gemfile | 3 | ||||
-rw-r--r-- | Gemfile.lock | 3 | ||||
-rw-r--r-- | app/models/build.rb | 4 | ||||
-rw-r--r-- | app/models/job.rb | 2 | ||||
-rw-r--r-- | db/migrate/20150415142013_add_deleted_at_to_jobs.rb | 6 | ||||
-rw-r--r-- | db/schema.rb | 4 |
6 files changed, 19 insertions, 3 deletions
@@ -79,6 +79,9 @@ gem 'turbolinks' gem 'jquery-turbolinks' gem 'nprogress-rails' +# Soft deletion +gem "paranoia", "~> 2.0" + group :development do gem 'brakeman', require: false diff --git a/Gemfile.lock b/Gemfile.lock index 8d66913..9160d12 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -201,6 +201,8 @@ GEM multi_json (~> 1.3) multi_xml (~> 0.5) rack (~> 1.2) + paranoia (2.1.1) + activerecord (~> 4.0) parser (2.2.0.2) ast (>= 1.1, < 3.0) pg (0.17.0) @@ -396,6 +398,7 @@ DEPENDENCIES nested_form nprogress-rails oauth2 (= 1.0.0) + paranoia (~> 2.0) pg poltergeist (~> 1.5.1) pry diff --git a/app/models/build.rb b/app/models/build.rb index de44a1c..3d776ba 100644 --- a/app/models/build.rb +++ b/app/models/build.rb @@ -28,7 +28,7 @@ class Build < ActiveRecord::Base belongs_to :commit belongs_to :project belongs_to :runner - belongs_to :job + belongs_to :job, -> { with_deleted } validates :commit, presence: true validates :status, presence: true @@ -115,7 +115,7 @@ class Build < ActiveRecord::Base WebHookService.new.build_end(build) end - if build.commit.success? && !build.job.deploy? + if build.commit.success? && !(build.job && build.job.deploy?) build.commit.create_deploy_builds(build.ref) end diff --git a/app/models/job.rb b/app/models/job.rb index 82dac8f..14cc344 100644 --- a/app/models/job.rb +++ b/app/models/job.rb @@ -16,6 +16,8 @@ # class Job < ActiveRecord::Base + acts_as_paranoid + belongs_to :project has_many :builds diff --git a/db/migrate/20150415142013_add_deleted_at_to_jobs.rb b/db/migrate/20150415142013_add_deleted_at_to_jobs.rb new file mode 100644 index 0000000..7a825a2 --- /dev/null +++ b/db/migrate/20150415142013_add_deleted_at_to_jobs.rb @@ -0,0 +1,6 @@ +class AddDeletedAtToJobs < ActiveRecord::Migration + def change + add_column :jobs, :deleted_at, :datetime + add_index :jobs, :deleted_at + end +end diff --git a/db/schema.rb b/db/schema.rb index e194f7a..65a1032 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20150330001111) do +ActiveRecord::Schema.define(version: 20150415142013) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -81,8 +81,10 @@ ActiveRecord::Schema.define(version: 20150330001111) do t.boolean "build_tags", default: false, null: false t.string "job_type", default: "parallel" t.string "refs" + t.datetime "deleted_at" end + add_index "jobs", ["deleted_at"], name: "index_jobs_on_deleted_at", using: :btree add_index "jobs", ["project_id"], name: "index_jobs_on_project_id", using: :btree create_table "projects", force: true do |t| |