def METHOD_NAME(db):
    class Peer(db.Entity):
        id = orm.PrimaryKey(int, auto=True)
        public_key = orm.Required(bytes, unique=True)
        added_at = orm.Optional(datetime.datetime, default=datetime.datetime.utcnow)
        operations = orm.Set(lambda: TorrentTagOp)
    class Torrent(db.Entity):
        id = orm.PrimaryKey(int, auto=True)
        infohash = orm.Required(bytes, unique=True)
        tags = orm.Set(lambda: TorrentTag)
    class TorrentTag(db.Entity):
        id = orm.PrimaryKey(int, auto=True)
        torrent = orm.Required(lambda: Torrent)
        tag = orm.Required(lambda: Tag)
        operations = orm.Set(lambda: TorrentTagOp)
        added_count = orm.Required(int, default=0)
        removed_count = orm.Required(int, default=0)
        local_operation = orm.Optional(int)  # in case user don't (or do) want to see it locally
        orm.composite_key(torrent, tag)
        @property
        def score(self):
            return self.added_count - self.removed_count
        def update_counter(self, operation: int, increment: int = 1, is_local_peer: bool = False):
            """ Update TorrentTag's counter
            Args:
                operation: Tag operation
                increment:
                is_local_peer: The flag indicates whether do we performs operations from a local user or from
                    a remote user. In case of the local user, his operations will be considered as
                    authoritative for his (only) local Tribler instance.
            Returns:
            """
            if is_local_peer:
                self.local_operation = operation
            if operation == 1:
                self.added_count += increment
            if operation == 2:
                self.removed_count += increment
    class Tag(db.Entity):
        id = orm.PrimaryKey(int, auto=True)
        name = orm.Required(str, unique=True)
        torrents = orm.Set(lambda: TorrentTag)
    class TorrentTagOp(db.Entity):
        id = orm.PrimaryKey(int, auto=True)
        torrent_tag = orm.Required(lambda: TorrentTag)
        peer = orm.Required(lambda: Peer)
        operation = orm.Required(int)
        clock = orm.Required(int)
        signature = orm.Required(bytes)
        updated_at = orm.Required(datetime.datetime, default=datetime.datetime.utcnow)
        auto_generated = orm.Required(bool, default=False)
        orm.composite_key(torrent_tag, peer)