@anchrd/intel-api 0.5.0 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/adapters/db/db.js
CHANGED
|
@@ -151,10 +151,14 @@ export function createKnowledgeRepository(deps) {
|
|
|
151
151
|
try {
|
|
152
152
|
await deps.db.batch([
|
|
153
153
|
deps.db
|
|
154
|
+
// ⚠️ `context_policy` is dead and is written anyway (#76). The column is NOT NULL
|
|
155
|
+
// without a DEFAULT and D1 will not let it be dropped — migration 0009 carries the
|
|
156
|
+
// reason. The fixed value is the price; nothing reads it, and the contract no longer
|
|
157
|
+
// knows the field. When the column goes (anchrd/intel#86), this line goes with it.
|
|
154
158
|
.prepare(`INSERT INTO knowledge_nodes (
|
|
155
|
-
id, parent_id, kind, title, description, owner_id,
|
|
159
|
+
id, parent_id, kind, title, description, context_policy, owner_id,
|
|
156
160
|
current_version_id, created_at, updated_at, archived_at
|
|
157
|
-
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`)
|
|
161
|
+
) VALUES (?, ?, ?, ?, ?, 'relevant', ?, ?, ?, ?, ?)`)
|
|
158
162
|
.bind(node.id, node.parentId, node.kind, node.title, node.description, node.ownerId, node.currentVersionId, node.createdAt, node.updatedAt, node.archivedAt),
|
|
159
163
|
deps.db
|
|
160
164
|
.prepare(`INSERT INTO idempotency_keys (
|
|
@@ -1,51 +1,33 @@
|
|
|
1
|
-
-- #76. `context_policy` leaves the
|
|
2
|
-
-- read to decide anything — and it could not have been: it instructed a retrieval Intel does not
|
|
3
|
-
-- perform. Intel hands out references and the agent fetches what it needs (D24).
|
|
1
|
+
-- #76. `context_policy` leaves the contract, the UI and every MCP answer. The COLUMN stays.
|
|
4
2
|
--
|
|
5
|
-
-- ⚠️ SQLite cannot drop a column
|
|
6
|
-
--
|
|
7
|
-
--
|
|
8
|
-
-- it is load-bearing:
|
|
3
|
+
-- ⚠️ That is not the intent, it is what D1 permits. SQLite cannot drop a column a CHECK names, and
|
|
4
|
+
-- this one names itself. The way around it is a table rebuild, and `knowledge_nodes` carries six
|
|
5
|
+
-- foreign keys, one of them from itself.
|
|
9
6
|
--
|
|
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
|
-
)
|
|
38
|
-
SELECT id, parent_id, kind, title, description, owner_id,
|
|
39
|
-
current_version_id, created_at, updated_at, archived_at
|
|
40
|
-
FROM knowledge_nodes;
|
|
41
|
-
|
|
42
|
-
DROP TABLE knowledge_nodes;
|
|
43
|
-
|
|
44
|
-
ALTER TABLE knowledge_nodes_rebuilt RENAME TO knowledge_nodes;
|
|
45
|
-
|
|
46
|
-
CREATE INDEX knowledge_nodes_parent_idx ON knowledge_nodes(parent_id, archived_at, title);
|
|
47
|
-
CREATE INDEX knowledge_nodes_owner_idx ON knowledge_nodes(owner_id, archived_at);
|
|
48
|
-
|
|
49
|
-
PRAGMA foreign_key_check;
|
|
50
|
-
|
|
51
|
-
PRAGMA foreign_keys = ON;
|
|
7
|
+
-- Three attempts against the real database, three failures, each with its own lesson:
|
|
8
|
+
--
|
|
9
|
+
-- 1. `PRAGMA foreign_keys = OFF` — **ignored** by D1 over its HTTP API. It works locally, because
|
|
10
|
+
-- miniflare honours it, so the integration test was green while production answered
|
|
11
|
+
-- `FOREIGN KEY constraint failed` on the DROP. ⚠️ A green migration test does not prove a D1
|
|
12
|
+
-- migration runs.
|
|
13
|
+
-- 2. `PRAGMA defer_foreign_keys = true` — it works, but the self-reference was written as
|
|
14
|
+
-- `REFERENCES knowledge_nodes(id)` and therefore pointed at the table this same migration was
|
|
15
|
+
-- about to drop. SQLite rewrites a self-reference along with the rename, so the temporary name
|
|
16
|
+
-- belongs there.
|
|
17
|
+
-- 3. Self-reference fixed → green through `wrangler d1 migrations apply --local`, still red
|
|
18
|
+
-- against `--remote`. The reason is the execution model: D1 commits the statements of a
|
|
19
|
+
-- migration file one at a time, and the deferral only lasts until the next COMMIT. After the
|
|
20
|
+
-- first statement the reprieve is gone and `DROP TABLE` runs unprotected.
|
|
21
|
+
--
|
|
22
|
+
-- A table rebuild with foreign keys is therefore not possible inside a migration file. It needs a
|
|
23
|
+
-- session that drives the transaction itself.
|
|
24
|
+
--
|
|
25
|
+
-- What holds instead: the column sits in D1, nothing reads it, and `db.ts` writes a fixed value on
|
|
26
|
+
-- insert because it is NOT NULL without a DEFAULT. The contract does not know it — for every
|
|
27
|
+
-- consumer it is gone. What remains is one dead column, and that is the price of Intel running.
|
|
28
|
+
--
|
|
29
|
+
-- How it disappears after all is anchrd/intel#86.
|
|
30
|
+
--
|
|
31
|
+
-- This file deliberately does nothing. It is where the above is written down; deleted, it would be
|
|
32
|
+
-- a gap in the numbering that nobody explains.
|
|
33
|
+
SELECT 1;
|