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

Function addNewSchemaObjects

backend/plugin/schema/differ.go:360–464  ·  view source on GitHub ↗

addNewSchemaObjects adds all objects from a new schema as created.

(diff *MetadataDiff, schemaName string, schema *model.SchemaMetadata)

Source from the content-addressed store, hash-verified

358
359// addNewSchemaObjects adds all objects from a new schema as created.
360func addNewSchemaObjects(diff *MetadataDiff, schemaName string, schema *model.SchemaMetadata) {
361 schemaProto := schema.GetProto()
362
363 // Add all tables
364 for _, tableName := range schema.ListTableNames() {
365 table := schema.GetTable(tableName)
366 if table != nil && !table.GetProto().GetSkipDump() {
367 diff.TableChanges = append(diff.TableChanges, &TableDiff{
368 Action: MetadataDiffActionCreate,
369 SchemaName: schemaName,
370 TableName: tableName,
371 NewTable: table.GetProto(),
372 })
373 }
374 }
375
376 // Add all views
377 for _, viewName := range schema.ListViewNames() {
378 view := schema.GetView(viewName)
379 if view != nil && !view.SkipDump {
380 diff.ViewChanges = append(diff.ViewChanges, &ViewDiff{
381 Action: MetadataDiffActionCreate,
382 SchemaName: schemaName,
383 ViewName: viewName,
384 NewView: view,
385 })
386 }
387 }
388
389 // Add all materialized views
390 for _, mvName := range schema.ListMaterializedViewNames() {
391 mv := schema.GetMaterializedView(mvName)
392 if mv != nil && !mv.SkipDump {
393 diff.MaterializedViewChanges = append(diff.MaterializedViewChanges, &MaterializedViewDiff{
394 Action: MetadataDiffActionCreate,
395 SchemaName: schemaName,
396 MaterializedViewName: mvName,
397 NewMaterializedView: mv,
398 })
399 }
400 }
401
402 // Add all functions
403 for _, function := range schema.GetProto().GetFunctions() {
404 if !function.GetSkipDump() {
405 // Use signature if available, otherwise fall back to name
406 functionName := function.Signature
407 if functionName == "" {
408 functionName = function.Name
409 }
410 diff.FunctionChanges = append(diff.FunctionChanges, &FunctionDiff{
411 Action: MetadataDiffActionCreate,
412 SchemaName: schemaName,
413 FunctionName: functionName,
414 NewFunction: function,
415 })
416 }
417 }

Callers 1

GetDatabaseSchemaDiffFunction · 0.85

Calls 11

ListTableNamesMethod · 0.80
ListViewNamesMethod · 0.80
GetMaterializedViewMethod · 0.80
ListProcedureNamesMethod · 0.80
GetProcedureMethod · 0.80
GetProtoMethod · 0.45
GetTableMethod · 0.45
GetSkipDumpMethod · 0.45
GetViewMethod · 0.45
GetFunctionsMethod · 0.45

Tested by

no test coverage detected