Exemple #1
0
    def _apply_field_ast(
        self,
        schema: s_schema.Schema,
        context: sd.CommandContext,
        node: qlast.DDLOperation,
        op: sd.AlterObjectProperty,
    ) -> None:
        if op.property == 'bases':
            explicit_bases = self.get_explicit_bases(schema, context,
                                                     op.new_value)

            if explicit_bases:
                if isinstance(node, qlast.CreateObject):
                    node.bases = [
                        qlast.TypeName(maintype=utils.name_to_ast_ref(b))
                        for b in explicit_bases
                    ]
                else:
                    node.commands.append(
                        qlast.AlterAddInherit(bases=[
                            utils.name_to_ast_ref(b) for b in explicit_bases
                        ], ))
        elif op.property == 'is_abstract':
            node.is_abstract = op.new_value
        elif op.property == 'is_final':
            node.is_final = op.new_value
        else:
            super()._apply_field_ast(schema, context, node, op)
Exemple #2
0
    def _apply_field_ast(
        self,
        schema: s_schema.Schema,
        context: sd.CommandContext,
        node: qlast.DDLOperation,
        op: sd.AlterObjectProperty,
    ) -> None:
        if op.property == 'bases':
            mcls = self.get_schema_metaclass()
            default_base = mcls.get_default_base_name()

            bases = op.new_value
            assert isinstance(bases, so.ObjectList)

            base_names: List[sn.SchemaName] = [
                b for b in bases.names(schema, allow_unresolved=True)
                if isinstance(b, sn.SchemaName)
                if b != default_base and sn.shortname_from_fullname(b) == b
            ]

            if base_names:
                if isinstance(node, qlast.CreateObject):
                    node.bases = [
                        qlast.TypeName(
                            maintype=qlast.ObjectRef(
                                name=b.name,
                                module=b.module
                            )
                        )
                        for b in base_names
                    ]
                else:
                    node.commands.append(
                        qlast.AlterAddInherit(
                            bases=[
                                qlast.ObjectRef(
                                    module=b.module,
                                    name=b.name
                                )
                                for b in base_names
                            ],
                        )
                    )

        elif op.property == 'is_abstract':
            node.is_abstract = op.new_value
        elif op.property == 'is_final':
            node.is_final = op.new_value
        else:
            super()._apply_field_ast(schema, context, node, op)