Skip to content

Instantly share code, notes, and snippets.

@ernado
Forked from 6/readme.md
Last active May 28, 2018 07:47
Show Gist options
  • Save ernado/5d19fac57d8ad404558492585bad39dd to your computer and use it in GitHub Desktop.
Save ernado/5d19fac57d8ad404558492585bad39dd to your computer and use it in GitHub Desktop.
Batch-update Heroku dataclip databases using js console in 2018

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_id for each databases

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

Replace 5c6f807a-e3bb-4f3e-8d46-f4da3ec9b35d with the heroku 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_id === "5c6f807a-e3bb-4f3e-8d46-f4da3ec9b35d";
  });
  console.log("Found this many dataclips: " + clips.length);
});

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

Replace 8df837a-b321-4f3e-8f56-fadab445b35d with the heroku ID of the new database.

var postData = JSON.stringify({
  heroku_id: "8df837a-b321-4f3e-8f56-fadab445b35"
});
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