Repository navigation
Conversation
Adds a DynamoDB adapter to Devise's ORM layer. The library is selected with `config.dynamodb_library` (:dynamoid by default, or :aws_record) before `require 'devise/orm/dynamodb'`. Supported modules: database_authenticatable, rememberable, validatable, confirmable (including reconfirmable), trackable, recoverable and lockable. registerable and timeoutable work as well. - OrmAdapter implementations for both libraries. Lookups Query a global secondary index when one exists and fall back to a consistent Scan. - An ActiveRecord-compatible layer for aws-record models (validations, callbacks, dirty tracking, create/update/find/reload/destroy). - A uniqueness validator matching ActiveRecord's options and messages. - Atomic failed_attempts increments for Lockable. - dynamodb:devise, dynamoid:devise and aws_record:devise generators, and DynamoDB support in devise:install. - devise:dynamodb:create_tables and devise:dynamodb:check_indexes tasks. - The full suite runs with DEVISE_ORM=dynamoid and DEVISE_ORM=aws_record, plus DynamoDB-specific unit tests and generator tests. CI starts DynamoDB Local for these jobs. - README section with setup steps and the behaviour that differs from ActiveRecord, and a sample app in examples/dynamodb_app. Co-Authored-By: Claude Code <noreply@anthropic.com>
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds Amazon DynamoDB support to Devise's ORM layer, through either of two libraries:
You pick the library in the initializer, before requiring the ORM:
Supported modules:
database_authenticatable,rememberable,validatable,confirmable(includingreconfirmable),trackable,recoverableandlockable.registerableandtimeoutablework as well, since they need no database support.omniauthableisn't supported yet.Opening this as a draft to get feedback on whether this belongs in Devise itself or would be better as a separate gem.
What's included
lib/devise/orm/dynamodb/). Lookups Query a global secondary index when one exists and fall back to a consistent Scan.Devise::Orm::Dynamodb::AwsRecordModeladds the subset of the ActiveRecord API that Devise and Rails forms rely on.case_sensitive,scope,allow_blank,conditions) and error message.failed_attemptsis incremented with an atomic DynamoDB update, likeincrement_counterin ActiveRecord.dynamodb:devise(plusdynamoid:deviseandaws_record:devise).devise:installwrites the DynamoDB setup when the ORM isdynamodb,dynamoidoraws_record.devise:dynamodb:create_tablesanddevise:dynamodb:check_indexes. The second one lists Devise lookups that would need a full table Scan.examples/dynamodb_apphas aUsermodel for each library, with integration tests covering all 7 modules over HTTP. It isn't included in the gem package.Differences from ActiveRecord
These are documented in the README.
after_*callback raises, the item has already been written.after_create/after_update, as with Mongoid, since there's noafter_commit.Changes to existing files
lib/devise/orm.rb: detects Dynamoid and aws-record models and includes the matching integration.lib/devise.rb: addsDevise.dynamodb_libraryandDevise::DYNAMODB_LIBRARIES.config/locales/en.yml: addserrors.messages.taken, which ActiveRecord and Mongoid ship themselves.test/support/locale/de.ymlandtest/helpers/devise_helper_test.rb: add theactivemodeltranslation scope that DynamoDB models use.test/models/confirmable_test.rb: the callback assertion'selsebranch now covers every ORM withoutafter_commit.dynamoidandaws_record, and starts DynamoDB Local for those jobs.Gemfileandgemfiles/*: adddynamoidandaws-recordgroups.Test plan
Run locally on Ruby 4.0 and Rails 8.1. The DynamoDB suites ran against moto, a DynamoDB emulator, because Docker wasn't available. CI uses DynamoDB Local instead, so the first CI run will be the first one against it.
DEVISE_ORM=active_record: 894 runs, 0 failuresDEVISE_ORM=dynamoid: 933 runs, 0 failures (the full existing suite, plus the new DynamoDB unit tests and generator tests)DEVISE_ORM=aws_record: 933 runs, 0 failuresgemfiles/Gemfile-rails-8-0: 0 failuresDEVISE_ORM=mongoid: not run locally (no MongoDB server). The Mongoid code path is unchanged.🤖 Generated with Claude Code