bytebase/bytebase · error

changelog %q not found

Error message

changelog %q not found

What it means

Raised by getSourceDBMetadata when the requested resource name refers to a changelog (the name contains the changelogs/ prefix) but the store lookup for that changelog returns no row. getSourceDBMetadata backs DiffSchema for both the source side and (via resolveDiffSchemaTargetSDL) the changelog target side, so this error can surface for either. It signals the changelog ID does not exist for that instance/database.

Source

Thrown at backend/api/v1/database_service.go:1041

		projectID, instanceID, databaseID, changelogID, err := common.GetDatabaseChangelogResourceName(request.Name)
		if err != nil {
			return nil, err
		}
		instance, err := s.getInstanceForDatabaseResource(ctx, projectID, instanceID)
		if err != nil {
			return nil, err
		}

		changelog, err := s.store.GetChangelog(ctx, &store.FindChangelogMessage{
			InstanceID:   instanceID,
			DatabaseName: &databaseID,
			ResourceID:   &changelogID,
		})
		if err != nil {
			return nil, err
		}
		if changelog == nil {
			return nil, errors.Errorf("changelog %q not found", changelogID)
		}

		// Use SyncHistory to get historical metadata
		if changelog.SyncHistory != nil {
			syncHistory, err := s.store.GetSyncHistory(ctx, *changelog.SyncHistory)
			if err != nil {
				return nil, err
			}
			if syncHistory == nil {
				return nil, errors.Errorf("sync history %s not found", *changelog.SyncHistory)
			}

			// Get instance to determine engine and case sensitivity
			return model.NewDatabaseMetadata(
				syncHistory.Metadata,
				[]byte(syncHistory.Schema),
				&storepb.DatabaseConfig{},
				instance.Metadata.GetEngine(),

View on GitHub (pinned to 1870550677)

Solutions

  1. List current changelogs for the database and use an existing changelog ID.
  2. Verify the changelog belongs to the exact instance/database in the resource name.
  3. If the changelog was garbage-collected, pick a newer changelog or diff against raw schema text instead.

Example fix

// before
name := "projects/p/instances/i/databases/d/changelogs/42" // purged
// after
changelogs := listChangelogs(db)
name := changelogs[len(changelogs)-1].Name // use a live changelog
Defensive patterns

Strategy: validation

Validate before calling

// Check the changelog exists before diffing
const cl = await api.listChangelogs({ parent: dbName, filter: `id = "${changelogID}"` })
if (cl.changelogs.length === 0) throw new Error(`changelog ${changelogID} not found; pick a live one`)

Try / catch

try {
  diffSchema(req)
} catch (e) {
  if (/changelog .* not found/.test(e.Message)) {
    const latest = await getLatestChangelog(dbName)
    req.target = new DiffSchemaRequest.Changelog(latest.name)
    return diffSchema(req)
  }
  throw e
}

Prevention

When it happens

Trigger: DiffSchema with request.Name (or target.Changelog) like projects/p/instances/i/databases/d/changelogs/<id> where GetChangelog finds nothing — deleted changelog, wrong ID, or changelog belongs to a different database.

Common situations: Changelog pruned by retention/cleanup policies; bookmarked diff URL pointing at a purged changelog; ID copied from a different database; cross-project changelog reference blocked earlier by validateDiffSchemaTargetProject.

Understand the failure class

Background: Record Not Found Errors: "not found", RecordNotFound, and "was not found" — what they mean and how to fix them — this error's family across 28 libraries.

Related errors


AI-assisted analysis of bytebase/bytebase@1870550677 (2026-09-06). Data as JSON: /api/errors/0061692bdc125e43. Report an issue: GitHub.