active_record_proxy_adapters 0.3.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -1
- data/LICENSE.txt +1 -1
- data/lib/active_record_proxy_adapters/connection_handling/mysql2.rb +39 -0
- data/lib/active_record_proxy_adapters/connection_handling/postgresql.rb +40 -0
- data/lib/active_record_proxy_adapters/connection_handling.rb +2 -52
- data/lib/active_record_proxy_adapters/version.rb +1 -1
- metadata +5 -6
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 151caa80f35f53ad02ef3307a55ef0fec4f1a6f369e6afac8d063e4ea2ad5e7f
         | 
| 4 | 
            +
              data.tar.gz: 60213ad52a363c435514038eeb65227bff7132b91a6dbed86b8917459449c39e
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 7720b6fe6b2d6848d30444f77c71d2567996f2e45011c79e6c4791e043b7d9333c2d92554cdf5f6b5a48c29c6b384509a00b9f9b3b930402d47c98188744daa7
         | 
| 7 | 
            +
              data.tar.gz: b73be535ad798afb4386d4027e4e92df00d9864a196d4cc1d30ad3a0a4e524c87ad12f67d214ef524a1641800ccf5bc2ab4911acf49c5606d867f51981a18fec
         | 
    
        data/CHANGELOG.md
    CHANGED
    
    | @@ -1,6 +1,10 @@ | |
| 1 1 | 
             
            ## [Unreleased]
         | 
| 2 2 |  | 
| 3 | 
            -
            -  | 
| 3 | 
            +
            - Fix Active Record adapters dependency loading
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            ## [0.3.0] - 2025-01-17
         | 
| 6 | 
            +
             | 
| 7 | 
            +
            - Add Mysql2ProxyAdapter https://github.com/Nasdaq/active_record_proxy_adapters/commit/7481b79dc93114f9b3b40faa8f3eecce90fe9104
         | 
| 4 8 |  | 
| 5 9 | 
             
            ## [0.2.2, 0.1.5] - 2025-01-02
         | 
| 6 10 |  | 
    
        data/LICENSE.txt
    CHANGED
    
    
| @@ -0,0 +1,39 @@ | |
| 1 | 
            +
            # frozen_string_literal: true
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            begin
         | 
| 4 | 
            +
              require "active_record/connection_adapters/mysql2_proxy_adapter"
         | 
| 5 | 
            +
            rescue LoadError
         | 
| 6 | 
            +
              # mysql2 not available
         | 
| 7 | 
            +
              return
         | 
| 8 | 
            +
            end
         | 
| 9 | 
            +
             | 
| 10 | 
            +
            module ActiveRecordProxyAdapters
         | 
| 11 | 
            +
              # Module to extend ActiveRecord::Base with the connection handling methods.
         | 
| 12 | 
            +
              # Required to make adapter work in ActiveRecord versions <= 7.2.x
         | 
| 13 | 
            +
              module ConnectionHandling
         | 
| 14 | 
            +
                def mysql2_proxy_adapter_class
         | 
| 15 | 
            +
                  ::ActiveRecord::ConnectionAdapters::Mysql2ProxyAdapter
         | 
| 16 | 
            +
                end
         | 
| 17 | 
            +
             | 
| 18 | 
            +
                # This method is a copy and paste from Rails' mysql2_connection,
         | 
| 19 | 
            +
                # replacing Mysql2Adapter by Mysql2ProxyAdapter
         | 
| 20 | 
            +
                # This is required by ActiveRecord versions <= 7.2.x to establish a connection using the adapter.
         | 
| 21 | 
            +
                def mysql2_proxy_connection(config) # rubocop:disable Metrics/MethodLength
         | 
| 22 | 
            +
                  config = config.symbolize_keys
         | 
| 23 | 
            +
                  config[:flags] ||= 0
         | 
| 24 | 
            +
             | 
| 25 | 
            +
                  if config[:flags].is_a? Array
         | 
| 26 | 
            +
                    config[:flags].push "FOUND_ROWS"
         | 
| 27 | 
            +
                  else
         | 
| 28 | 
            +
                    config[:flags] |= Mysql2::Client::FOUND_ROWS
         | 
| 29 | 
            +
                  end
         | 
| 30 | 
            +
             | 
| 31 | 
            +
                  mysql2_proxy_adapter_class.new(
         | 
| 32 | 
            +
                    mysql2_proxy_adapter_class.new_client(config),
         | 
| 33 | 
            +
                    logger,
         | 
| 34 | 
            +
                    nil,
         | 
| 35 | 
            +
                    config
         | 
| 36 | 
            +
                  )
         | 
| 37 | 
            +
                end
         | 
| 38 | 
            +
              end
         | 
| 39 | 
            +
            end
         | 
| @@ -0,0 +1,40 @@ | |
| 1 | 
            +
            # frozen_string_literal: true
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            begin
         | 
| 4 | 
            +
              require "active_record/connection_adapters/postgresql_proxy_adapter"
         | 
| 5 | 
            +
            rescue LoadError
         | 
| 6 | 
            +
              # Postgres not available
         | 
| 7 | 
            +
              return
         | 
| 8 | 
            +
            end
         | 
| 9 | 
            +
             | 
| 10 | 
            +
            module ActiveRecordProxyAdapters
         | 
| 11 | 
            +
              # Module to extend ActiveRecord::Base with the connection handling methods.
         | 
| 12 | 
            +
              # Required to make adapter work in ActiveRecord versions <= 7.2.x
         | 
| 13 | 
            +
              module ConnectionHandling
         | 
| 14 | 
            +
                def postgresql_proxy_adapter_class
         | 
| 15 | 
            +
                  ::ActiveRecord::ConnectionAdapters::PostgreSQLProxyAdapter
         | 
| 16 | 
            +
                end
         | 
| 17 | 
            +
             | 
| 18 | 
            +
                # This method is a copy and paste from Rails' postgresql_connection,
         | 
| 19 | 
            +
                # replacing PostgreSQLAdapter by PostgreSQLProxyAdapter
         | 
| 20 | 
            +
                # This is required by ActiveRecord versions <= 7.2.x to establish a connection using the adapter.
         | 
| 21 | 
            +
                def postgresql_proxy_connection(config) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
         | 
| 22 | 
            +
                  conn_params = config.symbolize_keys.compact
         | 
| 23 | 
            +
             | 
| 24 | 
            +
                  # Map ActiveRecords param names to PGs.
         | 
| 25 | 
            +
                  conn_params[:user]   = conn_params.delete(:username) if conn_params[:username]
         | 
| 26 | 
            +
                  conn_params[:dbname] = conn_params.delete(:database) if conn_params[:database]
         | 
| 27 | 
            +
             | 
| 28 | 
            +
                  # Forward only valid config params to PG::Connection.connect.
         | 
| 29 | 
            +
                  valid_conn_param_keys = PG::Connection.conndefaults_hash.keys + [:requiressl]
         | 
| 30 | 
            +
                  conn_params.slice!(*valid_conn_param_keys)
         | 
| 31 | 
            +
             | 
| 32 | 
            +
                  postgresql_proxy_adapter_class.new(
         | 
| 33 | 
            +
                    postgresql_proxy_adapter_class.new_client(conn_params),
         | 
| 34 | 
            +
                    logger,
         | 
| 35 | 
            +
                    conn_params,
         | 
| 36 | 
            +
                    config
         | 
| 37 | 
            +
                  )
         | 
| 38 | 
            +
                end
         | 
| 39 | 
            +
              end
         | 
| 40 | 
            +
            end
         | 
| @@ -1,61 +1,11 @@ | |
| 1 1 | 
             
            # frozen_string_literal: true
         | 
| 2 2 |  | 
| 3 | 
            -
            require " | 
| 4 | 
            -
            require " | 
| 3 | 
            +
            require "active_record_proxy_adapters/connection_handling/postgresql"
         | 
| 4 | 
            +
            require "active_record_proxy_adapters/connection_handling/mysql2"
         | 
| 5 5 |  | 
| 6 6 | 
             
            module ActiveRecordProxyAdapters
         | 
| 7 7 | 
             
              # Module to extend ActiveRecord::Base with the connection handling methods.
         | 
| 8 8 | 
             
              # Required to make adapter work in ActiveRecord versions <= 7.2.x
         | 
| 9 9 | 
             
              module ConnectionHandling
         | 
| 10 | 
            -
                def postgresql_proxy_adapter_class
         | 
| 11 | 
            -
                  ::ActiveRecord::ConnectionAdapters::PostgreSQLProxyAdapter
         | 
| 12 | 
            -
                end
         | 
| 13 | 
            -
             | 
| 14 | 
            -
                # This method is a copy and paste from Rails' postgresql_connection,
         | 
| 15 | 
            -
                # replacing PostgreSQLAdapter by PostgreSQLProxyAdapter
         | 
| 16 | 
            -
                # This is required by ActiveRecord versions <= 7.2.x to establish a connection using the adapter.
         | 
| 17 | 
            -
                def postgresql_proxy_connection(config) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
         | 
| 18 | 
            -
                  conn_params = config.symbolize_keys.compact
         | 
| 19 | 
            -
             | 
| 20 | 
            -
                  # Map ActiveRecords param names to PGs.
         | 
| 21 | 
            -
                  conn_params[:user]   = conn_params.delete(:username) if conn_params[:username]
         | 
| 22 | 
            -
                  conn_params[:dbname] = conn_params.delete(:database) if conn_params[:database]
         | 
| 23 | 
            -
             | 
| 24 | 
            -
                  # Forward only valid config params to PG::Connection.connect.
         | 
| 25 | 
            -
                  valid_conn_param_keys = PG::Connection.conndefaults_hash.keys + [:requiressl]
         | 
| 26 | 
            -
                  conn_params.slice!(*valid_conn_param_keys)
         | 
| 27 | 
            -
             | 
| 28 | 
            -
                  postgresql_proxy_adapter_class.new(
         | 
| 29 | 
            -
                    postgresql_proxy_adapter_class.new_client(conn_params),
         | 
| 30 | 
            -
                    logger,
         | 
| 31 | 
            -
                    conn_params,
         | 
| 32 | 
            -
                    config
         | 
| 33 | 
            -
                  )
         | 
| 34 | 
            -
                end
         | 
| 35 | 
            -
             | 
| 36 | 
            -
                def mysql2_proxy_adapter_class
         | 
| 37 | 
            -
                  ::ActiveRecord::ConnectionAdapters::Mysql2ProxyAdapter
         | 
| 38 | 
            -
                end
         | 
| 39 | 
            -
             | 
| 40 | 
            -
                # This method is a copy and paste from Rails' mysql2_connection,
         | 
| 41 | 
            -
                # replacing Mysql2Adapter by Mysql2ProxyAdapter
         | 
| 42 | 
            -
                # This is required by ActiveRecord versions <= 7.2.x to establish a connection using the adapter.
         | 
| 43 | 
            -
                def mysql2_proxy_connection(config) # rubocop:disable Metrics/MethodLength
         | 
| 44 | 
            -
                  config = config.symbolize_keys
         | 
| 45 | 
            -
                  config[:flags] ||= 0
         | 
| 46 | 
            -
             | 
| 47 | 
            -
                  if config[:flags].is_a? Array
         | 
| 48 | 
            -
                    config[:flags].push "FOUND_ROWS"
         | 
| 49 | 
            -
                  else
         | 
| 50 | 
            -
                    config[:flags] |= Mysql2::Client::FOUND_ROWS
         | 
| 51 | 
            -
                  end
         | 
| 52 | 
            -
             | 
| 53 | 
            -
                  mysql2_proxy_adapter_class.new(
         | 
| 54 | 
            -
                    mysql2_proxy_adapter_class.new_client(config),
         | 
| 55 | 
            -
                    logger,
         | 
| 56 | 
            -
                    nil,
         | 
| 57 | 
            -
                    config
         | 
| 58 | 
            -
                  )
         | 
| 59 | 
            -
                end
         | 
| 60 10 | 
             
              end
         | 
| 61 11 | 
             
            end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,13 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: active_record_proxy_adapters
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.3. | 
| 4 | 
            +
              version: 0.3.1
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Matt Cruz
         | 
| 8 | 
            -
            autorequire:
         | 
| 9 8 | 
             
            bindir: exe
         | 
| 10 9 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2025- | 
| 10 | 
            +
            date: 2025-02-12 00:00:00.000000000 Z
         | 
| 12 11 | 
             
            dependencies:
         | 
| 13 12 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 13 | 
             
              name: activerecord
         | 
| @@ -79,6 +78,8 @@ files: | |
| 79 78 | 
             
            - lib/active_record_proxy_adapters/active_record_context.rb
         | 
| 80 79 | 
             
            - lib/active_record_proxy_adapters/configuration.rb
         | 
| 81 80 | 
             
            - lib/active_record_proxy_adapters/connection_handling.rb
         | 
| 81 | 
            +
            - lib/active_record_proxy_adapters/connection_handling/mysql2.rb
         | 
| 82 | 
            +
            - lib/active_record_proxy_adapters/connection_handling/postgresql.rb
         | 
| 82 83 | 
             
            - lib/active_record_proxy_adapters/database_tasks.rb
         | 
| 83 84 | 
             
            - lib/active_record_proxy_adapters/hijackable.rb
         | 
| 84 85 | 
             
            - lib/active_record_proxy_adapters/log_subscriber.rb
         | 
| @@ -99,7 +100,6 @@ metadata: | |
| 99 100 | 
             
              source_code_uri: https://github.com/Nasdaq/active_record_proxy_adapters
         | 
| 100 101 | 
             
              changelog_uri: https://github.com/Nasdaq/active_record_proxy_adapters/blob/main/CHANGELOG.md
         | 
| 101 102 | 
             
              rubygems_mfa_required: 'true'
         | 
| 102 | 
            -
            post_install_message:
         | 
| 103 103 | 
             
            rdoc_options: []
         | 
| 104 104 | 
             
            require_paths:
         | 
| 105 105 | 
             
            - lib
         | 
| @@ -114,8 +114,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement | |
| 114 114 | 
             
                - !ruby/object:Gem::Version
         | 
| 115 115 | 
             
                  version: '0'
         | 
| 116 116 | 
             
            requirements: []
         | 
| 117 | 
            -
            rubygems_version: 3. | 
| 118 | 
            -
            signing_key:
         | 
| 117 | 
            +
            rubygems_version: 3.6.2
         | 
| 119 118 | 
             
            specification_version: 4
         | 
| 120 119 | 
             
            summary: Read replica proxy adapters for ActiveRecord!
         | 
| 121 120 | 
             
            test_files: []
         |