def _apply_field_ast( self, schema: s_schema.Schema, context: sd.CommandContext, node: qlast.DDLOperation, op: sd.AlterObjectProperty, ) -> None: objtype = self.get_referrer_context(context) if op.property == 'target' and objtype: # Due to how SDL is processed the underlying AST may be an # AlterConcreteLink, which requires different handling. if isinstance(node, qlast.CreateConcreteLink): if not node.target: expr = self.get_attribute_value('expr') if expr is not None: node.target = expr.qlast else: t = op.new_value assert isinstance(t, (so.Object, so.ObjectShell)) node.target = utils.typeref_to_ast(schema, t) else: assert isinstance(op.new_value, (so.Object, so.ObjectShell)) node.commands.append( qlast.SetPointerType(value=utils.typeref_to_ast( schema, op.new_value), )) elif op.property == 'on_target_delete': node.commands.append(qlast.OnTargetDelete(cascade=op.new_value)) else: super()._apply_field_ast(schema, context, node, op)
def _apply_field_ast( self, schema: s_schema.Schema, context: sd.CommandContext, node: qlast.DDLOperation, op: sd.AlterObjectProperty, ) -> None: if op.property == 'target': if op.new_value: assert isinstance(op.new_value, so.ObjectShell) node.commands.append( qlast.SetPointerType(value=utils.typeref_to_ast( schema, op.new_value), ), ) elif op.property == 'computable': if not op.new_value: node.commands.append( qlast.SetField( name='expr', value=None, special_syntax=True, ), ) elif op.property == 'on_target_delete': node.commands.append(qlast.OnTargetDelete(cascade=op.new_value)) else: super()._apply_field_ast(schema, context, node, op)
def _apply_field_ast(self, schema, context, node, op): objtype = context.get(LinkSourceCommandContext) if op.property == 'required': # Due to how SDL is processed the underlying AST may be an # AlterConcreteLink, which requires different handling. if isinstance(node, qlast.CreateConcreteLink): node.is_required = op.new_value else: node.commands.append( qlast.SetSpecialField( name='required', value=op.new_value, )) elif op.property == 'cardinality': node.cardinality = op.new_value elif op.property == 'target' and objtype: # Due to how SDL is processed the underlying AST may be an # AlterConcreteLink, which requires different handling. if isinstance(node, qlast.CreateConcreteLink): if not node.target: expr = self.get_attribute_value('expr') if expr is not None: node.target = expr.qlast else: t = op.new_value node.target = utils.typeref_to_ast(schema, t) else: node.commands.append( qlast.SetLinkType( type=utils.typeref_to_ast(schema, op.new_value))) elif op.property == 'on_target_delete': node.commands.append(qlast.OnTargetDelete(cascade=op.new_value)) else: super()._apply_field_ast(schema, context, node, op)
def _apply_field_ast( self, schema: s_schema.Schema, context: sd.CommandContext, node: qlast.DDLOperation, op: sd.AlterObjectProperty, ) -> None: objtype = self.get_referrer_context(context) if op.property == 'target' and objtype: # Due to how SDL is processed the underlying AST may be an # AlterConcreteLink, which requires different handling. if isinstance(node, qlast.CreateConcreteLink): if not node.target: expr = self.get_attribute_value('expr') if expr is not None: node.target = expr.qlast else: t = op.new_value assert isinstance(t, (so.Object, so.ObjectShell)) node.target = utils.typeref_to_ast(schema, t) else: old_type = pointers.merge_target( self.scls, list(self.scls.get_bases(schema).objects(schema)), 'target', ignore_local=True, schema=schema, ) assert isinstance(op.new_value, (so.Object, so.ObjectShell)) new_type = ( op.new_value.resolve(schema) if isinstance(op.new_value, so.ObjectShell) else op.new_value) new_type_ast = utils.typeref_to_ast(schema, op.new_value) cast_expr = None # If the type isn't assignment castable, generate a # USING with a nonsense cast. It shouldn't matter, # since there should be no data to cast, but the DDL side # of things doesn't know that since the command is split up. if old_type and not old_type.assignment_castable_to( new_type, schema): cast_expr = qlast.TypeCast( type=new_type_ast, expr=qlast.Set(elements=[]), ) node.commands.append( qlast.SetPointerType( value=new_type_ast, cast_expr=cast_expr, ) ) elif op.property == 'on_target_delete': node.commands.append(qlast.OnTargetDelete(cascade=op.new_value)) else: super()._apply_field_ast(schema, context, node, op)
def _apply_field_ast( self, schema: s_schema.Schema, context: sd.CommandContext, node: qlast.DDLOperation, op: sd.AlterObjectProperty, ) -> None: objtype = self.get_referrer_context(context) if op.property == 'target' and objtype: # Due to how SDL is processed the underlying AST may be an # AlterConcreteLink, which requires different handling. if isinstance(node, qlast.CreateConcreteLink): if not node.target: expr = self.get_attribute_value('expr') if expr is not None: node.target = expr.qlast else: t = op.new_value assert isinstance(t, (so.Object, so.ObjectShell)) node.target = utils.typeref_to_ast(schema, t) else: assert isinstance(op.new_value, (so.Object, so.ObjectShell)) top_op = self.get_top_referrer_op(context) conv_expr: Optional[qlast.Expr] if (top_op is not None and (isinstance(top_op, sd.CreateObject) or (top_op.orig_cmd_type is not None and issubclass(top_op.orig_cmd_type, sd.CreateObject)))): # This op is part of CREATE TYPE, so avoid tripping up # the DDL check on SET TYPE by generating an appropriate # conversion expression: USING (.foo[IS Type]). lname = sn.shortname_from_fullname(self.classname).name conv_expr = qlast.Path( partial=True, steps=[ qlast.Ptr(ptr=qlast.ObjectRef(name=lname)), qlast.TypeIntersection(type=utils.typeref_to_ast( schema, op.new_value)) ], ) else: conv_expr = None node.commands.append( qlast.SetPointerType( value=utils.typeref_to_ast(schema, op.new_value), expr=conv_expr, )) elif op.property == 'on_target_delete': node.commands.append(qlast.OnTargetDelete(cascade=op.new_value)) else: super()._apply_field_ast(schema, context, node, op)
def reduce_ON_TARGET_DELETE_DEFERRED_RESTRICT(self, *kids): self.val = qlast.OnTargetDelete( cascade=qlast.LinkTargetDeleteAction.DEFERRED_RESTRICT)
def reduce_ON_TARGET_DELETE_ALLOW(self, *kids): self.val = qlast.OnTargetDelete( cascade=qlast.LinkTargetDeleteAction.ALLOW)
def reduce_ON_TARGET_DELETE_DELETE_SOURCE(self, *kids): self.val = qlast.OnTargetDelete( cascade=qlast.LinkTargetDeleteAction.DELETE_SOURCE)
def reduce_ON_TARGET_DELETE_RESTRICT(self, *kids): self.val = qlast.OnTargetDelete( cascade=qltypes.LinkTargetDeleteAction.Restrict)