Skip to content

Instantly share code, notes, and snippets.

@6
Last active May 28, 2018 07:45
Show Gist options
  • Select an option

  • Save 6/7ef16f61679b71efb270 to your computer and use it in GitHub Desktop.

Select an option

Save 6/7ef16f61679b71efb270 to your computer and use it in GitHub Desktop.
Batch-update Heroku dataclip databases using js console

If you have many dataclips pointing to a database, and upgrade that database to a different plan, those dataclips will continue pointing to the old database. This will show you how to update all of those dataclips to point to the new database.

Step 1. Log in to Heroku

Step 2. Find heroku_resource_id for each databases

Step 3. In JS console, get the list of dataclips to update

Replace [email protected] with the resource ID of the database you are moving away from.

var clips;
$.getJSON("https://dataclips.heroku.com/api/v1/clips", function(response) {
  clips = response.filter(function(clip) {
    return clip.heroku_resource_id === "[email protected]";
  });
  console.log("Found this many dataclips: " + clips.length);
});

Step 4. Update those dataclips to point to the new resource

Replace [email protected] with the resource ID of the new database.

var postData = JSON.stringify({
  heroku_resource_id: "[email protected]"
});
clips.forEach(function(clip) {
  var url = "https://dataclips.heroku.com/api/v1/clips/" + clip.slug + "/move";
  $.ajax({
    type: "POST",
    url: url,
    data: postData,
    success: function() {
      console.log("Migrated:" + clip.slug);
    }
  });
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment