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

Function dropObjectsInOrder

backend/plugin/schema/oracle/generate_migration.go:44–392  ·  view source on GitHub ↗

dropObjectsInOrder drops all objects in reverse topological order (most dependent first)

(diff *schema.MetadataDiff, buf *strings.Builder)

Source from the content-addressed store, hash-verified

42
43// dropObjectsInOrder drops all objects in reverse topological order (most dependent first)
44func dropObjectsInOrder(diff *schema.MetadataDiff, buf *strings.Builder) {
45 // Build dependency graph for all objects being dropped or altered
46 graph := parserbase.NewGraph()
47
48 // Maps to store different object types
49 viewMap := make(map[string]*schema.ViewDiff)
50 materializedViewMap := make(map[string]*schema.MaterializedViewDiff)
51 tableMap := make(map[string]*schema.TableDiff)
52 functionMap := make(map[string]*schema.FunctionDiff)
53 procedureMap := make(map[string]*schema.ProcedureDiff)
54 sequenceMap := make(map[string]*schema.SequenceDiff)
55
56 // Track all object IDs for dependency resolution
57 allObjects := make(map[string]bool)
58
59 // Collect schemas being dropped to ensure their objects are dropped first
60 schemasBeingDropped := make(map[string]bool)
61 for _, schemaDiff := range diff.SchemaChanges {
62 if schemaDiff.Action == schema.MetadataDiffActionDrop {
63 schemasBeingDropped[schemaDiff.SchemaName] = true
64 }
65 }
66
67 // Add views to graph
68 for _, viewDiff := range diff.ViewChanges {
69 if viewDiff.Action == schema.MetadataDiffActionDrop || viewDiff.Action == schema.MetadataDiffActionAlter {
70 viewID := getMigrationObjectID(viewDiff.SchemaName, viewDiff.ViewName)
71 graph.AddNode(viewID)
72 viewMap[viewID] = viewDiff
73 allObjects[viewID] = true
74 }
75 }
76
77 // Add materialized views to graph
78 for _, mvDiff := range diff.MaterializedViewChanges {
79 if mvDiff.Action == schema.MetadataDiffActionDrop || mvDiff.Action == schema.MetadataDiffActionAlter {
80 mvID := getMigrationObjectID(mvDiff.SchemaName, mvDiff.MaterializedViewName)
81 graph.AddNode(mvID)
82 materializedViewMap[mvID] = mvDiff
83 allObjects[mvID] = true
84 }
85 }
86
87 // Add functions to graph
88 for _, funcDiff := range diff.FunctionChanges {
89 if funcDiff.Action == schema.MetadataDiffActionDrop {
90 funcID := getMigrationObjectID(funcDiff.SchemaName, funcDiff.FunctionName)
91 graph.AddNode(funcID)
92 functionMap[funcID] = funcDiff
93 allObjects[funcID] = true
94 }
95 }
96
97 // Add procedures to graph
98 for _, procDiff := range diff.ProcedureChanges {
99 if procDiff.Action == schema.MetadataDiffActionDrop {
100 procID := getMigrationObjectID(procDiff.SchemaName, procDiff.ProcedureName)
101 graph.AddNode(procID)

Callers 1

generateMigrationFunction · 0.70

Calls 15

AddNodeMethod · 0.95
AddEdgeMethod · 0.95
TopologicalSortMethod · 0.95
writeDropConstraintFunction · 0.85
writeDropSchemaFunction · 0.85
getMigrationObjectIDFunction · 0.70
writeDropForeignKeyFunction · 0.70
writeDropViewFunction · 0.70
writeDropFunctionFunction · 0.70
writeDropProcedureFunction · 0.70

Tested by

no test coverage detected