Class: ClaudeMemory::Commands::DbInitCommand

Inherits:
BaseCommand
  • Object
show all
Defined in:
lib/claude_memory/commands/db_init_command.rb

Overview

Initializes SQLite databases

Instance Attribute Summary

Attributes inherited from BaseCommand

#stderr, #stdin, #stdout

Instance Method Summary collapse

Methods inherited from BaseCommand

#initialize

Constructor Details

This class inherits a constructor from ClaudeMemory::Commands::BaseCommand

Instance Method Details

#call(args) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/claude_memory/commands/db_init_command.rb', line 7

def call(args)
  opts = parse_options(args, {global: false, project: false}) do |o|
    OptionParser.new do |parser|
      parser.banner = "Usage: claude-memory db:init [options]"
      parser.on("--global", "Initialize global database (~/.claude/memory.sqlite3)") { o[:global] = true }
      parser.on("--project", "Initialize project database (.claude/memory.sqlite3)") { o[:project] = true }
    end
  end
  return 1 if opts.nil?

  # If neither flag specified, initialize both
  opts[:global] = true if !opts[:global] && !opts[:project]
  opts[:project] = true if !opts[:global] && !opts[:project]

  manager = ClaudeMemory::Store::StoreManager.new

  if opts[:global]
    manager.ensure_global!
    stdout.puts "Global database initialized at #{manager.global_db_path}"
    stdout.puts "Schema version: #{manager.global_store.schema_version}"
  end

  if opts[:project]
    manager.ensure_project!
    stdout.puts "Project database initialized at #{manager.project_db_path}"
    stdout.puts "Schema version: #{manager.project_store.schema_version}"
  end

  manager.close
  0
end