Module: RailsMcpCodeSearch::Database

Defined in:
lib/rails_mcp_code_search/database.rb

Defined Under Namespace

Classes: Metadata

Constant Summary collapse

DATA_DIR =
File.join(ENV.fetch("XDG_DATA_HOME", File.join(Dir.home, ".local", "share")), "rails-mcp-code-search")

Class Method Summary collapse

Class Method Details

.db_path_for(project_path) ⇒ Object



33
34
35
36
# File 'lib/rails_mcp_code_search/database.rb', line 33

def db_path_for(project_path)
  digest = Digest::SHA256.hexdigest(project_path)
  File.join(DATA_DIR, "#{digest}.db")
end

.setup(project_path: Dir.pwd, db_path: nil) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/rails_mcp_code_search/database.rb', line 11

def setup(project_path: Dir.pwd, db_path: nil)
  path = db_path || db_path_for(project_path)
  ensure_data_directory(File.dirname(path))

  Neighbor::SQLite.initialize!

  ActiveRecord::Base.establish_connection(
    adapter: "sqlite3",
    database: path,
    pool: 5,
    timeout: 5000
  )

  configure_pragmas
  create_schema
  Metadata.set "project_path", project_path

  File.chmod 0o600, path if File.exist?(path)

  path
end