compareMaterializedViews compares materialized views between two schemas.
(engine storepb.Engine, diff *MetadataDiff, schemaName string, oldSchema, newSchema *model.SchemaMetadata)
| 1571 | |
| 1572 | // compareMaterializedViews compares materialized views between two schemas. |
| 1573 | func compareMaterializedViews(engine storepb.Engine, diff *MetadataDiff, schemaName string, oldSchema, newSchema *model.SchemaMetadata) { |
| 1574 | // Get the engine-specific view comparer |
| 1575 | comparer := GetViewComparer(engine) |
| 1576 | // Check for dropped materialized views |
| 1577 | for _, mvName := range oldSchema.ListMaterializedViewNames() { |
| 1578 | if newSchema.GetMaterializedView(mvName) == nil { |
| 1579 | oldMV := oldSchema.GetMaterializedView(mvName) |
| 1580 | if oldMV != nil && !oldMV.SkipDump { |
| 1581 | diff.MaterializedViewChanges = append(diff.MaterializedViewChanges, &MaterializedViewDiff{ |
| 1582 | Action: MetadataDiffActionDrop, |
| 1583 | SchemaName: schemaName, |
| 1584 | MaterializedViewName: mvName, |
| 1585 | OldMaterializedView: oldMV, |
| 1586 | }) |
| 1587 | } |
| 1588 | } |
| 1589 | } |
| 1590 | |
| 1591 | // Check for new and modified materialized views |
| 1592 | for _, mvName := range newSchema.ListMaterializedViewNames() { |
| 1593 | newMV := newSchema.GetMaterializedView(mvName) |
| 1594 | if newMV == nil || newMV.SkipDump { |
| 1595 | continue |
| 1596 | } |
| 1597 | |
| 1598 | oldMV := oldSchema.GetMaterializedView(mvName) |
| 1599 | if oldMV == nil { |
| 1600 | diff.MaterializedViewChanges = append(diff.MaterializedViewChanges, &MaterializedViewDiff{ |
| 1601 | Action: MetadataDiffActionCreate, |
| 1602 | SchemaName: schemaName, |
| 1603 | MaterializedViewName: mvName, |
| 1604 | NewMaterializedView: newMV, |
| 1605 | }) |
| 1606 | } else if !oldMV.SkipDump { |
| 1607 | // Use engine-specific comparison |
| 1608 | changes, err := comparer.CompareMaterializedView(oldMV, newMV) |
| 1609 | if err != nil { |
| 1610 | // Fallback to simple definition comparison on error |
| 1611 | if oldMV.Definition != newMV.Definition { |
| 1612 | diff.MaterializedViewChanges = append(diff.MaterializedViewChanges, &MaterializedViewDiff{ |
| 1613 | Action: MetadataDiffActionAlter, |
| 1614 | SchemaName: schemaName, |
| 1615 | MaterializedViewName: mvName, |
| 1616 | OldMaterializedView: oldMV, |
| 1617 | NewMaterializedView: newMV, |
| 1618 | }) |
| 1619 | } |
| 1620 | } else if len(changes) > 0 { |
| 1621 | // Check if any change requires recreation |
| 1622 | requiresRecreation := false |
| 1623 | for _, change := range changes { |
| 1624 | if change.RequiresRecreation { |
| 1625 | requiresRecreation = true |
| 1626 | break |
| 1627 | } |
| 1628 | } |
| 1629 | |
| 1630 | if requiresRecreation { |
no test coverage detected