Fix Bug 918952 - Add makeid to Goggles project model #28
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Add the makeid column to the butter database | ||
ALTER TABLE ThimbleProjects ADD COLUMN makeid CHAR(40); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add Add a second line to the migration script: This will make sure we don't have two projects pointing at the same makeid. This will not conflict with the default value of NULL because NULL != NULL, oddly enough. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are you sure? Sounds like mongo is wrong then if with SQL NULL != NULL There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, in javascript |
||
ALTER TABLE ThimbleProjects ADD UNIQUE KEY(makeid); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/** | ||
* This Script is designed to upgrade existing thimble projects | ||
* that are already in the MakeAPI. It will grab each makes id | ||
* and find it's corresponding Thimble project and update it | ||
* with that makes id. | ||
**/ | ||
|
||
var async = require( "async" ), | ||
habitat = require( "habitat" ), | ||
env; | ||
|
||
habitat.load(); | ||
env = new habitat(); | ||
|
||
// Database information | ||
var dbConfig = env.get( "DB" ), | ||
db = require( "../lib/database" ), | ||
dbAPI = db( "ThimbleProject", dbConfig ), | ||
makeEnv = env.get( "make" ), | ||
makeapi, | ||
utils = require( "../lib/utils" ), | ||
page = 1, | ||
LIMIT = 1000, | ||
completed, | ||
q; | ||
|
||
makeapi = require( "makeapi-client" )({ | ||
apiURL: makeEnv.endpoint, | ||
hawk: { | ||
key: makeEnv.privatekey, | ||
id: makeEnv.publickey, | ||
algorithm: "sha256" | ||
} | ||
}); | ||
|
||
function processGogglesMake( make, asyncCallback ) { | ||
dbAPI.model.find({ where: { | ||
title: utils.slugify( make.title ), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One thing I was thinking here; if we have the url, do we need to search by title? |
||
url: make.url, | ||
makeid: null | ||
}}) | ||
.error( asyncCallback ) | ||
.success(function( project ) { | ||
if ( project && !project.makeid ) { | ||
project.updateAttributes({ | ||
makeid: make.id | ||
}) | ||
.error( asyncCallback ) | ||
.success(function( updatedProject ) { | ||
asyncCallback( null, updatedProject ); | ||
}); | ||
} else { | ||
asyncCallback( null, project ); | ||
} | ||
}); | ||
} | ||
|
||
function getMakes( page ) { | ||
makeapi | ||
.contentType( "application/x-x-ray-goggles" ) | ||
.page( page ) | ||
.limit( LIMIT ) | ||
.then(function( err, results, count ) { | ||
if ( err ) { | ||
console.log( "Something went horribly wrong: " + err.toString() ); | ||
return process.exit( 1 ); | ||
} | ||
|
||
completed += results.length; | ||
q.push( results, function( error ) { | ||
if ( error ) { | ||
console.log( "Something went horribly wrong: " + error.toString() ); | ||
return process.exit( 1 ); | ||
} | ||
|
||
if ( completed < count ) { | ||
page++; | ||
getMakes( page ); | ||
} | ||
}); | ||
}); | ||
} | ||
|
||
q = async.queue( processGogglesMake, 5 ); | ||
|
||
q.drain = function() { | ||
console.log( "Hooray! All of the goggles makes have been updated" ); | ||
}; | ||
|
||
getMakes( page ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
project
is not defined in this scope