Skip to content

Provide methods to find names of the snapshot collections #5

Open
@dblock

Description

@dblock

Problem

We have a Rake task that copies data from a production database to staging. We only want to copy the most recent snapshots, not everything.

Solution

Reimplement the following, but better.

      # find the names of the collections for the most recent index
      # this generates a hash with entries like {"artist_gene_value_indices"=>"snapshot-794"}
      from = ... client
      recent_indexes = {}
      Mongoid.models.select do |model|
        model.new.respond_to?(:import_version)
      end.each do |model|
        snapshot = from[model.collection.name].find.sort(_id: -1).first
        recent_indexes[model.collection.name] = snapshot['_slugs'].first
      end
      # select actual collection names
      # this returns a list like
      #  tag_partitioned_artwork_similarity_indices.output.snapshot-857
      #  tag_partitioned_artwork_similarity_indices.ranked_partitions.snapshot-857
      from_imports = ... client
      collections = from_imports.collections.map(&:name).select do |name|
        recent_indexes.detect do |base_name, slug|
          name =~ /^#{base_name}\.([^\.]+\.)?#{slug}$/
        end
      end

I think I want to have AverageArtistPrice.latest.collections that returns mongoid collections for each of which we can do documents(collection.name).

Note that we cannot be looking at document_classes because that's constructed on-demand.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions