Sha256: 1d9a653ff1ff4e810fbf02694674b07e9da333006ed5f965ff93d4909656fd18

Contents?: true

Size: 1008 Bytes

Versions: 77

Compression:

Stored size: 1008 Bytes

Contents

# Resolve an issue where the wrong sequence name is used when
# importing data with Apartment and ActiveRecord::Import.
# See:
#   * https://github.com/zdennis/activerecord-import/issues/233
#   * https://github.com/influitive/apartment/issues/508

Rails.application.config.after_initialize do
  next unless defined?(Apartment)

  # Newer versions of Apartment already solves this issue (and in a better way)
  begin
    require('apartment/version')
    next if Gem::Version.new(Apartment::VERSION) >= Gem::Version.new('2.8.1')
  rescue LoadError
  end

  begin
    Rails.application.eager_load!
    ActiveRecord::Base.descendants.each do |model|
      seq_name = model.sequence_name
      if seq_name.present?
        tenant, seq_name = seq_name.include?(".") ? seq_name.split(".") : [nil, seq_name]
        model.sequence_name = seq_name
      end
    end
  rescue PG::ConnectionBad, ActiveRecord::NoDatabaseError, ActiveRecord::ConnectionNotEstablished
    # no-op if there is no database setup
  end
end

Version data entries

77 entries across 77 versions & 1 rubygems

Version Path
canvas_sync-0.22.9 config/initializers/apartment.rb
canvas_sync-0.22.8 config/initializers/apartment.rb
canvas_sync-0.22.6 config/initializers/apartment.rb
canvas_sync-0.22.5 config/initializers/apartment.rb
canvas_sync-0.22.4 config/initializers/apartment.rb
canvas_sync-0.22.3 config/initializers/apartment.rb
canvas_sync-0.22.2 config/initializers/apartment.rb
canvas_sync-0.22.1 config/initializers/apartment.rb
canvas_sync-0.22.0 config/initializers/apartment.rb
canvas_sync-0.22.0.beta8 config/initializers/apartment.rb
canvas_sync-0.22.0.beta7 config/initializers/apartment.rb
canvas_sync-0.22.0.beta6 config/initializers/apartment.rb
canvas_sync-0.22.0.beta5 config/initializers/apartment.rb
canvas_sync-0.22.0.beta4 config/initializers/apartment.rb
canvas_sync-0.22.0.beta3 config/initializers/apartment.rb
canvas_sync-0.22.0.beta2 config/initializers/apartment.rb
canvas_sync-0.22.0.beta1 config/initializers/apartment.rb
canvas_sync-0.21.1 config/initializers/apartment.rb
canvas_sync-0.21.1.beta1 config/initializers/apartment.rb
canvas_sync-0.21.0 config/initializers/apartment.rb