MCPcopy Index your code
hub / github.com/bytebase/bytebase / compareSchemaObjects

Function compareSchemaObjects

backend/plugin/schema/differ.go:467–531  ·  view source on GitHub ↗

compareSchemaObjects compares objects between two schemas.

(engine storepb.Engine, diff *MetadataDiff, schemaName string, oldSchema, newSchema *model.SchemaMetadata)

Source from the content-addressed store, hash-verified

465
466// compareSchemaObjects compares objects between two schemas.
467func compareSchemaObjects(engine storepb.Engine, diff *MetadataDiff, schemaName string, oldSchema, newSchema *model.SchemaMetadata) {
468 // Compare tables
469
470 // Check for dropped tables
471 for _, tableName := range oldSchema.ListTableNames() {
472 if newSchema.GetTable(tableName) == nil {
473 oldTable := oldSchema.GetTable(tableName)
474 if oldTable != nil && !oldTable.GetProto().GetSkipDump() {
475 diff.TableChanges = append(diff.TableChanges, &TableDiff{
476 Action: MetadataDiffActionDrop,
477 SchemaName: schemaName,
478 TableName: tableName,
479 OldTable: oldTable.GetProto(),
480 })
481 }
482 }
483 }
484
485 // Check for new and modified tables
486 for _, tableName := range newSchema.ListTableNames() {
487 newTable := newSchema.GetTable(tableName)
488 if newTable == nil || newTable.GetProto().GetSkipDump() {
489 continue
490 }
491
492 if oldSchema.GetTable(tableName) == nil {
493 diff.TableChanges = append(diff.TableChanges, &TableDiff{
494 Action: MetadataDiffActionCreate,
495 SchemaName: schemaName,
496 TableName: tableName,
497 NewTable: newTable.GetProto(),
498 })
499 } else {
500 // Compare table details
501 oldTable := oldSchema.GetTable(tableName)
502 if oldTable != nil && !oldTable.GetProto().GetSkipDump() {
503 tableDiff := compareTableDetails(engine, schemaName, tableName, oldTable, newTable)
504 if tableDiff != nil {
505 diff.TableChanges = append(diff.TableChanges, tableDiff)
506 }
507 }
508 }
509 }
510
511 // Compare views
512 compareViews(engine, diff, schemaName, oldSchema, newSchema)
513
514 // Compare materialized views
515 compareMaterializedViews(engine, diff, schemaName, oldSchema, newSchema)
516
517 // Compare functions
518 compareFunctions(engine, diff, schemaName, oldSchema, newSchema)
519
520 // Compare procedures
521 compareProcedures(diff, schemaName, oldSchema, newSchema)
522
523 // Compare sequences
524 compareSequences(diff, schemaName, oldSchema, newSchema)

Callers 1

GetDatabaseSchemaDiffFunction · 0.85

Calls 12

compareTableDetailsFunction · 0.85
compareEnumTypesFunction · 0.85
compareEventsFunction · 0.85
ListTableNamesMethod · 0.80
compareViewsFunction · 0.70
compareMaterializedViewsFunction · 0.70
compareFunctionsFunction · 0.70
compareProceduresFunction · 0.70
compareSequencesFunction · 0.70
GetTableMethod · 0.45
GetSkipDumpMethod · 0.45
GetProtoMethod · 0.45

Tested by

no test coverage detected