Ejemplo n.º 1
0
    def do_update(self):
        version = self.r.get('version')
        if not version:
            self.r.set('version', 8)
            return

        version = int(version)
        r = JSONRedis(self.r.r)
        r.caching = False

        # Deprecated since 0.14.0
        if version < 7:
            now = time()
            lists = r.omget(r.lrange('lists', 0, -1))
            for lst in lists:
                r.zadd('{}.lists'.format(lst['authors'][0]), {lst['id']: -now})
            r.set('version', 7)

        # Deprecated since 0.23.0
        if version < 8:
            lists = r.omget(r.lrange('lists', 0, -1))
            for lst in lists:
                users_key = '{}.users'.format(lst['id'])
                self.r.zadd(users_key, {lst['authors'][0].encode(): 0})
                events = r.omget(r.lrange('{}.activity.items'.format(lst['id']), 0, -1))
                for event in reversed(events):
                    t = parse_isotime(event['time'], aware=True).timestamp()
                    self.r.zadd(users_key, {event['user'].encode(): -t})
            r.set('version', 8)
Ejemplo n.º 2
0
    def do_update(self):
        db_version = self.r.get('version')

        # If fresh, initialize database
        if not db_version:
            self.r.set('version', 5)
            return

        db_version = int(db_version)
        r = JSONRedis(self.r.r)
        r.caching = False

        if db_version < 2:
            users = r.omget(r.lrange('users', 0, -1))
            for user in users:
                user['name'] = 'Guest'
                user['authors'] = [user['id']]
            r.omset({u['id']: u for u in users})
            r.set('version', 2)

        if db_version < 3:
            meetings = r.omget(r.lrange('meetings', 0, -1))
            for meeting in meetings:
                meeting['time'] = None
                meeting['location'] = None

                items = r.omget(r.lrange(meeting['id'] + '.items', 0, -1))
                for item in items:
                    item['duration'] = None
                r.omset({i['id']: i for i in items})
            r.omset({m['id']: m for m in meetings})
            r.set('version', 3)

        if db_version < 4:
            meeting_ids = r.lrange('meetings', 0, -1)
            objects = r.omget(chain(
                ['Settings'],
                r.lrange('users', 0, -1),
                meeting_ids,
                chain.from_iterable(r.lrange(i + b'.items', 0, -1) for i in meeting_ids)
            ))
            for object in objects:
                object['trashed'] = False
            r.omset({o['id']: o for o in objects})
            r.set('version', 4)

        if db_version < 5:
            users = r.omget(r.lrange('users', 0, -1))
            for user in users:
                user['email'] = None
            r.omset({u['id']: u for u in users})
            r.set('version', 5)
Ejemplo n.º 3
0
    def do_update(self):
        db_version = self.r.get('version')

        # If fresh, initialize database
        if not db_version:
            self.r.set('version', 5)
            return

        db_version = int(db_version)
        r = JSONRedis(self.r.r)
        r.caching = False

        # Deprecated since 0.12.0
        if db_version < 5:
            users = r.omget(r.lrange('users', 0, -1))
            for user in users:
                user['email'] = None
            r.omset({u['id']: u for u in users})
            r.set('version', 5)
Ejemplo n.º 4
0
    def do_update(self):
        version = self.r.get('version')
        if not version:
            self.r.set('version', 7)
            return

        version = int(version)
        r = JSONRedis(self.r.r)
        r.caching = False

        # Deprecated since 0.3.0
        if version < 2:
            lists = r.omget(r.lrange('lists', 0, -1))
            for lst in lists:
                lst['features'] = []
                items = r.omget(r.lrange('{}.items'.format(lst['id']), 0, -1))
                for item in items:
                    item['checked'] = False
                r.omset({item['id']: item for item in items})
            r.omset({lst['id']: lst for lst in lists})
            r.set('version', 2)

        # Deprecated since 0.5.0
        if version < 3:
            lists = r.omget(r.lrange('lists', 0, -1))
            for lst in lists:
                lst['activity'] = (Activity('{}.activity'.format(lst['id']),
                                            app=self,
                                            subscriber_ids=[]).json())
            r.omset({lst['id']: lst for lst in lists})
            r.set('version', 3)

        # Deprecated since 0.6.0
        if version < 4:
            items = r.omget([
                id for list_id in r.lrange('lists', 0, -1)
                for id in r.lrange('{}.items'.format(list_id.decode()), 0, -1)
            ])
            for item in items:
                item['location'] = None
            r.omset({item['id']: item for item in items})
            r.set('version', 4)

        # Deprecated since 0.7.0
        if version < 5:
            items = r.omget([
                id for list_id in r.lrange('lists', 0, -1)
                for id in r.lrange('{}.items'.format(list_id.decode()), 0, -1)
            ])
            for item in items:
                item['resource'] = None
            r.omset({item['id']: item for item in items})
            r.set('version', 5)

        # Deprecated since 0.11.0
        if version < 6:
            lists = r.omget(r.lrange('lists', 0, -1))
            for lst in lists:
                lst['mode'] = 'collaborate'
            r.omset({lst['id']: lst for lst in lists})
            r.set('version', 6)

        # Deprecated since 0.14.0
        if version < 7:
            now = time()
            lists = r.omget(r.lrange('lists', 0, -1))
            for lst in lists:
                r.zadd('{}.lists'.format(lst['authors'][0]), {lst['id']: -now})
            r.set('version', 7)