Rename tenant's storage folder when modifying the schema

This commit is contained in:
Senén Rodero Rodríguez
2023-12-12 15:57:50 +01:00
committed by Senén Rodero Rodríguez
parent b8156040a5
commit b3012caac7
2 changed files with 55 additions and 0 deletions

View File

@@ -172,9 +172,21 @@ class Tenant < ApplicationRecord
ActiveRecord::Base.connection.execute(
"ALTER SCHEMA \"#{schema_before_last_save}\" RENAME TO \"#{schema}\";"
)
rename_storage
end
end
def rename_storage
return unless ActiveStorage::Blob.service.is_a?(ActiveStorage::Service::TenantDiskService)
old_storage = File.join(ActiveStorage::Blob.service.root, "tenants", schema_before_last_save)
return unless File.directory?(old_storage)
new_storage = File.join(ActiveStorage::Blob.service.root, "tenants", schema)
File.rename(old_storage, new_storage)
end
def destroy_schema
Apartment::Tenant.drop(schema)
end