{"record":{"id":"b8c060556a2b95ff","repo":"bytebase/bytebase","slug":"failed-to-compute-sdl-migration","errorCode":null,"errorMessage":"failed to compute SDL migration","messagePattern":"failed to compute SDL migration","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"backend/runner/taskrun/database_migrate_executor.go","lineNumber":1029,"sourceCode":"\tdbMetadata, err := s.GetDBSchema(ctx, &store.FindDBSchemaMessage{\n\t\tWorkspace:    instance.Workspace,\n\t\tInstanceID:   database.InstanceID,\n\t\tDatabaseName: database.DatabaseName,\n\t})\n\tif err != nil {\n\t\treturn \"\", errors.Wrapf(err, \"failed to get database schema for database %q\", database.DatabaseName)\n\t}\n\tif dbMetadata == nil {\n\t\treturn \"\", errors.Errorf(\"database schema %q not found\", database.DatabaseName)\n\t}\n\n\t// instance.Metadata.GetVersion() is the synced server version (e.g. \"5.7.25\"); thread\n\t// it so MySQL canonicalizes a 5.7 database's schema as 5.7 rather than the default 8.0\n\t// stored form. model.DatabaseMetadata drops the version, so it is sourced here where the\n\t// instance message still carries it. Other engines ignore the version.\n\tmigrationSQL, err := schema.SDLMigration(instance.Metadata.GetEngine(), sheetContent, dbMetadata, instance.Metadata.GetVersion())\n\tif err != nil {\n\t\treturn \"\", errors.Wrapf(err, \"failed to compute SDL migration\")\n\t}\n\n\treturn migrationSQL, nil\n}\n\n// computeNeedDump determines if schema dump is needed based on task type and statements.\nfunc computeNeedDump(taskType storepb.Task_Type, engine storepb.Engine, statement string) bool {\n\t//exhaustive:enforce\n\tswitch taskType {\n\tcase storepb.Task_DATABASE_MIGRATE:\n\t\t// For DATABASE_MIGRATE, skip dump if all statements are DML since they\n\t\t// don't change schema. IsAllDML owns the type list.\n\t\treturn !parserbase.IsAllDML(engine, statement)\n\tcase storepb.Task_DATABASE_CREATE:\n\t\treturn true\n\tcase storepb.Task_TASK_TYPE_UNSPECIFIED:\n\t\treturn false\n\tdefault:","sourceCodeStart":1011,"sourceCodeEnd":1047,"githubUrl":"https://github.com/bytebase/bytebase/blob/1870550677fe08f0d2a78c07acd27541464eb945/backend/runner/taskrun/database_migrate_executor.go#L1011-L1047","documentation":"This error wraps a failure from schema.SDLMigration, which generates the SQL needed to move a database from its current schema to the desired schema defined in a sheet (declarative/SDL migration). It is thrown during the diff step of a declarative release when the schema engine cannot compute the diff, e.g. because the dumped metadata or desired SDL is invalid for the target engine. The wrapped inner error from the schema package identifies the actual cause.","triggerScenarios":"Running a declarative release via runDeclarativeRelease: schema.SDLMigration(instance.Engine, sheetContent, dbMetadata, instanceVersion) returns an error because the sheet SDL fails to parse, the dumped database metadata is inconsistent, or the engine cannot canonicalize the schema (e.g. MySQL version-specific parsing).","commonSituations":"Desired-schema sheet contains SQL the engine's parser rejects; database metadata was dumped from a MySQL 5.7 instance but version threading failed; unsupported engine features appear in the SDL; schema drift produced a diff the engine cannot express.","solutions":["Inspect the wrapped inner error to find which part of the SDL/diff failed","Validate the sheet SDL content locally with the same engine/version parser","Re-dump the database metadata so dbMetadata matches the live schema","Verify instance.Metadata.GetVersion() is correct for MySQL version canonicalization","Check the engine type matches the actual database engine"],"exampleFix":"// before\nmigrationSQL, err := schema.SDLMigration(instance.Metadata.GetEngine(), sheetContent, dbMetadata, instance.Metadata.GetVersion())\nif err != nil {\n\treturn \"\", errors.Wrapf(err, \"failed to compute SDL migration\")\n}\n// after\nmigrationSQL, err := schema.SDLMigration(instance.Metadata.GetEngine(), sheetContent, dbMetadata, instance.Metadata.GetVersion())\nif err != nil {\n\treturn \"\", errors.Wrapf(err, \"failed to compute SDL migration for engine %s, version %s\", instance.Metadata.GetEngine(), instance.Metadata.GetVersion())\n}","handlingStrategy":"validation","validationCode":"// Pre-validate the sheet SDL parses for the engine before submitting the release\nif _, err := schema.ParseSDL(instance.Engine, sheetContent); err != nil {\n\treturn fmt.Errorf(\"invalid sheet SDL: %w\", err)\n}","typeGuard":"func dbMetadataValid(m *model.DatabaseMetadata) bool { return m != nil && len(m.Schemas) > 0 }","tryCatchPattern":"migrationSQL, err := schema.SDLMigration(engine, sheetContent, dbMetadata, version)\nif err != nil {\n\treturn \"\", fmt.Errorf(\"failed to compute SDL migration: %w\", err)\n}","preventionTips":["Validate SDL sheets against the target engine version before creating releases","Keep instance metadata (engine version) in sync with the real server","Re-dump database metadata before declarative diffs after manual DDL"],"tags":["schema","migration","sdl","mysql"],"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-14T00:17:10.932Z"}