diff --git a/CHANGELOG.md b/CHANGELOG.md index 36689b2..0be4a7c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,8 @@ Unreleased Changes ------------------ +* Feature - [Major Version] Bump `aws-sessionstore-dynamodb` version to `~> 4`. The default `:serializer` is now `:json` instead of `:marshal`. To migrate existing sessions, set `:serializer` to `:json_allow_marshal`. + 1.0.0 (2024-11-21) ------------------ diff --git a/README.md b/README.md index 2113129..db31f1b 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ Add this gem to your Rails project's Gemfile: ```ruby gem 'aws-sdk-rails', '~> 5' -gem 'aws-actiondispatch-dynamodb', '~> 1' +gem 'aws-actiondispatch-dynamodb', '~> 2' ``` Then run `bundle install`. @@ -73,6 +73,32 @@ For more information about this feature and configuration options, see the class and the [GitHub repository](https://github.com/aws/aws-sessionstore-dynamodb-ruby). +### Session serialization + +As of version 2, session data is serialized as JSON by default. Earlier versions +used Ruby's `Marshal`. + +Session data must be made of JSON-compatible types (strings, numbers, booleans, +arrays, and hashes with string keys). Symbol keys are read back as strings, and +objects such as `Time` or custom classes are not preserved. + +If you are upgrading and your table has existing sessions, they were written +with `Marshal` and cannot be read by the default `:json` serializer. Set +`:serializer` to `:json_allow_marshal` so that existing sessions can still be +read while new sessions are written as JSON: + +```ruby +options = { + table_name: '_your_app_session', + serializer: :json_allow_marshal +} +Rails.application.config.session_store :dynamo_db_store, **options +``` + +`:json_allow_marshal` still reads session data with `Marshal`, so use it only +while migrating. Once the old sessions have expired, remove the option to use +`:json`. + ### Configuration file generator You can generate a configuration file for the session store using the following diff --git a/aws-actiondispatch-dynamodb.gemspec b/aws-actiondispatch-dynamodb.gemspec index 43bc24a..47ff901 100644 --- a/aws-actiondispatch-dynamodb.gemspec +++ b/aws-actiondispatch-dynamodb.gemspec @@ -13,7 +13,7 @@ Gem::Specification.new do |spec| spec.license = 'Apache-2.0' spec.files = Dir['LICENSE', 'CHANGELOG.md', 'VERSION', 'lib/**/*'] - spec.add_dependency('aws-sessionstore-dynamodb', '~> 3') + spec.add_dependency('aws-sessionstore-dynamodb', '~> 4') spec.add_dependency('actionpack', '>= 7.1.0') spec.add_dependency('railties', '>= 7.1.0') diff --git a/test/action_dispatch/session/dynamo_db_store_test.rb b/test/action_dispatch/session/dynamo_db_store_test.rb index cc9b21c..7221228 100644 --- a/test/action_dispatch/session/dynamo_db_store_test.rb +++ b/test/action_dispatch/session/dynamo_db_store_test.rb @@ -66,6 +66,11 @@ def teardown_env store = ActionDispatch::Session::DynamoDbStore.new(nil, options) assert_equal store.config.secret_key, secret_key end + + it 'serializes session data as JSON by default' do + store = ActionDispatch::Session::DynamoDbStore.new(nil, options) + assert_equal :json, store.config.serializer + end end end end