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/handling retries on sidekiq & set admin user before migrations and rollbacks #17

Merged

Conversation

juanmamaffei
Copy link

@juanmamaffei juanmamaffei commented Nov 29, 2023

Tries to solve #15 and #16.

As an additional suggestion, part of the initializer should be moved even before environment.rb, because, on the migrations, the password is taken from the mattr accessor of the gem instead of the initializer.

My solution was:

  1. Divide the initializer.
# config/initializers/pg_rls_database.rb
require 'pg_rls'

PgRls.setup do |config|
  ActiveRecord::ConnectionAdapters::AbstractAdapter.include PgRls::Schema::Statements

  config.class_name = :my_main_model
  config.table_name = :my_main_model
  config.search_methods = %i[id tenant_id]
  config.password = ENV.fetch('POSTGRES_PASSWORD', 'some_default_password')
end

(the following part should be loaded after Redis initialization)

#config/initializers/pg_rls_session.rb
PgRls.setup do |config|
  config.session_store_server = Rails.application.config_for(:redis).session
  config.session_key_prefix = "_hub_session_#{Rails.env}"
end

Requiring the db initializer on application.rb:

require_relative '../config/initializers/pg_rls_database'
  1. Removing the initialization on environment.rb because it is no longer necessary.

@juanmamaffei juanmamaffei marked this pull request as ready for review November 29, 2023 15:08
@Dandush03 Dandush03 merged commit 8c449eb into Dandush03:master Nov 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants