Merge pull request #5348 from consuldemocracy/rename_storage_folder

Rename tenant's storage folder when modifying the schema
This commit is contained in:
Senén Rodero
2024-01-19 17:16:43 +01:00
committed by GitHub
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