Skip to content

Instantly share code, notes, and snippets.

@mahemoff
Created August 26, 2011 22:44
Show Gist options
  • Save mahemoff/1174609 to your computer and use it in GitHub Desktop.
Save mahemoff/1174609 to your computer and use it in GitHub Desktop.
Cradle (CouchDB+Node) routine to prepare a new DB, destroying the old one if it already exists. Good for prepping a data dump.
data =
init: () ->
data.emptyDB "animals", () ->
console.log "ready"
# now populate your new DB
emptyDB: (name, done) ->
db = new(cradle.Connection)().database(name);
db.exists (err, exists) ->
if exists
db.destroy () ->
console.log "destroyed the old one"
db.create()
done
else
console.log "no old one found"
db.create()
done
data.init()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment