Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript
1.4 KB
Raw Blame
import type { Migration } from './types.ts';

export const v145: Migration = {
  version: 145,
  name: 'facts_kind_idea_alter',
  // Widen facts.kind with 'idea' (extractor/DB taxonomy only — the frozen
  // MEMORY_VERBS remember enum in src/core/verbs.ts does NOT gain it).
  // The kind CHECK shipped INLINE in v45's CREATE TABLE, so Postgres
  // autogenerated its name (`facts_kind_check` — table_column_check for a
  // single inline column CHECK) and old brains carry the 5-kind predicate:
  // an INSERT with kind='idea' violates it. ALTER counterpart per the v47
  // facts_notability_alter pattern. Idempotent under all states:
  //   - Fresh install (widened inline DDL above): probe finds the autogen
  //     constraint, drops it, re-adds the identical widened CHECK.
  //   - Old brain (5-kind CHECK): drop + re-add with the widened list.
  //   - Re-run / probe miss: ADD always runs, so the CHECK converges to
  //     the widened predicate under the same deterministic name.
  idempotent: true,
  sql: `
      DO $$ BEGIN
        IF EXISTS (
          SELECT 1 FROM pg_constraint
          WHERE conname = 'facts_kind_check'
            AND conrelid = 'facts'::regclass
        ) THEN
          ALTER TABLE facts DROP CONSTRAINT facts_kind_check;
        END IF;
        ALTER TABLE facts ADD CONSTRAINT facts_kind_check
          CHECK (kind IN ('event','preference','commitment','belief','fact','idea'));
      END $$;
    `,
};