mirror of
https://github.com/Retrospring/retrospring.git
synced 2024-11-20 10:29:53 +01:00
Make reportable models discardable
This commit is contained in:
parent
397ea9eaa4
commit
fab3a9323f
7 changed files with 28 additions and 2 deletions
|
@ -1,4 +1,5 @@
|
||||||
class Answer < ApplicationRecord
|
class Answer < ApplicationRecord
|
||||||
|
include Discard::Model
|
||||||
extend Answer::TimelineMethods
|
extend Answer::TimelineMethods
|
||||||
|
|
||||||
belongs_to :user
|
belongs_to :user
|
||||||
|
@ -21,7 +22,7 @@ class Answer < ApplicationRecord
|
||||||
|
|
||||||
before_destroy do
|
before_destroy do
|
||||||
# mark a report as deleted if it exists
|
# mark a report as deleted if it exists
|
||||||
rep = Report.where(target_id: self.id, type: 'Reports::Answer')
|
rep = Report.where(target_id: id, type: "Reports::Answer")
|
||||||
rep.each do |r|
|
rep.each do |r|
|
||||||
unless r.nil?
|
unless r.nil?
|
||||||
r.deleted = true
|
r.deleted = true
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class Appendable < ApplicationRecord
|
class Appendable < ApplicationRecord
|
||||||
|
include Discard::Model
|
||||||
|
|
||||||
belongs_to :parent, polymorphic: true
|
belongs_to :parent, polymorphic: true
|
||||||
belongs_to :user
|
belongs_to :user
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
class Comment < ApplicationRecord
|
class Comment < ApplicationRecord
|
||||||
|
include Discard::Model
|
||||||
|
|
||||||
belongs_to :user
|
belongs_to :user
|
||||||
belongs_to :answer
|
belongs_to :answer
|
||||||
validates :user_id, presence: true
|
validates :user_id, presence: true
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
class Question < ApplicationRecord
|
class Question < ApplicationRecord
|
||||||
include Question::AnswerMethods
|
include Question::AnswerMethods
|
||||||
|
include Discard::Model
|
||||||
|
|
||||||
belongs_to :user, optional: true
|
belongs_to :user, optional: true
|
||||||
has_many :answers, dependent: :destroy
|
has_many :answers, dependent: :destroy
|
||||||
|
|
|
@ -12,6 +12,7 @@ class User < ApplicationRecord
|
||||||
include User::RelationshipMethods
|
include User::RelationshipMethods
|
||||||
include User::TimelineMethods
|
include User::TimelineMethods
|
||||||
include ActiveModel::OneTimePassword
|
include ActiveModel::OneTimePassword
|
||||||
|
include Discard::Model
|
||||||
|
|
||||||
# Include default devise modules. Others available are:
|
# Include default devise modules. Others available are:
|
||||||
# :confirmable, :lockable, :timeoutable and :omniauthable
|
# :confirmable, :lockable, :timeoutable and :omniauthable
|
||||||
|
|
9
db/migrate/20220727174919_add_soft_deletes.rb
Normal file
9
db/migrate/20220727174919_add_soft_deletes.rb
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
class AddSoftDeletes < ActiveRecord::Migration[6.1]
|
||||||
|
def change
|
||||||
|
%i[answers appendables comments questions users].each do |table|
|
||||||
|
say "Migrating #{table}"
|
||||||
|
add_column table, :discarded_at, :datetime
|
||||||
|
add_index table, :discarded_at
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
12
db/schema.rb
12
db/schema.rb
|
@ -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: 2022_07_20_190421) do
|
ActiveRecord::Schema.define(version: 2022_07_27_174919) 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"
|
||||||
|
@ -46,6 +46,8 @@ ActiveRecord::Schema.define(version: 2022_07_20_190421) do
|
||||||
t.datetime "created_at"
|
t.datetime "created_at"
|
||||||
t.datetime "updated_at"
|
t.datetime "updated_at"
|
||||||
t.integer "smile_count", default: 0, null: false
|
t.integer "smile_count", default: 0, null: false
|
||||||
|
t.datetime "discarded_at"
|
||||||
|
t.index ["discarded_at"], name: "index_answers_on_discarded_at"
|
||||||
t.index ["question_id"], name: "index_answers_on_question_id"
|
t.index ["question_id"], name: "index_answers_on_question_id"
|
||||||
t.index ["user_id", "created_at"], name: "index_answers_on_user_id_and_created_at"
|
t.index ["user_id", "created_at"], name: "index_answers_on_user_id_and_created_at"
|
||||||
end
|
end
|
||||||
|
@ -58,6 +60,8 @@ ActiveRecord::Schema.define(version: 2022_07_20_190421) do
|
||||||
t.text "content"
|
t.text "content"
|
||||||
t.datetime "created_at", precision: 6, null: false
|
t.datetime "created_at", precision: 6, null: false
|
||||||
t.datetime "updated_at", precision: 6, null: false
|
t.datetime "updated_at", precision: 6, null: false
|
||||||
|
t.datetime "discarded_at"
|
||||||
|
t.index ["discarded_at"], name: "index_appendables_on_discarded_at"
|
||||||
t.index ["parent_id", "parent_type"], name: "index_appendables_on_parent_id_and_parent_type"
|
t.index ["parent_id", "parent_type"], name: "index_appendables_on_parent_id_and_parent_type"
|
||||||
t.index ["user_id", "created_at"], name: "index_appendables_on_user_id_and_created_at"
|
t.index ["user_id", "created_at"], name: "index_appendables_on_user_id_and_created_at"
|
||||||
end
|
end
|
||||||
|
@ -69,7 +73,9 @@ ActiveRecord::Schema.define(version: 2022_07_20_190421) do
|
||||||
t.datetime "created_at"
|
t.datetime "created_at"
|
||||||
t.datetime "updated_at"
|
t.datetime "updated_at"
|
||||||
t.integer "smile_count", default: 0, null: false
|
t.integer "smile_count", default: 0, null: false
|
||||||
|
t.datetime "discarded_at"
|
||||||
t.index ["answer_id"], name: "index_comments_on_answer_id"
|
t.index ["answer_id"], name: "index_comments_on_answer_id"
|
||||||
|
t.index ["discarded_at"], name: "index_comments_on_discarded_at"
|
||||||
t.index ["user_id", "created_at"], name: "index_comments_on_user_id_and_created_at"
|
t.index ["user_id", "created_at"], name: "index_comments_on_user_id_and_created_at"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -144,6 +150,8 @@ ActiveRecord::Schema.define(version: 2022_07_20_190421) do
|
||||||
t.datetime "updated_at"
|
t.datetime "updated_at"
|
||||||
t.integer "answer_count", default: 0, null: false
|
t.integer "answer_count", default: 0, null: false
|
||||||
t.boolean "direct", default: false, null: false
|
t.boolean "direct", default: false, null: false
|
||||||
|
t.datetime "discarded_at"
|
||||||
|
t.index ["discarded_at"], name: "index_questions_on_discarded_at"
|
||||||
t.index ["user_id", "created_at"], name: "index_questions_on_user_id_and_created_at"
|
t.index ["user_id", "created_at"], name: "index_questions_on_user_id_and_created_at"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -292,7 +300,9 @@ ActiveRecord::Schema.define(version: 2022_07_20_190421) do
|
||||||
t.datetime "export_created_at"
|
t.datetime "export_created_at"
|
||||||
t.string "otp_secret_key"
|
t.string "otp_secret_key"
|
||||||
t.integer "otp_module", default: 0, null: false
|
t.integer "otp_module", default: 0, null: false
|
||||||
|
t.datetime "discarded_at"
|
||||||
t.index ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true
|
t.index ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true
|
||||||
|
t.index ["discarded_at"], name: "index_users_on_discarded_at"
|
||||||
t.index ["email"], name: "index_users_on_email", unique: true
|
t.index ["email"], name: "index_users_on_email", unique: true
|
||||||
t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
|
t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
|
||||||
t.index ["screen_name"], name: "index_users_on_screen_name", unique: true
|
t.index ["screen_name"], name: "index_users_on_screen_name", unique: true
|
||||||
|
|
Loading…
Reference in a new issue