Skip to content

ENG-1977 Add schema import data layer for Obsidian - #1264

Open
trangdoan982 wants to merge 2 commits into
eng-1976-add-schema-export-command-to-obsidianfrom
eng-1977-add-schema-import-command-to-obsidian
Open

ENG-1977 Add schema import data layer for Obsidian#1264
trangdoan982 wants to merge 2 commits into
eng-1976-add-schema-export-command-to-obsidianfrom
eng-1977-add-schema-import-command-to-obsidian

Conversation

@trangdoan982

@trangdoan982 trangdoan982 commented Jul 29, 2026

Copy link
Copy Markdown
Member

Summary

Adds the import data layer — file parsing, match planning, and apply logic. The UI modal is in the next PR.

  • specImport.ts — three responsibilities co-located:
    • parseDgSchemaFile — lightweight version guard + cast (no Zod; export is the authoritative source)
    • buildSchemaImportMatchPlan — computes id and name/label mappings between the schema file and the local vault in one pass; id match first, name/label fallback second
    • applySchemaImportSelection — creates new items as provisional, skips existing matches; preserves template reference when template already exists locally

Stack

PR 4 of 5 for FEE-840. Stacks on #1263.

  1. Shared foundation — ENG-1975 (ENG-1975 Define schema file contract and shared foundation for Obsidian export/import #1180)
  2. Schema selection panel UI — ENG-2083 (ENG-2083 Add schema selection panel UI for Obsidian export/import #1262)
  3. Schema export command — ENG-1976 (ENG-1976 Add schema export command to Obsidian #1263)
  4. This PR — schema import data layer (ENG-1977)
  5. Schema import UI (ENG-2084)

Test plan

  • pnpm --filter @discourse-graphs/obsidian check-types passes
  • parseDgSchemaFile rejects files with wrong version with a clear error
  • buildSchemaImportMatchPlan id-matches first, name/label fallback second
  • applySchemaImportSelection creates new items as provisional, skips duplicates
  • Re-running apply on the same file creates no duplicates
  • New node type retains its template reference when template already exists locally

Open in Devin Review

@linear-code

linear-code Bot commented Jul 29, 2026

Copy link
Copy Markdown

ENG-1977

@supabase

supabase Bot commented Jul 29, 2026

Copy link
Copy Markdown

This pull request has been ignored for the connected project zytfjzqyijgagqxrzbmz because there are no changes detected in packages/database/supabase directory. You can change this behaviour in Project Integrations Settings ↗︎.


Preview Branches by Supabase.
Learn more about Supabase Branching ↗︎.

@vercel

vercel Bot commented Jul 29, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
discourse-graph Skipped Skipped Jul 29, 2026 2:59am

Request Review

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 1 potential issue.

View 1 additional finding in Devin Review.

Open in Devin Review

Comment on lines +333 to +338
template:
importedNodeType.template &&
(selectedTemplateNames.has(importedNodeType.template) ||
matchPlan.existingTemplateNames.has(importedNodeType.template))
? importedNodeType.template
: undefined,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Imported node type loses its template link when the template already exists in the vault but wasn't part of the imported file

A newly imported node type drops its template reference (matchPlan.existingTemplateNames.has(...) at apps/obsidian/src/utils/specImport.ts:336) whenever the referenced template exists locally but is not itself listed in the imported schema file, so the link is silently cleared even though the template is present in the vault.
Impact: A node type that should point at an existing local template ends up with no template, so notes created from it won't apply the expected template.

Why the local-existence check is too narrow

The preservation condition at apps/obsidian/src/utils/specImport.ts:333-338 keeps importedNodeType.template only if it is in selectedTemplateNames or in matchPlan.existingTemplateNames. existingTemplateNames is built in buildSchemaImportMatchPlan (apps/obsidian/src/utils/specImport.ts:176-181) by iterating schemaFile.templates and intersecting with the local template names — i.e. it only contains templates that are BOTH in the schema file AND present locally.

However, the exporter (apps/obsidian/src/utils/specExport.ts:92-95) includes only the templates explicitly selected for export, independent of which templates the exported node types reference. So a node type can be exported with template: "Foo" while "Foo" is not in schemaFile.templates. If "Foo" happens to exist locally in the importing vault, existingTemplateNames will not contain it, selectedTemplateNames won't either, and the reference is set to undefined — contradicting the intended behavior of retaining a template reference when the template already exists locally.

A correct check would compare importedNodeType.template against the full set of local template names (available at apps/obsidian/src/utils/specImport.ts:237), not just the schema∩local intersection.

Prompt for agents
In applySchemaImportSelection (apps/obsidian/src/utils/specImport.ts), the new node type's template reference is only preserved when the template name is in selectedTemplateNames or matchPlan.existingTemplateNames. matchPlan.existingTemplateNames is the intersection of the schema file's templates and the local vault templates, so a node type that references a template which exists locally but was NOT included in the schema file's templates array loses its reference. To fix, thread the full set of local template names (the localTemplateNames set computed in pickAndPreviewSchemaImport) into the match plan (e.g. store it on SchemaImportMatchPlan) and check the node's template against that full local set, so a reference to any locally-existing template is preserved regardless of whether the template was part of the imported file.
Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed: added localTemplateNames to SchemaImportMatchPlan and changed the template-preservation check from matchPlan.existingTemplateNames (schema∩local intersection) to matchPlan.localTemplateNames (full local set). A node type that references a template present in the vault but not in the imported file now correctly retains its template link.

@trangdoan982
trangdoan982 force-pushed the eng-1976-add-schema-export-command-to-obsidian branch from 3af9adf to f364d5a Compare July 29, 2026 02:58
@trangdoan982
trangdoan982 force-pushed the eng-1977-add-schema-import-command-to-obsidian branch from 23c69c1 to d417d43 Compare July 29, 2026 02:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant