Only recreate inhviews that actually include modified pointers
Currently whenever a pointer changes or is deleted we update all
the inhviews of all the ancestors of the *source*, which always
includes Object and BaseObject.
Instead of updating the ancestors of the source, update the source
of the ancestors.
@@ -2955,6 +2955,25 @@ class CompositeMetaCommand(MetaCommand):
alter_ancestors=False,
)
+ def alter_ancestor_source_inhviews(
+ self,
+ schema: s_schema.Schema,
+ context: sd.CommandContext,
+ obj: s_pointers.Pointer,
+ *,
+ exclude_children: FrozenSet[s_sources.Source] = frozenset(),
+ ) -> None:
+ for base in obj.get_ancestors(schema).objects(schema):
+ src = base.get_source(schema)
+ if src and has_table(src, schema) and not context.is_deleting(src):
+ self.alter_inhview(
+ schema,
+ context,
+ src,
+ exclude_children=exclude_children,
+ alter_ancestors=False,
+ )
+
def create_inhview(
self,
schema: s_schema.Schema,
@@ -3603,7 +3622,10 @@ class PointerMetaCommand(MetaCommand):
self.pgops.add(dbops.Query(update_qry))
- self.recreate_inhview(schema, context, ref_op.scls)
+ self.recreate_inhview(
+ schema, context, ref_op.scls, alter_ancestors=False)
+ self.alter_ancestor_source_inhviews(
+ schema, context, ptr)
ref_op = self.get_referrer_context_or_die(context).op
alter_table = ref_op.get_alter_table(
@@ -3887,8 +3909,9 @@ class PointerMetaCommand(MetaCommand):
if changing_col_type:
self.drop_inhview(schema, context, source)
- self.alter_ancestor_inhviews(
- schema, context, source, exclude_children=frozenset((source,)))
+ self.alter_ancestor_source_inhviews(
+ schema, context, pointer,
+ exclude_children=frozenset((source,)))
tab = q(*old_ptr_stor_info.table_name)
target_col = old_ptr_stor_info.column_name
@@ -4044,7 +4067,8 @@ class PointerMetaCommand(MetaCommand):
self._recreate_constraints(pointer, schema, context)
if changing_col_type:
- self.create_inhview(schema, context, source)
+ self.create_inhview(schema, context, source, alter_ancestors=False)
+ self.alter_ancestor_source_inhviews(schema, context, pointer)
def _compile_conversion_expr(
self,
@@ -4467,6 +4491,10 @@ class LinkMetaCommand(CompositeMetaCommand, PointerMetaCommand):
context,
objtype.scls,
exclude_ptrs=frozenset((link,)),
+ alter_ancestors=False,
+ )
+ self.alter_ancestor_source_inhviews(
+ schema, context, link
)
alter_table = objtype.op.get_alter_table(
schema, context, manual=True)
@@ -4901,11 +4929,19 @@ class PropertyMetaCommand(CompositeMetaCommand, PointerMetaCommand):
alter_table = source_op.get_alter_table(
schema, context, force_new=True, manual=True)
+ # source and target don't have a proper inheritence
+ # hierarchy, so we can't do the source trick for them
+ is_endpoint_ptr = prop.is_endpoint_pointer(schema)
self.recreate_inhview(
schema,
context,
source,
exclude_ptrs=frozenset((prop,)),
+ alter_ancestors=is_endpoint_ptr,
+ )
+ if not is_endpoint_ptr:
+ self.alter_ancestor_source_inhviews(
+ schema, context, prop
)
col = dbops.AlterTableDropColumn(
