Sha256: 595c2a80fce22168d4f5160871fffae5b24e7b49d35b388cdde31209fcb32a8f

Contents?: true

Size: 1.33 KB

Versions: 20

Compression:

Stored size: 1.33 KB

Contents

# frozen_string_literal: true

module Switchman
  module ActiveRecord
    module Persistence
      # touch reads the id attribute directly, so it's not relative to the current shard
      def touch(*, **)
        writable_shadow_record_warning
        shard.activate(self.class.connection_class_for_self) { super }
      end

      def update_columns(*)
        writable_shadow_record_warning
        shard.activate(self.class.connection_class_for_self) { super }
      end

      def delete
        db = shard.database_server
        db.unguard { super }
      end

      def destroy
        writable_shadow_record_warning
        super
      end

      def create_or_update(**, &block)
        writable_shadow_record_warning
        super
      end

      def reload(*)
        res = super
        # When a shadow record is reloaded the real record is returned. So
        # we need to ensure the loaded_from_shard is set correctly after a reload.
        @loaded_from_shard = @shard
        if @readonly_from_shadow
          @readonly_from_shadow = false
          @readonly = false
        end
        res
      end

      def writable_shadow_record_warning
        return unless shadow_record? && Switchman.config[:writable_shadow_records]

        Switchman::Deprecation.warn("writing to shadow records is not supported")
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
switchman-4.0.0 lib/switchman/active_record/persistence.rb
switchman-3.6.8 lib/switchman/active_record/persistence.rb
switchman-3.6.7 lib/switchman/active_record/persistence.rb
switchman-3.6.6 lib/switchman/active_record/persistence.rb
switchman-3.6.5 lib/switchman/active_record/persistence.rb
switchman-3.6.3 lib/switchman/active_record/persistence.rb
switchman-3.6.2 lib/switchman/active_record/persistence.rb
switchman-3.6.1 lib/switchman/active_record/persistence.rb
switchman-3.6.0 lib/switchman/active_record/persistence.rb
switchman-3.5.22 lib/switchman/active_record/persistence.rb
switchman-3.5.21 lib/switchman/active_record/persistence.rb
switchman-3.5.20 lib/switchman/active_record/persistence.rb
switchman-3.5.19 lib/switchman/active_record/persistence.rb
switchman-3.5.18 lib/switchman/active_record/persistence.rb
switchman-3.5.17 lib/switchman/active_record/persistence.rb
switchman-3.5.16 lib/switchman/active_record/persistence.rb
switchman-3.5.15 lib/switchman/active_record/persistence.rb
switchman-3.5.14 lib/switchman/active_record/persistence.rb
switchman-3.5.13 lib/switchman/active_record/persistence.rb
switchman-3.5.12 lib/switchman/active_record/persistence.rb