MCPcopy Create free account
hub / github.com/bytebase/bytebase / DiffMigration

Function DiffMigration

backend/plugin/schema/schema.go:302–323  ·  view source on GitHub ↗

DiffMigration computes the migration SQL between two database metadata states. Engines may register a metadata migration to avoid round-tripping synced metadata through SDL text. Otherwise, engines with DiffSDLMigration registered convert both sides to SDL and diff. The legacy MetadataDiff + Generat

(engine storepb.Engine, oldSchema, newSchema *model.DatabaseMetadata)

Source from the content-addressed store, hash-verified

300// convert both sides to SDL and diff. The legacy MetadataDiff + GenerateMigration
301// path remains the fallback for engines that haven't migrated yet.
302func DiffMigration(engine storepb.Engine, oldSchema, newSchema *model.DatabaseMetadata) (string, error) {
303 if f, ok := diffMetadataMigrations[engine]; ok {
304 return f(oldSchema, newSchema)
305 }
306 if _, ok := diffSDLMigrations[engine]; ok {
307 sourceSDL, err := MetadataToSDL(engine, oldSchema)
308 if err != nil {
309 return "", errors.Wrap(err, "failed to convert source schema to SDL")
310 }
311 targetSDL, err := MetadataToSDL(engine, newSchema)
312 if err != nil {
313 return "", errors.Wrap(err, "failed to convert target schema to SDL")
314 }
315 return DiffSDLMigration(engine, sourceSDL, targetSDL)
316 }
317 // Fallback to legacy path for engines that haven't migrated yet.
318 diff, err := GetDatabaseSchemaDiff(engine, oldSchema, newSchema)
319 if err != nil {
320 return "", err
321 }
322 return GenerateMigration(engine, diff)
323}
324
325func RegisterDiffMetadataMigration(engine storepb.Engine, f diffMetadataMigration) {
326 mux.Lock()

Calls 5

fFunction · 0.85
MetadataToSDLFunction · 0.85
DiffSDLMigrationFunction · 0.85
GetDatabaseSchemaDiffFunction · 0.85
GenerateMigrationFunction · 0.85