Rename tenant's storage folder when modifying the schema
This commit is contained in:
committed by
Senén Rodero Rodríguez
parent
b8156040a5
commit
b3012caac7
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user