internal/store/migrations/0072_symbols.up.sql
64 lines · 3131 bytes
1-- Symbol indexes (#293): the definitions found in the tree of a
2-- repository's default branch head. tree is the key: a head whose tree
3-- is the current index's needs no new one.
4--
5-- An index is written in chunks while its state is building, which no
6-- read sees; publishing it makes it ok or partial (a bound was reached,
7-- note says which) and retires the previous one in one short
8-- transaction. Building and retired rows are deleted, symbols first and
9-- in chunks, by the worker. At most one index per repository is current.
10--
11-- AUTOINCREMENT because a replaced index must not hand its id to the
12-- next: a paging cursor names the index it was taken from.
13CREATE TABLE symbol_indexes (
14 id INTEGER PRIMARY KEY AUTOINCREMENT,
15 repo_id INTEGER NOT NULL REFERENCES repos(id) ON DELETE CASCADE,
16 commit_sha TEXT NOT NULL,
17 tree TEXT NOT NULL,
18 state TEXT NOT NULL CHECK (state IN ('building', 'ok', 'partial', 'retired')),
19 note TEXT NOT NULL DEFAULT '',
20 files INTEGER NOT NULL DEFAULT 0,
21 symbols INTEGER NOT NULL DEFAULT 0,
22 built_at TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ','now'))
23);
24CREATE INDEX symbol_indexes_repo ON symbol_indexes(repo_id, state);
25CREATE UNIQUE INDEX symbol_indexes_current ON symbol_indexes(repo_id)
26 WHERE state IN ('ok', 'partial');
27-- name is what is listed, key the name as written at a use site (they
28-- differ for Go methods: Type.Method and Method). lname and lkey are
29-- their lower-case forms, for case-insensitive prefix ranges.
30CREATE TABLE symbols (
31 id INTEGER PRIMARY KEY,
32 index_id INTEGER NOT NULL REFERENCES symbol_indexes(id) ON DELETE CASCADE,
33 name TEXT NOT NULL,
34 lname TEXT NOT NULL,
35 key TEXT NOT NULL,
36 lkey TEXT NOT NULL,
37 kind TEXT NOT NULL,
38 path TEXT NOT NULL,
39 line INTEGER NOT NULL
40);
41CREATE INDEX symbols_lname ON symbols(index_id, lname);
42CREATE INDEX symbols_lkey ON symbols(index_id, lkey);
43CREATE INDEX symbols_key ON symbols(index_id, key);
44CREATE INDEX symbols_path ON symbols(index_id, path, line);
45-- The last run that could not build an index, kept apart so the current
46-- index stays in place. Cleared by the next index published.
47CREATE TABLE symbol_failures (
48 repo_id INTEGER PRIMARY KEY REFERENCES repos(id) ON DELETE CASCADE,
49 tree TEXT NOT NULL,
50 note TEXT NOT NULL,
51 failed_at TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ','now'))
52);
53-- Repositories waiting for the index worker. seq counts requests, so a
54-- push that lands while a build runs leaves its request in place; force
55-- rebuilds even when the tree is the indexed one. not_before defers a
56-- retry after a failure; attempts counts those retries.
57CREATE TABLE symbol_requests (
58 repo_id INTEGER PRIMARY KEY REFERENCES repos(id) ON DELETE CASCADE,
59 seq INTEGER NOT NULL DEFAULT 1,
60 force INTEGER NOT NULL DEFAULT 0,
61 attempts INTEGER NOT NULL DEFAULT 0,
62 not_before TEXT NOT NULL DEFAULT '',
63 requested_at TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ','now'))
64);