botnote 0.2.16 → 0.2.17
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/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,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';
|