adds discard gem, move deletion of repositories in a rake task to run in background worker [fixes SCI-2448]

This commit is contained in:
zmagod 2018-05-24 14:39:25 +02:00
parent f972676f8d
commit b13e39a0d9
7 changed files with 29 additions and 5 deletions

View file

@ -77,6 +77,8 @@ gem 'devise-async',
git: 'https://github.com/mhfs/devise-async.git', git: 'https://github.com/mhfs/devise-async.git',
branch: 'devise-4.x' branch: 'devise-4.x'
gem 'discard', '~> 1.0'
gem 'ruby-graphviz', '~> 1.2' # Graphviz for rails gem 'ruby-graphviz', '~> 1.2' # Graphviz for rails
gem 'tinymce-rails', '~> 4.6.4' # Rich text editor gem 'tinymce-rails', '~> 4.6.4' # Rich text editor

View file

@ -204,6 +204,8 @@ GEM
actionmailer (>= 4.1.0) actionmailer (>= 4.1.0)
devise (>= 4.0.0) devise (>= 4.0.0)
diff-lcs (1.3) diff-lcs (1.3)
discard (1.0.0)
activerecord (>= 4.2, < 6)
docile (1.1.5) docile (1.1.5)
erubi (1.7.0) erubi (1.7.0)
execjs (2.7.0) execjs (2.7.0)
@ -547,6 +549,7 @@ DEPENDENCIES
devise-async! devise-async!
devise_invitable devise_invitable
devise_security_extension! devise_security_extension!
discard (~> 1.0)
factory_bot_rails factory_bot_rails
faker faker
figaro figaro

View file

@ -1,6 +1,7 @@
class Repository < ApplicationRecord class Repository < ApplicationRecord
include SearchableModel include SearchableModel
include RepositoryImportParser include RepositoryImportParser
include Discard::Model
belongs_to :team, optional: true belongs_to :team, optional: true
belongs_to :created_by, belongs_to :created_by,
@ -22,6 +23,8 @@ class Repository < ApplicationRecord
validates :team, presence: true validates :team, presence: true
validates :created_by, presence: true validates :created_by, presence: true
default_scope -> { kept }
def self.search( def self.search(
user, user,
query = nil, query = nil,

View file

@ -1,7 +1,9 @@
class RemoveRepositoryRowsAndColumnsWithoutRepository < ActiveRecord::Migration[5.1] class RemoveRepositoryRowsAndColumnsWithoutRepository < ActiveRecord::Migration[5.1]
def up def up
repository_ids = Repository.select(:id) if column_exists?(:repositories, :discarded_at)
RepositoryRow.where.not(repository_id: repository_ids).delete_all repository_ids = Repository.select(:id)
RepositoryColumn.where.not(repository_id: repository_ids).delete_all RepositoryRow.where.not(repository_id: repository_ids).delete_all
RepositoryColumn.where.not(repository_id: repository_ids).delete_all
end
end end
end end

View file

@ -0,0 +1,6 @@
class AddDiscardToRepositories < ActiveRecord::Migration[5.1]
def change
add_column :repositories, :discarded_at, :datetime
add_index :repositories, :discarded_at
end
end

View file

@ -10,7 +10,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20180518113526) do ActiveRecord::Schema.define(version: 20180524091143) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
@ -363,6 +363,8 @@ ActiveRecord::Schema.define(version: 20180518113526) do
t.string "name" t.string "name"
t.datetime "created_at" t.datetime "created_at"
t.datetime "updated_at" t.datetime "updated_at"
t.datetime "discarded_at"
t.index ["discarded_at"], name: "index_repositories_on_discarded_at"
t.index ["team_id"], name: "index_repositories_on_team_id" t.index ["team_id"], name: "index_repositories_on_team_id"
end end

View file

@ -0,0 +1,6 @@
namespace :clear_discarded_repositories do
desc 'Removes all discarded repositories'
task run: :environment do
Repository.with_discarded.discarded.destroy_all
end
end