Class: HotwireClub::MCP::Schema

Inherits:
Object
  • Object
show all
Defined in:
lib/hotwire_club/mcp/schema.rb

Constant Summary collapse

DB_PATH =
File.join(Dir.pwd, "db", "kb.sqlite")

Class Method Summary collapse

Class Method Details

.create!(db_path = DB_PATH) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/hotwire_club/mcp/schema.rb', line 11

def self.create!(db_path = DB_PATH)
  db_dir = File.dirname(db_path)
  FileUtils.mkdir_p(db_dir)
  FileUtils.rm_f(db_path)

  db = SQLite3::Database.new(db_path)

  create_docs_table(db)
  create_tags_table(db)
  create_doc_tags_table(db)
  create_chunks_table(db)

  db.close
end

.create_chunks_table(db) ⇒ Object

Create chunks FTS5 virtual table

Parameters:

  • db (SQLite3::Database)

    Database connection



69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/hotwire_club/mcp/schema.rb', line 69

def self.create_chunks_table(db)
  db.execute <<~SQL
    CREATE VIRTUAL TABLE chunks USING fts5(
      chunk_id,
      doc_id,
      title,
      text,
      category,
      tags,
      position,
      tokenize='porter'
    )
  SQL
end

.create_doc_tags_table(db) ⇒ Object

Create doc_tags table

Parameters:

  • db (SQLite3::Database)

    Database connection



56
57
58
59
60
61
62
63
64
# File 'lib/hotwire_club/mcp/schema.rb', line 56

def self.create_doc_tags_table(db)
  db.execute <<~SQL
    CREATE TABLE doc_tags (
      doc_id TEXT,
      tag TEXT,
      PRIMARY KEY (doc_id, tag)
    )
  SQL
end

.create_docs_table(db) ⇒ Object

Create docs table

Parameters:

  • db (SQLite3::Database)

    Database connection



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/hotwire_club/mcp/schema.rb', line 29

def self.create_docs_table(db)
  db.execute <<~SQL
    CREATE TABLE docs (
      id TEXT PRIMARY KEY,
      title TEXT,
      category TEXT,
      summary TEXT,
      body TEXT,
      date TEXT
    )
  SQL
end

.create_tags_table(db) ⇒ Object

Create tags table

Parameters:

  • db (SQLite3::Database)

    Database connection



45
46
47
48
49
50
51
# File 'lib/hotwire_club/mcp/schema.rb', line 45

def self.create_tags_table(db)
  db.execute <<~SQL
    CREATE TABLE tags (
      name TEXT PRIMARY KEY
    )
  SQL
end