Ejemplo n.º 1
0
    def update(self):
        """Updates the database schema
        """
        # Make sure that database functions are up to date even if there are no patches to apply.
        from stoqlib.database.admin import create_database_functions
        create_database_functions()

        if self.check_uptodate():
            print('Database is already at the latest version %d.%d' %
                  (self.get_current_version()))
        else:
            from_, to = self._update_schema()
            if to is None:
                print('Database schema is already up to date')
            else:
                f = "(%d.%d)" % from_
                t = "(%d.%d)" % to
                print('Database schema updated from %s to %s' % (f, t))
Ejemplo n.º 2
0
    def update(self):
        """Updates the database schema
        """
        # Make sure that database functions are up to date even if there are no patches to apply.
        from stoqlib.database.admin import create_database_functions
        create_database_functions()

        if self.check_uptodate():
            print('Database is already at the latest version %d.%d' % (
                self.get_current_version()))
        else:
            from_, to = self._update_schema()
            if to is None:
                print('Database schema is already up to date')
            else:
                f = "(%d.%d)" % from_
                t = "(%d.%d)" % to
                print('Database schema updated from %s to %s' % (f, t))
Ejemplo n.º 3
0
    def _update_schema(self):
        """Check the current version of database and update the schema if
        it's needed
        """
        log.info("Updating schema")

        if self.check_uptodate():
            log.info("Schema is already up to date")
            return

        patches = self._get_patches()
        latest_available = patches[-1].get_version()
        current_version = self.get_current_version()

        last_level = None
        if current_version != latest_available:
            patches_to_apply = []
            for patch in patches:
                if patch.get_version() <= current_version:
                    continue
                patches_to_apply.append(patch)

            from stoqlib.database.admin import create_database_functions
            create_database_functions()

            log.info("Applying %d patches" % (len(patches_to_apply), ))
            create_log.info("PATCHES:%d" % (len(patches_to_apply), ))

            for patch in patches_to_apply:
                create_log.info("PATCH:%d.%d" % (patch.generation,
                                                 patch.level))
                patch.apply(self.default_store)

            assert patches_to_apply
            log.info("All patches (%s) applied." % (
                ', '.join(str(p.level) for p in patches_to_apply)))
            last_level = patches_to_apply[-1].get_version()

        self.after_update()

        return current_version, last_level
Ejemplo n.º 4
0
    def _update_schema(self):
        """Check the current version of database and update the schema if
        it's needed
        """
        log.info("Updating schema")

        if self.check_uptodate():
            log.info("Schema is already up to date")
            return

        patches = self._get_patches()
        latest_available = patches[-1].get_version()
        current_version = self.get_current_version()

        last_level = None
        if current_version != latest_available:
            patches_to_apply = []
            for patch in patches:
                if patch.get_version() <= current_version:
                    continue
                patches_to_apply.append(patch)

            from stoqlib.database.admin import create_database_functions
            create_database_functions()

            log.info("Applying %d patches" % (len(patches_to_apply), ))
            create_log.info("PATCHES:%d" % (len(patches_to_apply), ))

            for patch in patches_to_apply:
                create_log.info("PATCH:%d.%d" %
                                (patch.generation, patch.level))
                patch.apply(self.default_store)

            assert patches_to_apply
            log.info("All patches (%s) applied." %
                     (', '.join(str(p.level) for p in patches_to_apply)))
            last_level = patches_to_apply[-1].get_version()

        self.after_update()

        return current_version, last_level