mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-12-25 17:24:51 +08:00
adds discard gem, move deletion of repositories in a rake task to run in background worker [fixes SCI-2448]
This commit is contained in:
parent
f972676f8d
commit
b13e39a0d9
7 changed files with 29 additions and 5 deletions
2
Gemfile
2
Gemfile
|
@ -77,6 +77,8 @@ gem 'devise-async',
|
|||
git: 'https://github.com/mhfs/devise-async.git',
|
||||
branch: 'devise-4.x'
|
||||
|
||||
gem 'discard', '~> 1.0'
|
||||
|
||||
gem 'ruby-graphviz', '~> 1.2' # Graphviz for rails
|
||||
gem 'tinymce-rails', '~> 4.6.4' # Rich text editor
|
||||
|
||||
|
|
|
@ -204,6 +204,8 @@ GEM
|
|||
actionmailer (>= 4.1.0)
|
||||
devise (>= 4.0.0)
|
||||
diff-lcs (1.3)
|
||||
discard (1.0.0)
|
||||
activerecord (>= 4.2, < 6)
|
||||
docile (1.1.5)
|
||||
erubi (1.7.0)
|
||||
execjs (2.7.0)
|
||||
|
@ -547,6 +549,7 @@ DEPENDENCIES
|
|||
devise-async!
|
||||
devise_invitable
|
||||
devise_security_extension!
|
||||
discard (~> 1.0)
|
||||
factory_bot_rails
|
||||
faker
|
||||
figaro
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
class Repository < ApplicationRecord
|
||||
include SearchableModel
|
||||
include RepositoryImportParser
|
||||
|
||||
include Discard::Model
|
||||
|
||||
belongs_to :team, optional: true
|
||||
belongs_to :created_by,
|
||||
foreign_key: :created_by_id,
|
||||
|
@ -22,6 +23,8 @@ class Repository < ApplicationRecord
|
|||
validates :team, presence: true
|
||||
validates :created_by, presence: true
|
||||
|
||||
default_scope -> { kept }
|
||||
|
||||
def self.search(
|
||||
user,
|
||||
query = nil,
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
class RemoveRepositoryRowsAndColumnsWithoutRepository < ActiveRecord::Migration[5.1]
|
||||
def up
|
||||
repository_ids = Repository.select(:id)
|
||||
RepositoryRow.where.not(repository_id: repository_ids).delete_all
|
||||
RepositoryColumn.where.not(repository_id: repository_ids).delete_all
|
||||
if column_exists?(:repositories, :discarded_at)
|
||||
repository_ids = Repository.select(:id)
|
||||
RepositoryRow.where.not(repository_id: repository_ids).delete_all
|
||||
RepositoryColumn.where.not(repository_id: repository_ids).delete_all
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
6
db/migrate/20180524091143_add_discard_to_repositories.rb
Normal file
6
db/migrate/20180524091143_add_discard_to_repositories.rb
Normal 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
|
|
@ -10,7 +10,7 @@
|
|||
#
|
||||
# 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
|
||||
enable_extension "plpgsql"
|
||||
|
@ -363,6 +363,8 @@ ActiveRecord::Schema.define(version: 20180518113526) do
|
|||
t.string "name"
|
||||
t.datetime "created_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"
|
||||
end
|
||||
|
||||
|
|
6
lib/tasks/clear_discarded_repositories.rake
Normal file
6
lib/tasks/clear_discarded_repositories.rake
Normal 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
|
Loading…
Reference in a new issue