{"record":{"id":"28c0c7fa791e8cbf","repo":"bytebase/bytebase","slug":"schema-metadata-not-found-for-s","errorCode":null,"errorMessage":"schema metadata not found for %s","messagePattern":"schema metadata not found for (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"backend/plugin/parser/pg/restore.go","lineNumber":111,"sourceCode":"\t\treturn \"\", errors.Errorf(\"GetDatabaseMetadataFunc is required\")\n\t}\n\n\t_, metadata, err := rCtx.GetDatabaseMetadataFunc(ctx, rCtx.InstanceID, sourceDatabase)\n\tif err != nil {\n\t\treturn \"\", errors.Wrapf(err, \"failed to get database metadata for %s\", sourceDatabase)\n\t}\n\n\tif metadata == nil {\n\t\treturn \"\", errors.Errorf(\"database metadata not found for %s\", sourceDatabase)\n\t}\n\n\tschema := backupItem.SourceTable.Schema\n\tif schema == \"\" {\n\t\tschema = \"public\"\n\t}\n\tschemaMetadata := metadata.GetSchemaMetadata(schema)\n\tif schemaMetadata == nil {\n\t\treturn \"\", errors.Errorf(\"schema metadata not found for %s\", schema)\n\t}\n\n\ttableMetadata := schemaMetadata.GetTable(backupItem.SourceTable.Table)\n\tif tableMetadata == nil {\n\t\treturn \"\", errors.Errorf(\"table metadata not found for %s.%s\", schema, backupItem.SourceTable.Table)\n\t}\n\n\tbackupSchema := backupItem.TargetTable.Schema\n\tbackupTable := backupItem.TargetTable.Table\n\toriginalSchema := schema\n\toriginalTable := backupItem.SourceTable.Table\n\tquotedColumnList := quotePGColumns(restorableColumns(tableMetadata))\n\n\tvar result string\n\tswitch n := node.(type) {\n\tcase *ast.DeleteStmt:\n\t\tresult = fmt.Sprintf(`INSERT INTO \"%s\".\"%s\" (%s) SELECT %s FROM \"%s\".\"%s\";`, originalSchema, originalTable, quotedColumnList, quotedColumnList, backupSchema, backupTable)\n\tcase *ast.UpdateStmt:","sourceCodeStart":93,"sourceCodeEnd":129,"githubUrl":"https://github.com/bytebase/bytebase/blob/1870550677fe08f0d2a78c07acd27541464eb945/backend/plugin/parser/pg/restore.go#L93-L129","documentation":"Database metadata was loaded, but the schema named by backupItem.SourceTable.Schema (defaulting to \"public\" when empty) has no corresponding SchemaMetadata entry. The restore needs the schema's tables to build the INSERT..SELECT statement.","triggerScenarios":"backupItem.SourceTable.Schema names a schema absent from the fetched metadata — schema dropped/renamed since backup, or the backup item recorded a schema that never existed (empty schema on a database where the table is not in public).","commonSituations":"Restoring after a schema rename; backups taken before a migration removed the schema; non-public schema stored incorrectly so the code falls back to \"public\" and misses.","solutions":["Verify the schema exists in the source database and update backupItem.SourceTable.Schema if it was renamed","If the table lives in the default schema, ensure metadata actually contains it or record the correct explicit schema","Refresh/sync database metadata so the provider returns current schemas"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"schema := backupItem.SourceTable.Schema\nif schema == \"\" { schema = \"public\" }\nif metadata.GetSchemaMetadata(schema) == nil {\n    return fmt.Errorf(\"schema %q missing from metadata; cannot restore\", schema)\n}","typeGuard":null,"tryCatchPattern":"if err != nil && strings.Contains(err.Error(), \"schema metadata not found\") {\n    // refresh metadata or surface a schema-mismatch error to the user\n}","preventionTips":["Record the explicit schema in backup items instead of relying on the \"public\" fallback","Re-sync schema metadata after any DDL migration affecting schemas","Validate backup items against current metadata before scheduling restore"],"tags":["go","postgres","schema","not-found"],"backgroundTag":"schema-validation-failed","analyzedSha":"1870550677fe08f0d2a78c07acd27541464eb945","analyzedAt":"2026-09-06T21:16:13.665Z","contentChangedAt":"2026-09-06T21:16:13.665Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}