Пример #1
0
    def _apply_field_ast(self, schema, context, node, op):
        link = context.get(PropertySourceContext)

        if op.property == 'required':
            if isinstance(node, qlast.CreateConcreteProperty):
                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 link:
            if isinstance(node, qlast.CreateConcreteProperty):
                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.SetPropertyType(
                        type=utils.typeref_to_ast(schema, op.new_value)
                    )
                )
        else:
            super()._apply_field_ast(schema, context, node, op)
Пример #2
0
 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.SetPropertyType(type=utils.typeref_to_ast(
                     schema, op.new_value), ), )
     else:
         super()._apply_field_ast(schema, context, node, op)
Пример #3
0
    def _apply_field_ast(
        self,
        schema: s_schema.Schema,
        context: sd.CommandContext,
        node: qlast.DDLOperation,
        op: sd.AlterObjectProperty,
    ) -> None:
        # type ignore below, because the class is used as mixin
        link = context.get(PropertySourceContext)  # type: ignore

        if op.property == 'required':
            if isinstance(node, qlast.CreateConcreteProperty):
                node.is_required = bool(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 link:
            if isinstance(node, qlast.CreateConcreteProperty):
                expr = self.get_attribute_value('expr')
                if expr is not None:
                    node.target = expr.qlast
                else:
                    ref = op.new_value
                    assert isinstance(ref, (so.Object, so.ObjectShell))
                    node.target = utils.typeref_to_ast(schema, ref)
            else:
                ref = op.new_value
                assert isinstance(ref, (so.Object, so.ObjectShell))
                node.commands.append(
                    qlast.SetPropertyType(
                        type=utils.typeref_to_ast(schema, ref)
                    )
                )
        else:
            super()._apply_field_ast(schema, context, node, op)
Пример #4
0
    def _apply_field_ast(self, schema, context, node, op):
        link = context.get(PropertySourceContext)

        if op.property == 'required':
            if isinstance(node, qlast.CreateConcreteProperty):
                node.is_required = op.new_value
            else:
                node.commands.append(
                    qlast.SetSpecialField(
                        name=qlast.ObjectRef(name='required'),
                        value=op.new_value,
                    ), )
        elif op.property == 'cardinality':
            node.cardinality = op.new_value
        elif op.property == 'target' and link:
            if isinstance(node, qlast.CreateConcreteProperty):
                node.target = utils.typeref_to_ast(schema, op.new_value)
            else:
                node.commands.append(
                    qlast.SetPropertyType(
                        type=utils.typeref_to_ast(schema, op.new_value)))
        else:
            super()._apply_field_ast(schema, context, node, op)
Пример #5
0
 def reduce_SETTYPE_FullTypeExpr(self, *kids):
     self.val = qlast.SetPropertyType(type=kids[1].val)