diff options
author | Benjamin Neff <benjamin@coding4coffee.ch> | 2017-10-18 01:22:46 +0300 |
---|---|---|
committer | Benjamin Neff <benjamin@coding4coffee.ch> | 2017-10-18 02:08:26 +0300 |
commit | 9673f45ff9dc51166ad5fc97a7609a347a7cea20 (patch) | |
tree | 58bbaabaf09b44ef4b83b64e16c8b5beef804c52 /db | |
parent | 2e9c6f46dc6c01a63123445da876f23780b3398d (diff) |
Cleanup empty signatures
Some relayables from redmatrix and hubzilla have empty signatures. They
are invalid and break therefore the user data export.
closes #7644
Diffstat (limited to 'db')
-rw-r--r-- | db/migrate/20171017221434_cleanup_empty_signatures.rb | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/db/migrate/20171017221434_cleanup_empty_signatures.rb b/db/migrate/20171017221434_cleanup_empty_signatures.rb new file mode 100644 index 000000000..de12be8b1 --- /dev/null +++ b/db/migrate/20171017221434_cleanup_empty_signatures.rb @@ -0,0 +1,44 @@ +# frozen_string_literal: true + +class CleanupEmptySignatures < ActiveRecord::Migration[5.1] + class Comment < ApplicationRecord + belongs_to :commentable, polymorphic: true + + has_one :signature, class_name: "CommentSignature", dependent: :delete + + before_destroy do + Like.where(target_type: "Comment", target_id: id).destroy_all + ActsAsTaggableOn::Tagging.where(taggable_type: "Comment", taggable_id: id).destroy_all + end + + after_destroy do + commentable.update_comments_counter + end + end + + class Like < ApplicationRecord + belongs_to :target, polymorphic: true + + has_one :signature, class_name: "LikeSignature", dependent: :delete + + after_destroy do + target.update_likes_counter + end + end + + class PollParticipation < ApplicationRecord + belongs_to :poll_answer, counter_cache: :vote_count + + has_one :signature, class_name: "PollParticipationSignature", dependent: :delete + end + + def up + Comment.joins("INNER JOIN comment_signatures as signature ON comments.id = signature.comment_id") + .where("signature.author_signature = ''").destroy_all + Like.joins("INNER JOIN like_signatures as signature ON likes.id = signature.like_id") + .where("signature.author_signature = ''").destroy_all + PollParticipation.joins("INNER JOIN poll_participation_signatures as signature " \ + "ON poll_participations.id = signature.poll_participation_id") + .where("signature.author_signature = ''").destroy_all + end +end |