-
-
Notifications
You must be signed in to change notification settings - Fork 199
Feature: Add multi-config #918
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
ed7f84e
to
fcf6012
Compare
fcf6012
to
ae595c3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
First of all thank you for your interest to Dynamoid and I appreciate efforts you put into this big pull request. As I mentioned in a comment above there are already a few discussions regarding functionality and interface this feature is supposed to have. I wish you have joined one of them before starting working on the code. So have been thinking about this feature for quite a long time and have some opinion that would like to share with you. The feature users were asking for is very close to the Rails's Multiple Databases (see the guide). As far as Dynamoid is trying to mimic Rails ActiveRecord's API as much as possible (to be sometimes a drop-in replacement) it's beneficial to review the Rails' multi database approach and borrow from the Rails' interface parts that work well for Dynamoid. Multi config conceptHow it's done in Rails and it completely makes sense for Dynamoid as well is to have not a complete fully fledged config per database, but only connection-related options like This way we talk about not config but connection config/profile/etc. So Rails' terminology completely makes sense in Dynamoid too, e.g. method names like For instance a model configuration may look like class User
include Dynamoid::Document
connects_to :primary
# ...
end And configuration like this: config do |c|
c.access_key = ENV['PRIMARY_AWS_ACCESS_KEY']
c.secret_key = ENV['PRIMARY_AWS_SECRET_KEY']
c.region = 'us-east-1'
c.namespace = 'myapp_primary'
end
config :analytics do |c|
c.access_key = ENV['ANALYTICS_AWS_ACCESS_KEY']
c.secret_key = ENV['ANALYTICS_AWS_SECRET_KEY']
c.region = 'us-west-2'
c.namespace = 'myapp_analytics'
end Configuration ManagementI would keep it as small as possible and add methods only when users ask for them. So instead of
And I wouldn't expose I've reviewed the pull request briefly and there might be more low-level remarks regarding particular line of code. So once again thank you for your efforts and look forward for your next iteration on this pull request. |
Thank you sincerely for your insightful and valuable comments. I will respectfully revise this pull request at my earliest convenience. |
@andrykonchin @vietdevne I do see the sometimes benefit of using access keys while developing, however. In production, keys should be avoided. When you create a key in AWS you'll see a long list of alternative authentication methods and reasons to use them. |
Add Multi-Configuration Support for Cross-Account DynamoDB Access
🎯 Overview
This PR introduces multi-configuration support to Dynamoid, enabling applications to connect to multiple DynamoDB instances across different AWS accounts, regions, and environments within a single application. This feature is particularly valuable for:
🚀 Key Features
1. Multi-Configuration Registry
2. Model-Level Configuration
dynamoid_config
method to specify which configuration a model should use3. Isolated Connection Management
📝 Usage Examples
Basic Multi-Configuration Setup
Model Configuration
🔧 Implementation Details
New Files Added:
lib/dynamoid/multi_config.rb
- Core multi-configuration functionalitylib/dynamoid/errors.rb
- AddedUnknownConfiguration
errorFiles Modified:
lib/dynamoid.rb
- Added multi-config require and helper methodslib/dynamoid/document.rb
- Added model-level configuration supportlib/dynamoid/persistence.rb
- Updated to use model-specific adapterslib/dynamoid/finders.rb
- Updated to use model-specific adapterslib/dynamoid/criteria/chain.rb
- Updated to use model-specific adapterslib/dynamoid/persistence/*.rb
- Updated all persistence operationsREADME.md
- Comprehensive multi-config documentationArchitecture:
🧪 Test Coverage
🔄 Backward Compatibility
dynamoid_config
automatically use the default configuration📊 Benefits
🛡️ Error Handling
Dynamoid::Errors::UnknownConfiguration
for invalid configuration names📚 Documentation
🔍 Configuration Management
🎯 Use Cases Addressed
This implementation provides a robust, scalable solution for complex DynamoDB connectivity requirements while maintaining the simplicity and elegance that makes Dynamoid popular.
Breaking Changes: None ✅
Migration Required: No ✅
Backward Compatible: Yes ✅