从 Active Storage 中删除所有数据? [英] Remove all data from Active Storage?
问题描述
我想知道如何从 Active Storage 中删除所有数据甚至重置 Active Storage?有没有办法做到这一点?提前致谢!
I would like to know how can I delete all data from Active Storage or even resetting Active Storage? There is any way to do that? Thank you in advance!
注意:我使用的是 Rails 5.2
NOTE: I'm using Rails 5.2
推荐答案
这个问题对我提出了挑战,所以我在我的带有本地存储的虚拟应用程序上做了一些测试.
This question challenged me, so I did some test on my dummy app with local storage.
我有通常的模型 User
其中 has_one_attached :avatar
I have the usual model User
which has_one_attached :avatar
本地存储文件保存在/storage
文件夹下,子文件夹下随机命名为两个字符的字符串.
On local storage files are saved on /storage
folder, under subfolders named randomly with a string of two characters.
与文件相关的信息存储在两个表中:
Informations related to files are stored in two tables:
为了彻底清理两个表,我在rails控制台
中做了:
ActiveStorage::Attachment.all.each { |attachment| attachment.purge }
该命令删除
- 该表中的所有记录:
ActiveStorage::Attachment.any?#=>假
- 所有的 blob:
ActiveStorage::Blob.any?#=>假
- 位于
/storage
子文件夹下的所有文件;当然,子文件夹仍然是空的.
- All record in that table:
ActiveStorage::Attachment.any? #=> false
- All the blobs:
ActiveStorage::Blob.any? #=> false
- All the files located under
/storage
subfolders; of course, subfolders are still there empty.
ActiveStorage 仍然可以正常工作.
The ActiveStorage still works poperly.
我希望远程存储具有相同的行为,并具有正确的权限.
I expect the same behaviour for remote storage, having the right privileges.
这篇关于从 Active Storage 中删除所有数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!