Documentation
¶
Overview ¶
Package kbmigrate imports a camggould/kb SQLite database into a memgraph deployment.
kb's data model is a single SQLite `notes` table with a JSON `links` field referencing other notes by ID and a `workspace` column. memgraph partitions by workspace (one graph per distinct value, NULL/empty/whitespace → "default") and promotes `links` to real `cites` edges. Cross-workspace links become cross-graph symlinks.
Migration is idempotent: re-running Migrate against the same kb source picks up any net-new content and leaves existing nodes / edges untouched. Two mechanisms make this work:
- Stable lineage IDs derived from sha256(workspace, kb_note_id) so the same kb note always maps to the same memgraph lineage.
- Per-workspace graph identity stored in graph.metadata (kb_managed=true, kb_workspace=<ws>) so re-runs locate the existing graph instead of creating a new one.
Content updates on existing notes are NOT detected here; that's a v1.2 concern. For v1.1 the rule is: existing lineage → skip.
Index ¶
Constants ¶
const CreatedBy = "kb-migration"
CreatedBy is the opaque provenance string stamped on every node and edge written by the migrator.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type GraphReport ¶
type GraphReport struct {
Name string
ID memgraph.GraphID
NodeCount int // total nodes in the graph after the run
NodesCreated int // nodes inserted by this run
NodesSkipped int // notes whose lineage already existed
Reused bool // true if an existing kb-managed graph was matched
}
GraphReport describes a single graph that was (or would be) created or reused during migration.
type Options ¶
type Options struct {
// DryRun validates the source and reports what would be migrated
// without writing anything to the target store.
DryRun bool
}
Options controls migration behavior.
type Report ¶
type Report struct {
SourcePath string
TargetPath string // populated by the caller, not Migrate itself
Graphs []GraphReport
NodesCreated int
NodesSkipped int
EdgesCreated int
EdgesSkipped int
SkippedLinks []SkippedLink
DryRun bool
}
Report summarizes a migration run.
func Migrate ¶
func Migrate(ctx context.Context, kbDBPath string, store memgraph.Store, opts Options) (Report, error)
Migrate reads a kb SQLite database at kbDBPath and writes its contents into store as one graph per distinct workspace. Re-running against the same source is a noop on already-migrated notes; net-new notes/links are added.
type SkippedLink ¶
SkippedLink records a kb link whose target note was not present in the source database.