{"record":{"id":"2aa374f20bf3e494","repo":"siyuan-note/siyuan","slug":"encrypted-index-has-no-compatibility-metadata","errorCode":null,"errorMessage":"encrypted index has no compatibility metadata","messagePattern":"encrypted index has no compatibility metadata","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/util/encrypted_index.go","lineNumber":42,"sourceCode":"\t\t\treturn fmt.Errorf(\"missing encrypted index setting %s\", name)\n\t\t}\n\t\tsettings[name] = value\n\t}\n\tencoded, err := json.Marshal(settings)\n\tif err != nil {\n\t\treturn err\n\t}\n\tvar metadataTables int\n\tif err = db.QueryRow(\"SELECT count(*) FROM sqlite_master WHERE type = 'table' AND name = 'encrypted_index_meta'\").Scan(&metadataTables); err != nil {\n\t\treturn err\n\t}\n\tif metadataTables == 0 {\n\t\tvar tables int\n\t\tif err = db.QueryRow(\"SELECT count(*) FROM sqlite_master WHERE type = 'table'\").Scan(&tables); err != nil {\n\t\t\treturn err\n\t\t}\n\t\tif tables != 0 {\n\t\t\treturn errors.New(\"encrypted index has no compatibility metadata\")\n\t\t}\n\t\tif _, err = db.Exec(\"CREATE TABLE encrypted_index_meta (kind TEXT NOT NULL, schema_version INTEGER NOT NULL, cipher_settings TEXT NOT NULL)\"); err != nil {\n\t\t\treturn err\n\t\t}\n\t\t_, err = db.Exec(\"INSERT INTO encrypted_index_meta VALUES (?, ?, ?)\", kind, schema, string(encoded))\n\t\treturn err\n\t}\n\tvar storedKind, storedSettings string\n\tvar storedSchema, rows int\n\tif err = db.QueryRow(\"SELECT count(*) FROM encrypted_index_meta\").Scan(&rows); err != nil {\n\t\treturn err\n\t}\n\tif rows != 1 {\n\t\treturn errors.New(\"invalid encrypted index compatibility metadata\")\n\t}\n\tif err = db.QueryRow(\"SELECT kind, schema_version, cipher_settings FROM encrypted_index_meta\").Scan(&storedKind, &storedSchema, &storedSettings); err != nil {\n\t\treturn err\n\t}","sourceCodeStart":24,"sourceCodeEnd":60,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/util/encrypted_index.go#L24-L60","documentation":"CheckEncryptedIndexCompatibility expects an encrypted_index_meta table holding compatibility metadata (kind, schema_version, cipher settings). If the table is absent but the database already contains other tables, the kernel refuses to proceed: an index with data but no compatibility record cannot be authenticated. A brand-new empty database gets the meta table created and seeded instead.","triggerScenarios":"Opening an encrypted index DB that has data tables but no encrypted_index_meta — e.g. the meta table was dropped manually, the DB was created by a pre-metadata kernel version, or a plain unencrypted index is opened via the encrypted path.","commonSituations":"Upgrading from a development build before metadata was introduced; manual tampering with siyuan.db/blocktree.db; copying a plain SQLite index into an encrypted workspace.","solutions":["Let the kernel rebuild the index from authenticated source documents (delete the index file and reindex)","Restore the database from a sync snapshot or file history","Never copy plain SQLite index files into an encrypted workspace; let the kernel create encrypted indexes itself","If this appears after a version change, follow the release's migration steps"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":"var n int\nif err := db.QueryRow(\"SELECT count(*) FROM sqlite_master WHERE type='table' AND name='encrypted_index_meta'\").Scan(&n); err == nil && n == 0 {\n    // metadata absent: schedule rebuild from authenticated source documents\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Do not drop or edit encrypted_index_meta manually","Follow documented migration steps when upgrading kernels","Never place plain SQLite indexes into encrypted workspaces"],"tags":["database","encryption","metadata","schema"],"backgroundTag":"missing-required-config-field","analyzedSha":"9f775e8a12daef8255556097396f9b2739078892","analyzedAt":"2026-09-19T03:17:15.984Z","contentChangedAt":"2026-09-19T03:17:15.984Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}