Sha256: 2231dac038766a5ab1dfc52979d3051cdb2191515ebc7af0da5fa666d865647f

Contents?: true

Size: 1.21 KB

Versions: 11

Compression:

Stored size: 1.21 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
        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

11 entries across 11 versions & 1 rubygems

Version Path
switchman-3.5.11 lib/switchman/active_record/persistence.rb
switchman-3.5.10 lib/switchman/active_record/persistence.rb
switchman-3.5.9 lib/switchman/active_record/persistence.rb
switchman-3.5.8 lib/switchman/active_record/persistence.rb
switchman-3.5.7 lib/switchman/active_record/persistence.rb
switchman-3.5.6 lib/switchman/active_record/persistence.rb
switchman-3.5.5 lib/switchman/active_record/persistence.rb
switchman-3.5.4 lib/switchman/active_record/persistence.rb
switchman-3.5.3 lib/switchman/active_record/persistence.rb
switchman-3.5.2 lib/switchman/active_record/persistence.rb
switchman-3.5.1 lib/switchman/active_record/persistence.rb