botnote 0.2.16 → 0.2.18
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/README.md +24 -504
- package/dist/bin.js +16 -9
- package/dist/bin.js.map +1 -1
- package/dist/config.d.ts +0 -4
- package/dist/config.js +0 -31
- package/dist/config.js.map +1 -1
- package/dist/mcp/server.js +1 -1
- package/dist/mcp/server.js.map +1 -1
- package/dist/mcp/stdio.d.ts +8 -0
- package/dist/mcp/stdio.js +46 -0
- package/dist/mcp/stdio.js.map +1 -0
- package/package.json +8 -40
- package/dist/cli.d.ts +0 -1
- package/dist/cli.js +0 -186
- package/dist/cli.js.map +0 -1
- package/dist/db/client.d.ts +0 -14
- package/dist/db/client.js +0 -16
- package/dist/db/client.js.map +0 -1
- package/dist/db/migrate.d.ts +0 -1
- package/dist/db/migrate.js +0 -57
- package/dist/db/migrate.js.map +0 -1
- package/dist/db/migrations/0001_init.sql +0 -89
- package/dist/db/migrations/0002_tasks_due_at.sql +0 -16
- package/dist/db/migrations/0003_task_priority_and_sequence.sql +0 -45
- package/dist/db/migrations/0004_pinned.sql +0 -8
- package/dist/db/migrations/0005_nullable_title_and_parent.sql +0 -5
- package/dist/db/migrations/0006_project_color_icon.sql +0 -3
- package/dist/db/migrations/0007_tokens.sql +0 -14
- package/dist/db/migrations/0008_simplify_kinds_drop_actors.sql +0 -21
- package/dist/db/migrations/0009_sessions.sql +0 -14
- package/dist/db/migrations/0010_completed_at.sql +0 -17
- package/dist/db/migrations/0011_completed_at_backfill_fix.sql +0 -14
- package/dist/db/migrations/0012_completed_at_backfill_due.sql +0 -16
- package/dist/db/migrations/0013_due_at_noon_utc.sql +0 -13
- package/dist/db/migrations/0014_recoverable_api_tokens.sql +0 -3
- package/dist/db/migrations/0015_collapse_delayed_archived_statuses.sql +0 -18
- package/dist/db/migrations/0016_embedding_settings.sql +0 -23
- package/dist/db/migrations/0017_recurrence_rules.sql +0 -55
- package/dist/db/migrations/0018_project_archived_at.sql +0 -8
- package/dist/db/migrations/0019_project_status.sql +0 -20
- package/dist/db/migrations/0020_project_archived_status.sql +0 -20
- package/dist/db/migrations/0021_workspace_settings.sql +0 -18
- package/dist/db/migrations/0022_recurrence_split.sql +0 -13
- package/dist/db/migrations/0023_comment_kind.sql +0 -24
- package/dist/db/migrations/0024_memory_access.sql +0 -12
- package/dist/db/migrations/0025_soft_delete.sql +0 -12
- package/dist/db/migrations/0026_sequence_counter.sql +0 -61
- package/dist/db/migrations/0027_self_parent_repair.sql +0 -10
- package/dist/db/migrations/0028_workspaces.sql +0 -65
- package/dist/db/migrations/0029_drop_global_uniques.sql +0 -38
- package/dist/db/migrations/0030_entity_actor_token.sql +0 -12
- package/dist/db/migrations/0031_entity_revisions.sql +0 -19
- package/dist/db/migrations/0032_touch_respects_explicit_updated_at.sql +0 -18
- package/dist/db/migrations/0033_worklog_kind.sql +0 -42
- package/dist/db/schema.d.ts +0 -2023
- package/dist/db/schema.js +0 -245
- package/dist/db/schema.js.map +0 -1
- package/dist/rest/attribution.d.ts +0 -22
- package/dist/rest/attribution.js +0 -62
- package/dist/rest/attribution.js.map +0 -1
- package/dist/rest/auth.d.ts +0 -47
- package/dist/rest/auth.js +0 -116
- package/dist/rest/auth.js.map +0 -1
- package/dist/rest/routes.d.ts +0 -3
- package/dist/rest/routes.js +0 -844
- package/dist/rest/routes.js.map +0 -1
- package/dist/rest/server.d.ts +0 -28
- package/dist/rest/server.js +0 -276
- package/dist/rest/server.js.map +0 -1
- package/dist/service/blockers.d.ts +0 -37
- package/dist/service/blockers.js +0 -46
- package/dist/service/blockers.js.map +0 -1
- package/dist/service/dates.d.ts +0 -19
- package/dist/service/dates.js +0 -52
- package/dist/service/dates.js.map +0 -1
- package/dist/service/embedding.d.ts +0 -75
- package/dist/service/embedding.js +0 -318
- package/dist/service/embedding.js.map +0 -1
- package/dist/service/embedding_settings.d.ts +0 -16
- package/dist/service/embedding_settings.js +0 -82
- package/dist/service/embedding_settings.js.map +0 -1
- package/dist/service/entities.d.ts +0 -96
- package/dist/service/entities.js +0 -628
- package/dist/service/entities.js.map +0 -1
- package/dist/service/feedback.d.ts +0 -13
- package/dist/service/feedback.js +0 -50
- package/dist/service/feedback.js.map +0 -1
- package/dist/service/hierarchy.d.ts +0 -31
- package/dist/service/hierarchy.js +0 -76
- package/dist/service/hierarchy.js.map +0 -1
- package/dist/service/index.d.ts +0 -10
- package/dist/service/index.js +0 -10
- package/dist/service/index.js.map +0 -1
- package/dist/service/locks.d.ts +0 -25
- package/dist/service/locks.js +0 -34
- package/dist/service/locks.js.map +0 -1
- package/dist/service/opening_brief.d.ts +0 -24
- package/dist/service/opening_brief.js +0 -210
- package/dist/service/opening_brief.js.map +0 -1
- package/dist/service/projects.d.ts +0 -9
- package/dist/service/projects.js +0 -59
- package/dist/service/projects.js.map +0 -1
- package/dist/service/recurrence.d.ts +0 -93
- package/dist/service/recurrence.js +0 -799
- package/dist/service/recurrence.js.map +0 -1
- package/dist/service/revisions.d.ts +0 -31
- package/dist/service/revisions.js +0 -53
- package/dist/service/revisions.js.map +0 -1
- package/dist/service/scope.d.ts +0 -14
- package/dist/service/scope.js +0 -19
- package/dist/service/scope.js.map +0 -1
- package/dist/service/search.d.ts +0 -34
- package/dist/service/search.js +0 -198
- package/dist/service/search.js.map +0 -1
- package/dist/service/sessions.d.ts +0 -24
- package/dist/service/sessions.js +0 -89
- package/dist/service/sessions.js.map +0 -1
- package/dist/service/tasks.d.ts +0 -48
- package/dist/service/tasks.js +0 -354
- package/dist/service/tasks.js.map +0 -1
- package/dist/service/tokens.d.ts +0 -21
- package/dist/service/tokens.js +0 -71
- package/dist/service/tokens.js.map +0 -1
- package/dist/service/transfer.d.ts +0 -64
- package/dist/service/transfer.js +0 -629
- package/dist/service/transfer.js.map +0 -1
- package/dist/service/types.d.ts +0 -772
- package/dist/service/types.js +0 -274
- package/dist/service/types.js.map +0 -1
- package/dist/service/workspace_settings.d.ts +0 -9
- package/dist/service/workspace_settings.js +0 -49
- package/dist/service/workspace_settings.js.map +0 -1
- package/web/dist/assets/index-C0u0ZrR4.css +0 -1
- package/web/dist/assets/index-sCiJNYQ3.js +0 -235
- package/web/dist/favicon.svg +0 -13
- package/web/dist/index.html +0 -22
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
-- botnote 0017 — recurring task rules.
|
|
2
|
-
-- Idempotent: safe to re-run.
|
|
3
|
-
|
|
4
|
-
CREATE TABLE IF NOT EXISTS recurrence_rules (
|
|
5
|
-
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
6
|
-
series_id uuid NOT NULL REFERENCES entities(id) ON DELETE CASCADE,
|
|
7
|
-
current_occurrence_id uuid REFERENCES entities(id) ON DELETE SET NULL,
|
|
8
|
-
enabled boolean NOT NULL DEFAULT true,
|
|
9
|
-
rrule text NOT NULL,
|
|
10
|
-
dtstart timestamptz NOT NULL,
|
|
11
|
-
timezone text NOT NULL DEFAULT 'UTC',
|
|
12
|
-
all_day boolean NOT NULL DEFAULT true,
|
|
13
|
-
anchor text NOT NULL DEFAULT 'scheduled',
|
|
14
|
-
max_instances_ahead integer NOT NULL DEFAULT 1,
|
|
15
|
-
generated_count integer NOT NULL DEFAULT 1,
|
|
16
|
-
last_occurrence_at timestamptz,
|
|
17
|
-
next_occurrence_at timestamptz,
|
|
18
|
-
ended_at timestamptz,
|
|
19
|
-
created_at timestamptz NOT NULL DEFAULT now(),
|
|
20
|
-
updated_at timestamptz NOT NULL DEFAULT now()
|
|
21
|
-
);
|
|
22
|
-
|
|
23
|
-
CREATE UNIQUE INDEX IF NOT EXISTS recurrence_rules_series_idx
|
|
24
|
-
ON recurrence_rules(series_id);
|
|
25
|
-
|
|
26
|
-
CREATE INDEX IF NOT EXISTS recurrence_rules_current_occurrence_idx
|
|
27
|
-
ON recurrence_rules(current_occurrence_id);
|
|
28
|
-
|
|
29
|
-
CREATE INDEX IF NOT EXISTS recurrence_rules_next_occurrence_idx
|
|
30
|
-
ON recurrence_rules(next_occurrence_at)
|
|
31
|
-
WHERE enabled = true;
|
|
32
|
-
|
|
33
|
-
CREATE INDEX IF NOT EXISTS recurrence_rules_enabled_idx
|
|
34
|
-
ON recurrence_rules(enabled, next_occurrence_at);
|
|
35
|
-
|
|
36
|
-
DROP TRIGGER IF EXISTS recurrence_rules_touch_updated_at ON recurrence_rules;
|
|
37
|
-
CREATE TRIGGER recurrence_rules_touch_updated_at
|
|
38
|
-
BEFORE UPDATE ON recurrence_rules
|
|
39
|
-
FOR EACH ROW EXECUTE FUNCTION botnote_touch_updated_at();
|
|
40
|
-
|
|
41
|
-
CREATE TABLE IF NOT EXISTS recurrence_exceptions (
|
|
42
|
-
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
43
|
-
rule_id uuid NOT NULL REFERENCES recurrence_rules(id) ON DELETE CASCADE,
|
|
44
|
-
occurrence_at timestamptz NOT NULL,
|
|
45
|
-
action text NOT NULL,
|
|
46
|
-
entity_id uuid REFERENCES entities(id) ON DELETE SET NULL,
|
|
47
|
-
metadata jsonb NOT NULL DEFAULT '{}'::jsonb,
|
|
48
|
-
created_at timestamptz NOT NULL DEFAULT now()
|
|
49
|
-
);
|
|
50
|
-
|
|
51
|
-
CREATE INDEX IF NOT EXISTS recurrence_exceptions_rule_occurrence_idx
|
|
52
|
-
ON recurrence_exceptions(rule_id, occurrence_at);
|
|
53
|
-
|
|
54
|
-
CREATE INDEX IF NOT EXISTS recurrence_exceptions_entity_idx
|
|
55
|
-
ON recurrence_exceptions(entity_id);
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
-- botnote 0019 — project lifecycle status.
|
|
2
|
-
-- Idempotent: safe to re-run.
|
|
3
|
-
|
|
4
|
-
ALTER TABLE projects ADD COLUMN IF NOT EXISTS status text NOT NULL DEFAULT 'active';
|
|
5
|
-
|
|
6
|
-
UPDATE projects
|
|
7
|
-
SET status = 'active'
|
|
8
|
-
WHERE status IS NULL;
|
|
9
|
-
|
|
10
|
-
DO $$
|
|
11
|
-
BEGIN
|
|
12
|
-
ALTER TABLE projects ADD CONSTRAINT projects_status_check
|
|
13
|
-
CHECK (status IN ('planned', 'active', 'watching', 'paused', 'archived'));
|
|
14
|
-
EXCEPTION
|
|
15
|
-
WHEN duplicate_object THEN NULL;
|
|
16
|
-
END $$;
|
|
17
|
-
|
|
18
|
-
CREATE INDEX IF NOT EXISTS projects_active_status_idx
|
|
19
|
-
ON projects(status, key)
|
|
20
|
-
WHERE status <> 'archived';
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
-- botnote 0020 — make archive a project status.
|
|
2
|
-
-- Idempotent: safe to re-run.
|
|
3
|
-
|
|
4
|
-
ALTER TABLE projects DROP CONSTRAINT IF EXISTS projects_status_check;
|
|
5
|
-
|
|
6
|
-
ALTER TABLE projects ADD CONSTRAINT projects_status_check
|
|
7
|
-
CHECK (status IN ('planned', 'active', 'watching', 'paused', 'archived'));
|
|
8
|
-
|
|
9
|
-
UPDATE projects
|
|
10
|
-
SET status = 'archived'
|
|
11
|
-
WHERE archived_at IS NOT NULL
|
|
12
|
-
AND status <> 'archived';
|
|
13
|
-
|
|
14
|
-
UPDATE projects
|
|
15
|
-
SET archived_at = now()
|
|
16
|
-
WHERE status = 'archived'
|
|
17
|
-
AND archived_at IS NULL;
|
|
18
|
-
|
|
19
|
-
CREATE INDEX IF NOT EXISTS projects_status_key_idx
|
|
20
|
-
ON projects(status, key);
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
-- botnote 0021 workspace settings
|
|
2
|
-
-- Idempotent: safe to re-run.
|
|
3
|
-
|
|
4
|
-
CREATE TABLE IF NOT EXISTS workspace_settings (
|
|
5
|
-
id text PRIMARY KEY DEFAULT 'default' CHECK (id = 'default'),
|
|
6
|
-
timezone text NOT NULL DEFAULT 'UTC',
|
|
7
|
-
created_at timestamptz NOT NULL DEFAULT now(),
|
|
8
|
-
updated_at timestamptz NOT NULL DEFAULT now()
|
|
9
|
-
);
|
|
10
|
-
|
|
11
|
-
INSERT INTO workspace_settings (id)
|
|
12
|
-
VALUES ('default')
|
|
13
|
-
ON CONFLICT (id) DO NOTHING;
|
|
14
|
-
|
|
15
|
-
DROP TRIGGER IF EXISTS workspace_settings_touch_updated_at ON workspace_settings;
|
|
16
|
-
CREATE TRIGGER workspace_settings_touch_updated_at
|
|
17
|
-
BEFORE UPDATE ON workspace_settings
|
|
18
|
-
FOR EACH ROW EXECUTE FUNCTION botnote_touch_updated_at();
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
-- botnote 0022 — allow splitting a recurrence series.
|
|
2
|
-
-- A split keeps the old rule as frozen history (enabled = false, bounded by
|
|
3
|
-
-- UNTIL) and creates a new enabled rule that shares the SAME series_id so the
|
|
4
|
-
-- UI still groups history + future as one continuous series. That requires more
|
|
5
|
-
-- than one rule per series, so the unique constraint is relaxed to a PARTIAL
|
|
6
|
-
-- unique index: at most one ENABLED rule per series, unlimited disabled history.
|
|
7
|
-
-- Idempotent: safe to re-run.
|
|
8
|
-
|
|
9
|
-
DROP INDEX IF EXISTS recurrence_rules_series_idx;
|
|
10
|
-
|
|
11
|
-
CREATE UNIQUE INDEX IF NOT EXISTS recurrence_rules_series_idx
|
|
12
|
-
ON recurrence_rules(series_id)
|
|
13
|
-
WHERE enabled = true;
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
-- botnote 0023 — reintroduce the 'comment' entity kind as an append-only
|
|
2
|
-
-- worklog attached to a task (parent_id). Unlike the pre-0008 comment kind,
|
|
3
|
-
-- these have a concrete product role: agent/human progress notes that the
|
|
4
|
-
-- opening brief surfaces for in_progress tasks.
|
|
5
|
-
-- Idempotent.
|
|
6
|
-
|
|
7
|
-
-- Comments carry project_id (so project-scoped search/recent include them)
|
|
8
|
-
-- but must NOT consume a per-project sequence number — KEY-SEQ identifiers
|
|
9
|
-
-- are for addressable work items (tasks/notes), not log lines.
|
|
10
|
-
CREATE OR REPLACE FUNCTION botnote_set_sequence_id() RETURNS trigger AS $$
|
|
11
|
-
BEGIN
|
|
12
|
-
IF NEW.sequence_id IS NULL AND NEW.project_id IS NOT NULL AND NEW.kind <> 'comment' THEN
|
|
13
|
-
SELECT COALESCE(MAX(sequence_id), 0) + 1
|
|
14
|
-
INTO NEW.sequence_id
|
|
15
|
-
FROM entities
|
|
16
|
-
WHERE project_id = NEW.project_id;
|
|
17
|
-
END IF;
|
|
18
|
-
RETURN NEW;
|
|
19
|
-
END;
|
|
20
|
-
$$ LANGUAGE plpgsql;
|
|
21
|
-
|
|
22
|
-
-- Fast "latest comment per task" lookups for the opening brief.
|
|
23
|
-
CREATE INDEX IF NOT EXISTS entities_comment_parent_created_idx
|
|
24
|
-
ON entities(parent_id, created_at DESC) WHERE kind = 'comment';
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
-- Memory upgrade: access tracking + supersedes edges.
|
|
2
|
-
--
|
|
3
|
-
-- last_accessed_at / access_count are bumped on explicit entity reads
|
|
4
|
-
-- (GET /v1/entities/:id and by-key lookups) and feed a light boost into
|
|
5
|
-
-- hybrid search so frequently-recalled memories rank slightly higher.
|
|
6
|
-
--
|
|
7
|
-
-- The 'supersedes' edge kind (new note -> outdated note) needs no schema
|
|
8
|
-
-- change (edges.kind is text); search downweights entities that are the
|
|
9
|
-
-- target of a supersedes edge.
|
|
10
|
-
|
|
11
|
-
ALTER TABLE entities ADD COLUMN IF NOT EXISTS last_accessed_at timestamptz;
|
|
12
|
-
ALTER TABLE entities ADD COLUMN IF NOT EXISTS access_count integer NOT NULL DEFAULT 0;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
-- Soft delete / trash bin. deleted_at marks an entity as trashed: hidden from
|
|
2
|
-
-- every read path (search, recent, tasks-range, briefs, comments, feedback)
|
|
3
|
-
-- but restorable until the retention purge hard-deletes it. Projects are not
|
|
4
|
-
-- part of the trash — they keep their own archive lifecycle.
|
|
5
|
-
|
|
6
|
-
ALTER TABLE entities ADD COLUMN IF NOT EXISTS deleted_at timestamptz;
|
|
7
|
-
|
|
8
|
-
-- Partial index: the trash view and the retention purge only ever scan
|
|
9
|
-
-- trashed rows, which stay a tiny fraction of the table.
|
|
10
|
-
CREATE INDEX IF NOT EXISTS entities_deleted_at_idx
|
|
11
|
-
ON entities (deleted_at)
|
|
12
|
-
WHERE deleted_at IS NOT NULL;
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
-- Replace the MAX(sequence_id)+1 trigger with a per-project counter.
|
|
2
|
-
--
|
|
3
|
-
-- The old trigger read MAX(sequence_id) outside any lock, so two concurrent
|
|
4
|
-
-- inserts into one project could both become KEY-55. The counter lives on
|
|
5
|
-
-- projects.next_seq; the trigger's UPDATE takes the project's row lock, which
|
|
6
|
-
-- serializes writers. A partial unique index makes a duplicate impossible
|
|
7
|
-
-- rather than merely unlikely.
|
|
8
|
-
--
|
|
9
|
-
-- Expand-only: the previous release never reads next_seq, and the replaced
|
|
10
|
-
-- trigger keeps the same signature and guards.
|
|
11
|
-
|
|
12
|
-
DO $$
|
|
13
|
-
DECLARE
|
|
14
|
-
dup_count integer;
|
|
15
|
-
BEGIN
|
|
16
|
-
SELECT count(*) INTO dup_count FROM (
|
|
17
|
-
SELECT project_id, sequence_id FROM entities
|
|
18
|
-
WHERE sequence_id IS NOT NULL
|
|
19
|
-
GROUP BY project_id, sequence_id HAVING count(*) > 1
|
|
20
|
-
) d;
|
|
21
|
-
IF dup_count > 0 THEN
|
|
22
|
-
RAISE EXCEPTION
|
|
23
|
-
'migration 0026 aborted: % duplicate (project_id, sequence_id) pair(s) exist; resolve them before adding the unique index',
|
|
24
|
-
dup_count;
|
|
25
|
-
END IF;
|
|
26
|
-
END $$;
|
|
27
|
-
|
|
28
|
-
ALTER TABLE projects ADD COLUMN IF NOT EXISTS next_seq integer NOT NULL DEFAULT 1;
|
|
29
|
-
|
|
30
|
-
UPDATE projects p
|
|
31
|
-
SET next_seq = COALESCE(
|
|
32
|
-
(SELECT MAX(e.sequence_id) FROM entities e WHERE e.project_id = p.id), 0
|
|
33
|
-
) + 1;
|
|
34
|
-
|
|
35
|
-
CREATE OR REPLACE FUNCTION botnote_set_sequence_id()
|
|
36
|
-
RETURNS TRIGGER AS $$
|
|
37
|
-
BEGIN
|
|
38
|
-
IF NEW.project_id IS NULL OR NEW.kind = 'comment' THEN
|
|
39
|
-
RETURN NEW;
|
|
40
|
-
END IF;
|
|
41
|
-
|
|
42
|
-
IF NEW.sequence_id IS NULL THEN
|
|
43
|
-
UPDATE projects
|
|
44
|
-
SET next_seq = next_seq + 1
|
|
45
|
-
WHERE id = NEW.project_id
|
|
46
|
-
RETURNING next_seq - 1 INTO NEW.sequence_id;
|
|
47
|
-
ELSE
|
|
48
|
-
-- An explicit sequence id (imports, repairs) must never leave the
|
|
49
|
-
-- counter behind it, or the next auto-assigned id would collide.
|
|
50
|
-
UPDATE projects
|
|
51
|
-
SET next_seq = GREATEST(next_seq, NEW.sequence_id + 1)
|
|
52
|
-
WHERE id = NEW.project_id;
|
|
53
|
-
END IF;
|
|
54
|
-
|
|
55
|
-
RETURN NEW;
|
|
56
|
-
END;
|
|
57
|
-
$$ LANGUAGE plpgsql;
|
|
58
|
-
|
|
59
|
-
CREATE UNIQUE INDEX IF NOT EXISTS entities_project_seq_unique
|
|
60
|
-
ON entities (project_id, sequence_id)
|
|
61
|
-
WHERE sequence_id IS NOT NULL;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
-- Repair entities that point at themselves as their own parent.
|
|
2
|
-
--
|
|
3
|
-
-- The Letheia import wrote parent_id = id (and a matching parent_of self
|
|
4
|
-
-- edge) for 1034 notes, so listChildren and get_entity_by_key listed each
|
|
5
|
-
-- note as its own child. Data fix only, no schema change; both statements
|
|
6
|
-
-- are no-ops once applied, and the service now rejects self-parenting.
|
|
7
|
-
|
|
8
|
-
UPDATE entities SET parent_id = NULL WHERE parent_id = id;
|
|
9
|
-
|
|
10
|
-
DELETE FROM edges WHERE from_id = to_id;
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
-- Workspaces: the tenant boundary shared by the single-user OSS build and the
|
|
2
|
-
-- hosted multi-user build (BOT-113, subtask 1 of BOT-101).
|
|
3
|
-
--
|
|
4
|
-
-- Schema only. Every tenant table gains workspace_id with a DEFAULT pointing
|
|
5
|
-
-- at the fixed default workspace, which backfills existing rows in the same
|
|
6
|
-
-- statement and keeps inserts from the previous release working. Service code
|
|
7
|
-
-- starts filtering by it in the next release (BOT-114); the old global unique
|
|
8
|
-
-- indexes stay until that release has shipped.
|
|
9
|
-
|
|
10
|
-
CREATE TABLE IF NOT EXISTS workspaces (
|
|
11
|
-
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
12
|
-
slug text NOT NULL,
|
|
13
|
-
name text NOT NULL,
|
|
14
|
-
created_at timestamptz NOT NULL DEFAULT now(),
|
|
15
|
-
updated_at timestamptz NOT NULL DEFAULT now()
|
|
16
|
-
);
|
|
17
|
-
|
|
18
|
-
CREATE UNIQUE INDEX IF NOT EXISTS workspaces_slug_idx ON workspaces (slug);
|
|
19
|
-
|
|
20
|
-
DROP TRIGGER IF EXISTS workspaces_touch_updated_at ON workspaces;
|
|
21
|
-
CREATE TRIGGER workspaces_touch_updated_at
|
|
22
|
-
BEFORE UPDATE ON workspaces
|
|
23
|
-
FOR EACH ROW EXECUTE FUNCTION botnote_touch_updated_at();
|
|
24
|
-
|
|
25
|
-
INSERT INTO workspaces (id, slug, name)
|
|
26
|
-
VALUES ('00000000-0000-4000-8000-000000000001', 'default', 'Default workspace')
|
|
27
|
-
ON CONFLICT (id) DO NOTHING;
|
|
28
|
-
|
|
29
|
-
ALTER TABLE projects
|
|
30
|
-
ADD COLUMN IF NOT EXISTS workspace_id uuid NOT NULL
|
|
31
|
-
DEFAULT '00000000-0000-4000-8000-000000000001' REFERENCES workspaces(id);
|
|
32
|
-
ALTER TABLE entities
|
|
33
|
-
ADD COLUMN IF NOT EXISTS workspace_id uuid NOT NULL
|
|
34
|
-
DEFAULT '00000000-0000-4000-8000-000000000001' REFERENCES workspaces(id);
|
|
35
|
-
ALTER TABLE recurrence_rules
|
|
36
|
-
ADD COLUMN IF NOT EXISTS workspace_id uuid NOT NULL
|
|
37
|
-
DEFAULT '00000000-0000-4000-8000-000000000001' REFERENCES workspaces(id);
|
|
38
|
-
ALTER TABLE tokens
|
|
39
|
-
ADD COLUMN IF NOT EXISTS workspace_id uuid NOT NULL
|
|
40
|
-
DEFAULT '00000000-0000-4000-8000-000000000001' REFERENCES workspaces(id);
|
|
41
|
-
ALTER TABLE sessions
|
|
42
|
-
ADD COLUMN IF NOT EXISTS workspace_id uuid NOT NULL
|
|
43
|
-
DEFAULT '00000000-0000-4000-8000-000000000001' REFERENCES workspaces(id);
|
|
44
|
-
ALTER TABLE embedding_settings
|
|
45
|
-
ADD COLUMN IF NOT EXISTS workspace_id uuid NOT NULL
|
|
46
|
-
DEFAULT '00000000-0000-4000-8000-000000000001' REFERENCES workspaces(id);
|
|
47
|
-
ALTER TABLE workspace_settings
|
|
48
|
-
ADD COLUMN IF NOT EXISTS workspace_id uuid NOT NULL
|
|
49
|
-
DEFAULT '00000000-0000-4000-8000-000000000001' REFERENCES workspaces(id);
|
|
50
|
-
|
|
51
|
-
-- Tenant-scoped uniqueness. The global projects_key_idx and
|
|
52
|
-
-- entities_idempotency_idx remain for one release so the current code keeps
|
|
53
|
-
-- its guarantees; BOT-114 drops them once every query is scoped.
|
|
54
|
-
CREATE UNIQUE INDEX IF NOT EXISTS projects_ws_key_unique
|
|
55
|
-
ON projects (workspace_id, key);
|
|
56
|
-
CREATE UNIQUE INDEX IF NOT EXISTS entities_ws_idem_unique
|
|
57
|
-
ON entities (workspace_id, idempotency_key)
|
|
58
|
-
WHERE idempotency_key IS NOT NULL;
|
|
59
|
-
|
|
60
|
-
CREATE INDEX IF NOT EXISTS entities_ws_kind_created_idx
|
|
61
|
-
ON entities (workspace_id, kind, created_at DESC);
|
|
62
|
-
CREATE INDEX IF NOT EXISTS recurrence_rules_ws_idx
|
|
63
|
-
ON recurrence_rules (workspace_id, enabled, next_occurrence_at);
|
|
64
|
-
CREATE INDEX IF NOT EXISTS tokens_ws_idx ON tokens (workspace_id);
|
|
65
|
-
CREATE INDEX IF NOT EXISTS sessions_ws_idx ON sessions (workspace_id);
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
-- Workspace scoping is live in service code as of this release (BOT-114,
|
|
2
|
-
-- subtask 2 of BOT-101): every tenant-facing query filters by workspace_id and
|
|
3
|
-
-- every insert stamps it.
|
|
4
|
-
--
|
|
5
|
-
-- 1. The per-workspace unique indexes from 0028 (projects_ws_key_unique,
|
|
6
|
-
-- entities_ws_idem_unique) now carry the invariant, so the pre-workspace
|
|
7
|
-
-- global uniques are redundant and would wrongly reject the same project
|
|
8
|
-
-- key or idempotency key reused in a second workspace.
|
|
9
|
-
--
|
|
10
|
-
-- 2. workspace_settings and embedding_settings were singletons keyed by
|
|
11
|
-
-- id = 'default'. They become one row per workspace: the primary key moves
|
|
12
|
-
-- to workspace_id and `id` stays as a constant discriminator column. The
|
|
13
|
-
-- CHECK (id = 'default') is kept on purpose — it no longer limits the row
|
|
14
|
-
-- count once id is not unique, and keeping it means the N-1 code path
|
|
15
|
-
-- (INSERT id='default' ... ON CONFLICT DO NOTHING; SELECT WHERE id='default')
|
|
16
|
-
-- still runs unchanged against this schema.
|
|
17
|
-
|
|
18
|
-
DROP INDEX IF EXISTS projects_key_idx;
|
|
19
|
-
DROP INDEX IF EXISTS entities_idempotency_idx;
|
|
20
|
-
|
|
21
|
-
DO $$
|
|
22
|
-
BEGIN
|
|
23
|
-
IF EXISTS (SELECT 1 FROM pg_constraint
|
|
24
|
-
WHERE conname = 'workspace_settings_pkey'
|
|
25
|
-
AND conrelid = 'workspace_settings'::regclass
|
|
26
|
-
AND pg_get_constraintdef(oid) = 'PRIMARY KEY (id)') THEN
|
|
27
|
-
ALTER TABLE workspace_settings DROP CONSTRAINT workspace_settings_pkey;
|
|
28
|
-
ALTER TABLE workspace_settings ADD CONSTRAINT workspace_settings_pkey PRIMARY KEY (workspace_id);
|
|
29
|
-
END IF;
|
|
30
|
-
|
|
31
|
-
IF EXISTS (SELECT 1 FROM pg_constraint
|
|
32
|
-
WHERE conname = 'embedding_settings_pkey'
|
|
33
|
-
AND conrelid = 'embedding_settings'::regclass
|
|
34
|
-
AND pg_get_constraintdef(oid) = 'PRIMARY KEY (id)') THEN
|
|
35
|
-
ALTER TABLE embedding_settings DROP CONSTRAINT embedding_settings_pkey;
|
|
36
|
-
ALTER TABLE embedding_settings ADD CONSTRAINT embedding_settings_pkey PRIMARY KEY (workspace_id);
|
|
37
|
-
END IF;
|
|
38
|
-
END $$;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
-- Write attribution (BOT-108): remember which API token wrote an entity so
|
|
2
|
-
-- the brief and the UI can say "written by <token name>" instead of the bare
|
|
3
|
-
-- actor_kind. Nullable and expand-only: rows written through a session
|
|
4
|
-
-- cookie, the trusted loopback path, or by N-1 code simply carry NULL.
|
|
5
|
-
-- Revoking a token keeps the rows and clears the reference.
|
|
6
|
-
|
|
7
|
-
ALTER TABLE entities
|
|
8
|
-
ADD COLUMN IF NOT EXISTS actor_token_id uuid REFERENCES tokens(id) ON DELETE SET NULL;
|
|
9
|
-
|
|
10
|
-
CREATE INDEX IF NOT EXISTS entities_actor_token_idx
|
|
11
|
-
ON entities (actor_token_id)
|
|
12
|
-
WHERE actor_token_id IS NOT NULL;
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
-- Content history: one row per content-changing update, holding the values
|
|
2
|
-
-- as they were BEFORE that update. actor_* name who made the change that
|
|
3
|
-
-- replaced this snapshot. Expand-only; 0.2.x code ignores the table.
|
|
4
|
-
CREATE TABLE IF NOT EXISTS entity_revisions (
|
|
5
|
-
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
6
|
-
entity_id uuid NOT NULL REFERENCES entities(id) ON DELETE CASCADE,
|
|
7
|
-
revision integer NOT NULL,
|
|
8
|
-
title text,
|
|
9
|
-
body text NOT NULL DEFAULT '',
|
|
10
|
-
tags text[] NOT NULL DEFAULT '{}'::text[],
|
|
11
|
-
priority text NOT NULL DEFAULT 'none',
|
|
12
|
-
status text NOT NULL DEFAULT 'open',
|
|
13
|
-
actor_kind text NOT NULL DEFAULT 'human',
|
|
14
|
-
actor_token_id uuid REFERENCES tokens(id) ON DELETE SET NULL,
|
|
15
|
-
created_at timestamptz NOT NULL DEFAULT now()
|
|
16
|
-
);
|
|
17
|
-
|
|
18
|
-
CREATE UNIQUE INDEX IF NOT EXISTS entity_revisions_entity_revision_idx
|
|
19
|
-
ON entity_revisions (entity_id, revision DESC);
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
-- botnote_touch_updated_at used to overwrite updated_at on every UPDATE, so
|
|
2
|
-
-- nothing could ever restore a historical timestamp: the sequence trigger's
|
|
3
|
-
-- counter bump on projects (0026) stamped "now" on every project that
|
|
4
|
-
-- received an imported entity, and a workspace import could not round-trip
|
|
5
|
-
-- projects.updated_at. The function now leaves updated_at alone when the
|
|
6
|
-
-- statement itself changed it, and keeps stamping now() otherwise.
|
|
7
|
-
--
|
|
8
|
-
-- Expand-only: 0.2.x code only ever writes updated_at = now(), which this
|
|
9
|
-
-- version treats exactly as before. Same signature, same triggers.
|
|
10
|
-
CREATE OR REPLACE FUNCTION botnote_touch_updated_at() RETURNS trigger AS $$
|
|
11
|
-
BEGIN
|
|
12
|
-
IF NEW.updated_at IS DISTINCT FROM OLD.updated_at THEN
|
|
13
|
-
RETURN NEW;
|
|
14
|
-
END IF;
|
|
15
|
-
NEW.updated_at = now();
|
|
16
|
-
RETURN NEW;
|
|
17
|
-
END;
|
|
18
|
-
$$ LANGUAGE plpgsql;
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
-- Rename the 'comment' entity kind to 'worklog', matching what the UI, MCP
|
|
2
|
-
-- tools and CLI call these append-only progress entries.
|
|
3
|
-
--
|
|
4
|
-
-- The touch trigger is paused for the rename so entries keep their original
|
|
5
|
-
-- updated_at instead of all jumping to the top of "recent". The sequence
|
|
6
|
-
-- trigger skips both names so a rolled-back daemon that still writes
|
|
7
|
-
-- kind='comment' never hands its log lines a KEY-SEQ number.
|
|
8
|
-
-- Idempotent; runs inside the migration transaction.
|
|
9
|
-
|
|
10
|
-
ALTER TABLE entities DISABLE TRIGGER entities_touch_updated_at;
|
|
11
|
-
UPDATE entities SET kind = 'worklog' WHERE kind = 'comment';
|
|
12
|
-
ALTER TABLE entities ENABLE TRIGGER entities_touch_updated_at;
|
|
13
|
-
|
|
14
|
-
CREATE OR REPLACE FUNCTION botnote_set_sequence_id()
|
|
15
|
-
RETURNS TRIGGER AS $$
|
|
16
|
-
BEGIN
|
|
17
|
-
IF NEW.project_id IS NULL OR NEW.kind IN ('worklog', 'comment') THEN
|
|
18
|
-
RETURN NEW;
|
|
19
|
-
END IF;
|
|
20
|
-
|
|
21
|
-
IF NEW.sequence_id IS NULL THEN
|
|
22
|
-
UPDATE projects
|
|
23
|
-
SET next_seq = next_seq + 1
|
|
24
|
-
WHERE id = NEW.project_id
|
|
25
|
-
RETURNING next_seq - 1 INTO NEW.sequence_id;
|
|
26
|
-
ELSE
|
|
27
|
-
-- An explicit sequence id (imports, repairs) must never leave the
|
|
28
|
-
-- counter behind it, or the next auto-assigned id would collide.
|
|
29
|
-
UPDATE projects
|
|
30
|
-
SET next_seq = GREATEST(next_seq, NEW.sequence_id + 1)
|
|
31
|
-
WHERE id = NEW.project_id;
|
|
32
|
-
END IF;
|
|
33
|
-
|
|
34
|
-
RETURN NEW;
|
|
35
|
-
END;
|
|
36
|
-
$$ LANGUAGE plpgsql;
|
|
37
|
-
|
|
38
|
-
DROP INDEX IF EXISTS entities_comment_parent_created_idx;
|
|
39
|
-
|
|
40
|
-
-- Fast "latest worklog entry per task" lookups for the opening brief.
|
|
41
|
-
CREATE INDEX IF NOT EXISTS entities_worklog_parent_created_idx
|
|
42
|
-
ON entities(parent_id, created_at DESC) WHERE kind = 'worklog';
|