Last active
April 8, 2018 02:14
-
-
Save joeyAghion/9955727 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ImportBase | |
include Mongoid::Document | |
include Mongoid::Timestamps | |
field :import_version, type: String, default: 'v1' # legacy imports use 'v1' connection | |
before_create do | |
self.import_version = 'v2' # new imports use 'v2' connection | |
end | |
protected | |
def choose_connection | |
if import_version == 'v2' | |
Mongoid.session('imports') # alternate database configuration | |
else | |
self.class.mongo_session | |
end | |
end | |
end | |
class FooImport < ImportBase | |
def insert_data | |
# use choose_connection to insert data... | |
end | |
def get_data | |
# use choose_connection to retrieve data... | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment