diff options
author | George Claghorn <george.claghorn@gmail.com> | 2018-07-20 16:24:27 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-07-20 16:24:27 -0400 |
commit | 205aa1462acb038df8f434e941d2a4d68f36acf5 (patch) | |
tree | 75060f917e38c84a410df43ee74c0e1a30234120 /activestorage/app | |
parent | 7b3ead3b26682ee331e0e67eb4e3962742f9aa5e (diff) | |
parent | 6c45b04a7399bb629bf17319dc3519a061d4d7a0 (diff) | |
download | rails-205aa1462acb038df8f434e941d2a4d68f36acf5.tar.gz rails-205aa1462acb038df8f434e941d2a4d68f36acf5.tar.bz2 rails-205aa1462acb038df8f434e941d2a4d68f36acf5.zip |
Merge pull request #33405 from georgeclaghorn/activestorage-referential-integrity
Add a foreign-key constraint to the active_storage_attachments table for blobs
Diffstat (limited to 'activestorage/app')
-rw-r--r-- | activestorage/app/jobs/active_storage/purge_job.rb | 2 | ||||
-rw-r--r-- | activestorage/app/models/active_storage/attachment.rb | 4 | ||||
-rw-r--r-- | activestorage/app/models/active_storage/blob.rb | 2 |
3 files changed, 4 insertions, 4 deletions
diff --git a/activestorage/app/jobs/active_storage/purge_job.rb b/activestorage/app/jobs/active_storage/purge_job.rb index fa15e0451d..b021b5f2d0 100644 --- a/activestorage/app/jobs/active_storage/purge_job.rb +++ b/activestorage/app/jobs/active_storage/purge_job.rb @@ -2,7 +2,7 @@ # Provides asynchronous purging of ActiveStorage::Blob records via ActiveStorage::Blob#purge_later. class ActiveStorage::PurgeJob < ActiveStorage::BaseJob - discard_on ActiveRecord::RecordNotFound + discard_on ActiveRecord::RecordNotFound, ActiveRecord::InvalidForeignKey def perform(blob) blob.purge diff --git a/activestorage/app/models/active_storage/attachment.rb b/activestorage/app/models/active_storage/attachment.rb index 5d36990fb9..1c4dc25094 100644 --- a/activestorage/app/models/active_storage/attachment.rb +++ b/activestorage/app/models/active_storage/attachment.rb @@ -19,14 +19,14 @@ class ActiveStorage::Attachment < ActiveRecord::Base # Synchronously deletes the attachment and {purges the blob}[rdoc-ref:ActiveStorage::Blob#purge]. def purge - blob.purge delete + blob.purge end # Deletes the attachment and {enqueues a background job}[rdoc-ref:ActiveStorage::Blob#purge_later] to purge the blob. def purge_later - blob.purge_later delete + blob.purge_later end private diff --git a/activestorage/app/models/active_storage/blob.rb b/activestorage/app/models/active_storage/blob.rb index b72f2e796d..bf87598a66 100644 --- a/activestorage/app/models/active_storage/blob.rb +++ b/activestorage/app/models/active_storage/blob.rb @@ -205,8 +205,8 @@ class ActiveStorage::Blob < ActiveRecord::Base # blobs. Note, though, that deleting the file off the service will initiate a HTTP connection to the service, which may # be slow or prevented, so you should not use this method inside a transaction or in callbacks. Use #purge_later instead. def purge - delete destroy + delete end # Enqueues an ActiveStorage::PurgeJob to call #purge. This is the recommended way to purge blobs from a transaction, |