Exemplo n.º 1
0
    def build_models(self):
        """
        Build declarative version models based on classes that were collected
        during class instrumentation process.
        """
        if self.manager.pending_classes:
            cls = self.manager.pending_classes[0]
            self.manager.declarative_base = get_declarative_base(cls)
            self.manager.create_transaction_model()
            self.manager.plugins.after_build_tx_class(self.manager)

            for cls in self.manager.pending_classes:
                if not self.manager.option(cls, 'versioning'):
                    continue

                table = self.closest_matching_table(cls)
                if table is not None:
                    builder = ModelBuilder(self.manager, cls)
                    version_cls = builder(
                        table,
                        self.manager.transaction_cls
                    )

                    self.manager.plugins.after_version_class_built(
                        cls,
                        version_cls
                    )

        self.manager.plugins.after_build_models(self.manager)
def get_base_class(manager, model):
    """
    Returns all base classes for history model.
    """
    return (
        option(model, 'base_classes')
        or
        (get_declarative_base(model), )
    )
 def base_classes(self):
     """
     Returns all base classes for history model.
     """
     parents = (
         self.find_closest_versioned_parent()
         or option(self.model, 'base_classes')
         or (get_declarative_base(self.model), )
     )
     return parents + (VersionClassBase, )
Exemplo n.º 4
0
    def test_volume_dependent_models_list(self):
        """Make sure the volume dependent tables list is accurate."""
        # Addresses LP Bug #1542169

        volume_declarative_base = saf.get_declarative_base(models.Volume)
        volume_fks = saf.get_referencing_foreign_keys(models.Volume)

        dependent_tables = []
        for table, fks in saf.group_foreign_keys(volume_fks):
            dependent_tables.append(table)

        found_dependent_models = []
        for table in dependent_tables:
            found_dependent_models.append(
                saf.get_class_by_table(volume_declarative_base, table))

        self.assertEqual(len(found_dependent_models),
                         len(db_api.VOLUME_DEPENDENT_MODELS))
        for model in found_dependent_models:
            self.assertIn(model, db_api.VOLUME_DEPENDENT_MODELS)
Exemplo n.º 5
0
    def build_models(self):
        """
        Build declarative version models based on classes that were collected
        during class instrumentation process.
        """
        if self.manager.pending_classes:
            cls = self.manager.pending_classes[0]
            self.manager.declarative_base = get_declarative_base(cls)
            self.manager.create_transaction_model()
            self.manager.plugins.after_build_tx_class(self.manager)

            for cls in self.manager.pending_classes:
                if not self.manager.option(cls, 'versioning'):
                    continue

                table = self.closest_matching_table(cls)
                if table is not None:
                    builder = ModelBuilder(self.manager, cls)
                    version_cls = builder(table, self.manager.transaction_cls)

                    self.manager.plugins.after_version_class_built(
                        cls, version_cls)

        self.manager.plugins.after_build_models(self.manager)
Exemplo n.º 6
0
 def build_transaction_class(self):
     if self.manager.pending_classes:
         cls = self.manager.pending_classes[0]
         self.manager.declarative_base = get_declarative_base(cls)
         self.manager.create_transaction_model()
         self.manager.plugins.after_build_tx_class(self.manager)
Exemplo n.º 7
0
def get_base_class(manager, model):
    """
    Returns all base classes for history model.
    """
    return (option(model, 'base_classes') or (get_declarative_base(model), ))
Exemplo n.º 8
0
 def build_transaction_class(self):
     if self.manager.pending_classes:
         cls = self.manager.pending_classes[0]
         self.manager.declarative_base = get_declarative_base(cls)
         self.manager.create_transaction_model()
         self.manager.plugins.after_build_tx_class(self.manager)