[go: up one dir, main page]

ActiveContext: Start using connection model

What does this MR do and why?

This merge request updates the ActiveContext system to use a single active connection model instead of multiple databases. It introduces a new Connection model with an active scope, replaces the Config.databases with Config.connection_model, and modifies the adapter initialization process. The changes simplify the configuration and make it easier to manage active connections. Additionally, the code has been refactored to work with this new connection model, updating related tests and dependencies accordingly.

References

Please include cross links to any resources that are relevant to this MR. This will give reviewers and future readers helpful context to give an efficient review of the changes introduced.

MR acceptance checklist

Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Screenshots or screen recordings

Screenshots are required for UI changes, and strongly recommended for all other merge requests.

Before After

How to set up and validate locally

  1. Enable the gem via
    cat config/initializers/active_context.rb
    # frozen_string_literal: true
    
    ActiveContext.configure do |config|
      config.enabled = true
    end
  2. In rails create a new record
    ActiveContext::Config.connection_model.create!(active: true, name: 'pg1', options: {port: 5432, host: 'localhost', username: 'postgres', password: 'password'}, adapter_class: 'ActiveContext::Databases::Postgresql::Adapter', prefix: 'active_context')
  3. Create a file ee/db/active_context/migrate/20250123143913_create_merge_requests.rb with
    class CreateMergeRequests < ActiveContext::Migration[1.0]
      milestone '17.9'
    
      def migrate!
        create_collection :merge_requests, number_of_partitions: 3 do |c|
          c.bigint :issue_id, index: true
          c.bigint :namespace_id, index: true
          c.prefix :traversal_ids
          c.vector :embeddings, dimensions: 768
        end
      end
    end
  4. Start a postgresql container
    docker run -p 5432:5432 --name pgvector17 -e POSTGRES_PASSWORD=password pgvector/pgvector:pg17
  5. Execute the migration
    m = ActiveContext::Migration::Dictionary.migrations.last
    m.new.migrate!

Related to #521128 (closed)

Edited by Dmitry Gruzd

Merge request reports

Loading