Extract ActiveStorage::Record
Permit applications to hack in custom DB config for ASt models until ASt has first-class multi-DB support: ActiveSupport.on_load(:active_storage_record) do connects_to reading: :active_storage_replica, writing: :active_storage_primary end rebase
This commit is contained in:
parent
1e2cd7a75e
commit
a50d2f1993
|
@ -7,7 +7,7 @@ require "active_support/core_ext/module/delegation"
|
|||
# on the attachments table prevents blobs from being purged if they’re still attached to any records.
|
||||
#
|
||||
# Attachments also have access to all methods from {ActiveStorage::Blob}[rdoc-ref:ActiveStorage::Blob].
|
||||
class ActiveStorage::Attachment < ActiveRecord::Base
|
||||
class ActiveStorage::Attachment < ActiveStorage::Record
|
||||
self.table_name = "active_storage_attachments"
|
||||
|
||||
belongs_to :record, polymorphic: true, touch: true
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
# Blobs are intended to be immutable in as-so-far as their reference to a specific file goes. You're allowed to
|
||||
# update a blob's metadata on a subsequent pass, but you should not update the key or change the uploaded file.
|
||||
# If you need to create a derivative or otherwise change the blob, simply create a new blob and purge the old one.
|
||||
class ActiveStorage::Blob < ActiveRecord::Base
|
||||
class ActiveStorage::Blob < ActiveStorage::Record
|
||||
# We use constant paths in the following include calls to avoid a gotcha of
|
||||
# classic mode: If the parent application defines a top-level Analyzable, for
|
||||
# example, and ActiveStorage::Blob::Analyzable is not yet loaded, a bare
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class ActiveStorage::Record < ActiveRecord::Base #:nodoc:
|
||||
self.abstract_class = true
|
||||
end
|
||||
|
||||
ActiveSupport.run_load_hooks :active_storage_record, ActiveStorage::Record
|
|
@ -1,6 +1,6 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class ActiveStorage::VariantRecord < ActiveRecord::Base
|
||||
class ActiveStorage::VariantRecord < ActiveStorage::Record
|
||||
self.table_name = "active_storage_variant_records"
|
||||
|
||||
belongs_to :blob
|
||||
|
|
|
@ -133,7 +133,11 @@ class LoadingTest < ActiveSupport::TestCase
|
|||
require "#{rails_root}/config/environment"
|
||||
setup_ar!
|
||||
|
||||
initial = [ActiveStorage::Blob, ActiveStorage::Attachment, ActiveRecord::SchemaMigration, ActiveRecord::InternalMetadata, ApplicationRecord].collect(&:to_s).sort
|
||||
initial = [
|
||||
ActiveStorage::Record, ActiveStorage::Blob, ActiveStorage::Attachment,
|
||||
ActiveRecord::SchemaMigration, ActiveRecord::InternalMetadata, ApplicationRecord
|
||||
].collect(&:to_s).sort
|
||||
|
||||
assert_equal initial, ActiveRecord::Base.descendants.collect(&:to_s).sort.uniq
|
||||
get "/load"
|
||||
assert_equal [Post].collect(&:to_s).sort, ActiveRecord::Base.descendants.collect(&:to_s).sort - initial
|
||||
|
|
Loading…
Reference in New Issue