且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

从 Active Storage 中删除所有数据?

更新时间:2023-02-10 14:18:25

这个问题对我提出了挑战,所以我在我的带有本地存储的虚拟应用程序上做了一些测试.

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.