@netsirk/hippocampe-linux-x64 0.0.0-stage → 0.7.0

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.
Files changed (47) hide show
  1. package/bin/hippo +4 -0
  2. package/bin/migrations/20261006095556_baseline/migration.sql +201 -0
  3. package/bin/migrations/20261006095556_baseline/snapshot.json +2298 -0
  4. package/bin/migrations/20261006100925_sensitive_types/migration.sql +1 -0
  5. package/bin/migrations/20261006100925_sensitive_types/snapshot.json +2311 -0
  6. package/bin/migrations/20261006103751_entry_sources/migration.sql +1 -0
  7. package/bin/migrations/20261006103751_entry_sources/snapshot.json +2324 -0
  8. package/bin/migrations/20261006104542_inbox/migration.sql +20 -0
  9. package/bin/migrations/20261006104542_inbox/snapshot.json +2562 -0
  10. package/bin/migrations/20261006111614_inbox_mime/migration.sql +1 -0
  11. package/bin/migrations/20261006111614_inbox_mime/snapshot.json +2575 -0
  12. package/bin/migrations/20261006120126_search_index/migration.sql +9 -0
  13. package/bin/migrations/20261006120126_search_index/snapshot.json +2620 -0
  14. package/bin/migrations/20261006160724_findings/migration.sql +36 -0
  15. package/bin/migrations/20261006160724_findings/snapshot.json +3068 -0
  16. package/bin/migrations/20261007073146_instance_rules/migration.sql +6 -0
  17. package/bin/migrations/20261007073146_instance_rules/snapshot.json +3128 -0
  18. package/bin/migrations/20261007080007_read_in_parent/migration.sql +1 -0
  19. package/bin/migrations/20261007080007_read_in_parent/snapshot.json +3141 -0
  20. package/bin/migrations/20261007084816_pending_references/migration.sql +8 -0
  21. package/bin/migrations/20261007084816_pending_references/snapshot.json +3215 -0
  22. package/bin/migrations/20261007085835_merged_findings/migration.sql +1 -0
  23. package/bin/migrations/20261007085835_merged_findings/snapshot.json +3228 -0
  24. package/bin/migrations/20261007105935_merged_into_key/migration.sql +1 -0
  25. package/bin/migrations/20261007105935_merged_into_key/snapshot.json +3241 -0
  26. package/bin/migrations/20261007111353_remove_source_registry/migration.sql +13 -0
  27. package/bin/migrations/20261007111353_remove_source_registry/snapshot.json +3149 -0
  28. package/bin/migrations/20261007115731_link_note_and_dates/migration.sql +3 -0
  29. package/bin/migrations/20261007115731_link_note_and_dates/snapshot.json +3188 -0
  30. package/bin/migrations/20261008075945_resolve_stale_pending/migration.sql +11 -0
  31. package/bin/migrations/20261008075945_resolve_stale_pending/snapshot.json +3188 -0
  32. package/bin/migrations/20261008081223_archived_reason/migration.sql +1 -0
  33. package/bin/migrations/20261008081223_archived_reason/snapshot.json +3201 -0
  34. package/bin/migrations/20261009160041_entries_aliases/migration.sql +1 -0
  35. package/bin/migrations/20261009160041_entries_aliases/snapshot.json +3222 -0
  36. package/bin/migrations/20261009182911_known_or_supposed/migration.sql +32 -0
  37. package/bin/migrations/20261009182911_known_or_supposed/snapshot.json +3229 -0
  38. package/bin/migrations/20261009194740_part_of/migration.sql +86 -0
  39. package/bin/migrations/20261009194740_part_of/snapshot.json +3232 -0
  40. package/bin/migrations/20261009210344_rename_to_hippocampe/migration.sql +28 -0
  41. package/bin/migrations/20261009210344_rename_to_hippocampe/snapshot.json +3232 -0
  42. package/bin/migrations/20261010154936_dated_by/migration.sql +1 -0
  43. package/bin/migrations/20261010154936_dated_by/snapshot.json +3245 -0
  44. package/bin/migrations/20261010202749_instance_owner/migration.sql +8 -0
  45. package/bin/migrations/20261010202749_instance_owner/snapshot.json +3318 -0
  46. package/package.json +17 -4
  47. package/README.md +0 -3
@@ -0,0 +1,86 @@
1
+ -- The place an entry is part of is a dated link `part_of`, with its provenance. The key `parent`
2
+ -- of a write says that provenance, as `body` and `summary` say theirs: a field named `parent`
3
+ -- would share its key, and is refused, rather than guessed at. The owner renames it first.
4
+ DO $$
5
+ DECLARE
6
+ clashes text;
7
+ BEGIN
8
+ SELECT string_agg(format('the type `%s` has a field `parent`', t.name), ' and ' ORDER BY t.name)
9
+ INTO clashes
10
+ FROM "types" t, jsonb_array_elements(t.fields) AS f
11
+ WHERE t.deleted_at IS NULL AND f ->> 'name' = 'parent';
12
+ IF clashes IS NOT NULL THEN
13
+ RAISE EXCEPTION '%', upper(left(clashes, 1)) || substr(clashes, 2)
14
+ || ': it is the key of the provenance of the place an entry is part of. Rename the field first (`change_type` with `field` and `rename`), then start again.';
15
+ END IF;
16
+ END $$;
17
+ --> statement-breakpoint
18
+ -- Which of the links of one entry comes first: the order they were made in.
19
+ ALTER TABLE "links" ADD COLUMN "seq" bigint GENERATED BY DEFAULT AS IDENTITY (sequence name "links_seq_seq" INCREMENT BY 1 MINVALUE 1 MAXVALUE 9223372036854775807 START WITH 1 CACHE 1);--> statement-breakpoint
20
+ -- Each parent becomes a link `part_of` without dates, `unstated` as every link made before the
21
+ -- writers were asked, and the oldest of the places of its entry (a `seq` below every other), so
22
+ -- that its path is the one it had. A link `part_of` made by hand before, to the same parent, that
23
+ -- holds today is the place already, and is only put first; one that is over, or has not begun, is
24
+ -- kept as it was and the parent is a stay of its own (its period is the day of the migration). The
25
+ -- events keep their past changes of `parent_id`.
26
+ WITH migrated AS (
27
+ SELECT "id" AS "source_id", "parent_id" AS "target_id",
28
+ row_number() OVER (ORDER BY "id") - (SELECT count(*) + 1 FROM "entries" WHERE "parent_id" IS NOT NULL) AS "rank",
29
+ EXISTS (
30
+ SELECT 1 FROM "links" l
31
+ WHERE l."source_id" = "entries"."id" AND l."target_id" = "entries"."parent_id"
32
+ AND l."relation" = 'part_of' AND l."field" = ''
33
+ AND (l."valid_from" IS NULL OR l."valid_from" <= current_date)
34
+ AND (l."valid_until" IS NULL OR l."valid_until" >= current_date)
35
+ ) AS "held",
36
+ EXISTS (
37
+ SELECT 1 FROM "links" l
38
+ WHERE l."source_id" = "entries"."id" AND l."target_id" = "entries"."parent_id"
39
+ AND l."relation" = 'part_of' AND l."period" = '' AND l."field" = ''
40
+ ) AS "taken"
41
+ FROM "entries" WHERE "parent_id" IS NOT NULL
42
+ ), put_first AS (
43
+ UPDATE "links" SET "seq" = m."rank"
44
+ FROM migrated m
45
+ WHERE m."held" AND "links"."source_id" = m."source_id" AND "links"."target_id" = m."target_id"
46
+ AND "links"."relation" = 'part_of' AND "links"."field" = ''
47
+ AND ("links"."valid_from" IS NULL OR "links"."valid_from" <= current_date)
48
+ AND ("links"."valid_until" IS NULL OR "links"."valid_until" >= current_date)
49
+ )
50
+ INSERT INTO "links" ("source_id", "target_id", "relation", "period", "provenance", "seq")
51
+ SELECT m."source_id", m."target_id", 'part_of',
52
+ CASE WHEN m."taken" THEN to_char(current_date, 'YYYY-MM-DD') ELSE '' END, 'unstated', m."rank"
53
+ FROM migrated m WHERE NOT m."held";--> statement-breakpoint
54
+ -- The places an entry is part of form a tree, never a loop: a link `part_of` made by hand before
55
+ -- may close one with the parents, and is refused, rather than guessed at. One walk from every
56
+ -- entry along the places that hold today finds every entry a walk meets twice.
57
+ DO $$
58
+ DECLARE
59
+ slugs text[];
60
+ named text;
61
+ BEGIN
62
+ WITH RECURSIVE held AS (
63
+ SELECT "source_id", "target_id" FROM "links"
64
+ WHERE "relation" = 'part_of'
65
+ AND ("valid_from" IS NULL OR "valid_from" <= current_date)
66
+ AND ("valid_until" IS NULL OR "valid_until" >= current_date)
67
+ ), walk (id) AS (
68
+ SELECT "source_id" FROM held
69
+ UNION ALL
70
+ SELECT held."target_id" FROM walk JOIN held ON held."source_id" = walk.id
71
+ ) CYCLE id SET looped USING trail
72
+ SELECT array_agg(DISTINCT e.slug ORDER BY e.slug) INTO slugs
73
+ FROM "entries" e WHERE e.id IN (SELECT id FROM walk WHERE looped);
74
+ IF slugs IS NOT NULL THEN
75
+ named := regexp_replace((SELECT string_agg(format('`%s`', s), ', ') FROM unnest(slugs) AS s),
76
+ ', ([^,]*)$', ' and \1');
77
+ RAISE EXCEPTION '%', 'The links `part_of` make a loop: ' || named
78
+ || CASE WHEN cardinality(slugs) = 1 THEN ' is part of itself' ELSE ' are part of one another' END
79
+ || '. Remove one of them (`link` with `remove`), then start again.';
80
+ END IF;
81
+ END $$;
82
+ --> statement-breakpoint
83
+ ALTER TABLE "entries" DROP CONSTRAINT "entries_parent_id_fkey";--> statement-breakpoint
84
+ DROP INDEX "entries_parent_id";--> statement-breakpoint
85
+ ALTER TABLE "entries" DROP COLUMN "parent_id";--> statement-breakpoint
86
+ CREATE INDEX "links_part_of" ON "links" ("target_id","source_id") WHERE relation = 'part_of';