Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)
------------------

Expand Down
28 changes: 27 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion aws-actiondispatch-dynamodb.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
5 changes: 5 additions & 0 deletions test/action_dispatch/session/dynamo_db_store_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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