Ejemplo n.º 1
0
    def get_revert_migrations(self, current_migrations, backup_migrations):
        current_migrations, all_migrations = itertools.tee(
            reversed(
                list(
                    map(
                        Migration,
                        filter(None, current_migrations.splitlines()),
                    ))))
        all_migrations = utils.OrderedSet(all_migrations)

        backup_migrations = reversed(
            list(map(
                Migration,
                filter(None, backup_migrations.splitlines()),
            )))

        revert_migrations = utils.OrderedDict()

        while True:
            while True:
                backup_migration = next(backup_migrations, None)
                if not backup_migration or backup_migration in all_migrations:
                    break
            for current_migration in current_migrations:
                if current_migration == backup_migration:
                    break
                revert_migration = self._get_parent_migration(
                    current_migration,
                    migrations=all_migrations,
                )
                revert_migrations[current_migration.app] = revert_migration

            if backup_migration is None:
                return revert_migrations.values()
Ejemplo n.º 2
0
    def get_values_to_add(self, service, attr):
        new_values = self.get_new_values(service, attr)
        new_values = utils.OrderedSet(new_values)

        if not self.force_add:
            current_values = self.get_current_values(service.info)
            new_values -= current_values

        return list(new_values) or None
Ejemplo n.º 3
0
    def get_values_to_remove(self, service, attr):
        current_values = self.get_current_values(service.info)
        current_values = utils.OrderedSet(current_values)

        if not self.force_rm:
            new_values = self.get_new_values(service, attr)
            new_values = map(self.cast_rm, new_values)
            new_values = (value for values in new_values for value in (
                values if isinstance(values, (list, tuple)) else [values]))
            current_values -= new_values

        return list(current_values) or None