@@ -475,9 +475,37 @@ const convertDgToSupabaseConcepts = async ({
475475 const { isEnabled : templatesEnabled , folderPath : templatesFolderPath } =
476476 getTemplatePluginInfo ( plugin . app ) ;
477477
478+ let missingTemplateLocalIds = new Set < string | null > ( ) ;
479+ if ( fullSync && templatesEnabled && templatesFolderPath ) {
480+ const absentTemplates = await supabaseClient
481+ . from ( "my_concepts" )
482+ . select ( "source_local_id,literal_content" )
483+ . eq ( "is_schema" , true )
484+ . eq ( "arity" , 0 )
485+ . eq ( "space_id" , context . spaceId )
486+ . is ( "literal_content->>template_content" , null ) ;
487+ // could not filter on only absent keys, this includes nulls
488+
489+ if ( absentTemplates . data && absentTemplates . data . length > 0 ) {
490+ missingTemplateLocalIds = new Set (
491+ absentTemplates . data
492+ . filter (
493+ ( x ) =>
494+ ( x . literal_content as Record < string , Json > ) . template_content !==
495+ null ,
496+ )
497+ . map ( ( x ) => x [ "source_local_id" ] ) ,
498+ ) ;
499+ }
500+ }
501+
478502 const nodesTypesToLocalConcepts = await Promise . all (
479503 nodeTypes
480- . filter ( ( nodeType ) => nodeType . modified > lastNodeSchemaSync )
504+ . filter (
505+ ( nodeType ) =>
506+ nodeType . modified > lastNodeSchemaSync ||
507+ missingTemplateLocalIds . has ( nodeType . id ) ,
508+ )
481509 . map ( async ( nodeType ) => {
482510 let templateContent : string | undefined ;
483511 if ( nodeType . template && templatesEnabled && templatesFolderPath ) {
0 commit comments