Skip to content
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

feat: Add configurable session store with ActiveRecord #472

Merged
merged 2 commits into from
Jan 11, 2024
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
4 changes: 3 additions & 1 deletion .env-example
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,6 @@ DECIDIM_ADMIN_PASSWORD_STRONG="false"
# PUMA_MIN_THREADS=5
# PUMA_MAX_THREADS=5
# PUMA_WORKERS=0
# PUMA_PRELOAD_APP=false
# PUMA_PRELOAD_APP=false

# RAILS_SESSION_STORE=active_record
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ gem "omniauth-publik", git: "https://github.com/OpenSourcePolitics/omniauth-publ

# Default
gem "activejob-uniqueness", require: "active_job/uniqueness/sidekiq_patch"
gem "activerecord-session_store"
gem "aws-sdk-s3", require: false
gem "bootsnap", "~> 1.4"
gem "deepl-rb", require: "deepl"
Expand Down
9 changes: 9 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,13 @@ GEM
activerecord (6.1.7.6)
activemodel (= 6.1.7.6)
activesupport (= 6.1.7.6)
activerecord-session_store (2.1.0)
actionpack (>= 6.1)
activerecord (>= 6.1)
cgi (>= 0.3.6)
multi_json (~> 1.11, >= 1.11.2)
rack (>= 2.0.8, < 4)
railties (>= 6.1)
activestorage (6.1.7.6)
actionpack (= 6.1.7.6)
activejob (= 6.1.7.6)
Expand Down Expand Up @@ -244,6 +251,7 @@ GEM
cells-rails (0.1.5)
actionpack (>= 5.0)
cells (>= 4.1.6, < 5.0.0)
cgi (0.4.1)
charlock_holmes (0.7.7)
chef-utils (18.3.0)
concurrent-ruby
Expand Down Expand Up @@ -1069,6 +1077,7 @@ PLATFORMS

DEPENDENCIES
activejob-uniqueness
activerecord-session_store
aws-sdk-s3
bootsnap (~> 1.4)
brakeman (~> 5.1)
Expand Down
7 changes: 7 additions & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,12 @@ class Application < Rails::Application
config.initial_query = "{\n deployment {\n version\n branch\n remote\n upToDate\n currentCommit\n latestCommit\n locallyModified\n }\n}".html_safe
end
end

if ENV.fetch("RAILS_SESSION_STORE", "") == "active_record"
initializer "session cookie domain", after: "Expire sessions" do
Rails.application.config.session_store :active_record_store, key: "_decidim_session", expire_after: Decidim.config.expire_session_after
ActiveRecord::SessionStore::Session.serializer = :hybrid
end
end
end
end
16 changes: 16 additions & 0 deletions db/migrate/20240109144022_add_sessions_table.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class AddSessionsTable < ActiveRecord::Migration[6.1]
def up
create_table :sessions do |t|
t.string :session_id, null: false
t.text :data
t.timestamps
end

add_index :sessions, :session_id, unique: true
add_index :sessions, :updated_at
end

def down
drop_table :sessions
end
end
11 changes: 10 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2023_11_27_192451) do
ActiveRecord::Schema.define(version: 2024_01_09_144022) do

# These are extensions that must be enabled in order to support this database
enable_extension "ltree"
Expand Down Expand Up @@ -2052,6 +2052,15 @@
t.index ["redirect_rule_id"], name: "index_request_environment_rules_on_redirect_rule_id"
end

create_table "sessions", force: :cascade do |t|
t.string "session_id", null: false
t.text "data"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.index ["session_id"], name: "index_sessions_on_session_id", unique: true
t.index ["updated_at"], name: "index_sessions_on_updated_at"
end

create_table "versions", force: :cascade do |t|
t.string "item_type", null: false
t.integer "item_id", null: false
Expand Down
2 changes: 2 additions & 0 deletions docker-compose.local.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ services:
- PUMA_MAX_THREADS=5
- PUMA_WORKERS=4
- PUMA_PRELOAD_APP=true
- RAILS_SESSION_STORE=active_record
depends_on:
- app
volumes:
Expand Down Expand Up @@ -70,6 +71,7 @@ services:
- PUMA_MAX_THREADS=5
- PUMA_WORKERS=4
- PUMA_PRELOAD_APP=true
- RAILS_SESSION_STORE=active_record
volumes:
- shared-volume:/app
ports:
Expand Down
Loading