Permalink
Browse files

Port to sequelize 2.x.

  • Loading branch information...
1 parent ca828df commit 11988c8a11b63210e0bb04cf1b30e9ceabb7deae @xdarklight committed Apr 3, 2015
View
@@ -36,7 +36,7 @@ var validateUniqueActiveRomPerSubdirectory = function(romVariant, parentRomId, s
}
}
]
- }).success(function(totalExisting) {
+ }).then(function(totalExisting) {
if (totalExisting > 0) {
throw new Error('There are already ' + totalExisting + ' active ROMs for ' + JSON.stringify(romVariant) + ' with filename ' + buildInfo.filename);
} else {
@@ -53,7 +53,7 @@ function createNewRomVariantFor(device) {
subdirectory: buildInfo.subdirectory,
});
- romVariant.save().success(function() {
+ romVariant.save().then(function() {
console.log('Successfully created new rom variant ' + JSON.stringify(romVariant));
validateUniqueActiveRomPerSubdirectory(romVariant, null, createNewRomFor);
@@ -98,7 +98,7 @@ function createNewRomFor(romVariant, parentRomId) {
parentRomId: parentRomId,
targetFilesZipName: buildInfo.targetfileszip,
fileSize: filesize,
- }).save().success(function(newRom) {
+ }).save().then(function(newRom) {
console.log('Successfully created new rom: ' + JSON.stringify(newRom));
});
}
@@ -109,7 +109,7 @@ if (buildInfo.changelogfile) {
changelog = fs.readFileSync(buildInfo.changelogfile, 'utf-8');
}
-models.sequelize.sync().success(function() {
+models.sequelize.sync().then(function() {
models.RomVariant.find({
include: [
{
@@ -123,7 +123,7 @@ models.sequelize.sync().success(function() {
where: {
subdirectory: buildInfo.subdirectory
}
- }).success(function(romVariant) {
+ }).then(function(romVariant) {
if (romVariant) {
models.Rom.find({
include: [
@@ -135,21 +135,21 @@ models.sequelize.sync().success(function() {
}
],
order: 'timestamp DESC'
- }).success(function(parentRom) {
+ }).then(function(parentRom) {
validateUniqueActiveRomPerSubdirectory(romVariant, parentRom.id, createNewRomFor);
});
} else {
models.Device.find({
where: {
name: buildInfo.device
}
- }).success(function(device) {
+ }).then(function(device) {
if (device) {
createNewRomVariantFor(device);
} else {
var device = models.Device.build({ name: buildInfo.device });
- device.save().success(function() {
+ device.save().then(function() {
console.log('Successfully created new device ' + JSON.stringify(device));
createNewRomVariantFor(device);
View
@@ -32,7 +32,7 @@ function createNewIncremental(sourceRom, targetRom) {
filename: buildInfo.filename,
isActive: buildInfo.active == true,
fileSize: filesize,
- }).save().success(function(newRom) {
+ }).save().then(function(newRom) {
console.log('Successfully created new incremental: ' + JSON.stringify(newRom));
});
}
@@ -54,10 +54,10 @@ var findRomWithTargetFilesZipName = function(targetFilesZipName, subdirectory) {
});
}
-models.sequelize.sync().success(function() {
- findRomWithTargetFilesZipName(buildInfo.from_target_files, buildInfo.subdirectory).success(function(sourceRom) {
+models.sequelize.sync().then(function() {
+ findRomWithTargetFilesZipName(buildInfo.from_target_files, buildInfo.subdirectory).then(function(sourceRom) {
if (sourceRom) {
- findRomWithTargetFilesZipName(buildInfo.to_target_files, buildInfo.subdirectory).success(function(targetRom) {
+ findRomWithTargetFilesZipName(buildInfo.to_target_files, buildInfo.subdirectory).then(function(targetRom) {
if (targetRom) {
createNewIncremental(sourceRom, targetRom);
} else {
View
@@ -25,7 +25,7 @@ var extractRequestParameters = function(req) {
return requestParameters;
}
-models.sequelize.sync().success(function() {
+models.sequelize.sync().then(function() {
server.listen(serverConfig.listeningPort, serverConfig.listeningAddress, function () {
console.log('%s listening at %s', server.name, server.url);
});
View
@@ -9,7 +9,7 @@ var buildInfo = (new Troll()).options(function(troll) {
troll.opt('disable_incrementals', 'Disables the incrementals for this rom also.', { type: 'boolean' });
});
-models.sequelize.sync().success(function() {
+models.sequelize.sync().then(function() {
models.Rom.findAll({
include: [
{
@@ -33,10 +33,10 @@ models.sequelize.sync().success(function() {
filename: buildInfo.filename,
isActive: true,
}
- }).success(function(roms) {
+ }).then(function(roms) {
roms.forEach(function (rom) {
rom.isActive = false;
- rom.save().success(function() {
+ rom.save().then(function() {
console.log('Disabled ROM: ' + JSON.stringify(rom));
});
View
@@ -6,7 +6,7 @@ var config = require('config').Website;
var models = require('./models/');
var ResultConverter = require('./result-converter.js');
-models.sequelize.sync().success(function() {
+models.sequelize.sync().then(function() {
var Directories = {
deviceJsonPath: path.join(config.contents, 'devices'),
@@ -39,7 +39,7 @@ models.sequelize.sync().success(function() {
function(parallelCallback) {
models.Device.findAll({
order: 'name ASC'
- }).success(function(devices) {
+ }).then(function(devices) {
async.each(devices, function(device, eachCallback) {
models.Rom.count({
include: [
@@ -58,7 +58,7 @@ models.sequelize.sync().success(function() {
where: {
isActive: true,
},
- }).success(function(romCount) {
+ }).then(function(romCount) {
if (romCount > 0) {
var deviceValues = device.toJSON();
deviceValues.template = 'device.jade';
@@ -76,7 +76,7 @@ models.sequelize.sync().success(function() {
function(parallelCallback) {
models.RomVariant.findAll({
order: 'displayName ASC, name ASC'
- }).success(function(romVariants) {
+ }).then(function(romVariants) {
async.each(romVariants, function(romVariant, eachCallback) {
models.Rom.count({
include: [
@@ -90,7 +90,7 @@ models.sequelize.sync().success(function() {
where: {
isActive: true,
},
- }).success(function(romCount) {
+ }).then(function(romCount) {
if (romCount > 0) {
var romVariantValues = romVariant.toJSON();
@@ -121,8 +121,8 @@ models.sequelize.sync().success(function() {
where: {
isActive: true,
},
- order: 'createdAt DESC',
- }).success(function(roms) {
+ order: [ [ 'createdAt', 'DESC' ] ],
+ }).then(function(roms) {
async.each(roms, function(rom, eachCallback) {
var romValues = { rom: rom.toJSON() };
romValues.downloadUrl = ResultConverter.getRomDownloadUrl(rom);
@@ -146,8 +146,8 @@ models.sequelize.sync().success(function() {
models.Download.findAll({
attributes: [
- [ models.sequelize.fn('strftime', '%Y-%m-%d', models.sequelize.col('Downloads.createdAt')), 'downloadDate' ],
- [ models.sequelize.fn('COUNT', 'Downloads.id'), 'downloadCount' ],
+ [ models.sequelize.fn('strftime', '%Y-%m-%d', models.sequelize.col('Download.createdAt')), 'downloadDate' ],
+ [ models.sequelize.fn('COUNT', 'Download.id'), 'downloadCount' ],
],
include: [
{
@@ -181,22 +181,22 @@ models.sequelize.sync().success(function() {
}
],
group: [
- models.sequelize.fn('strftime', '"%Y-%m-%d"', models.sequelize.col('Downloads.createdAt')),
- 'Downloads.RomId',
- 'Downloads.IncrementalId',
+ models.sequelize.fn('strftime', '"%Y-%m-%d"', models.sequelize.col('Download.createdAt')),
+ 'Download.RomId',
+ 'Download.IncrementalId',
]
- }).success(function(allDownloads) {
+ }).then(function(allDownloads) {
async.map(allDownloads, function(download, mapCallback) {
var incrementalId = null;
var romId = null;
var romVariantId = null;
- if (!!download.rom) {
- romId = download.rom.id;
- romVariantId = download.rom.romVariant.id;
+ if (!!download.Rom) {
+ romId = download.Rom.id;
+ romVariantId = download.Rom.RomVariant.id;
} else {
- incrementalId = download.incremental.id;
- romVariantId = download.incremental.romVariant.id;
+ incrementalId = download.Incremental.id;
+ romVariantId = download.Incremental.RomVariant.id;
}
var result = {
@@ -7,7 +7,7 @@ var buildInfo = (new Troll()).options(function(troll) {
troll.opt('subdirectory', 'The subdirectory from which the file can be downloaded.', { type: 'string' });
});
-models.sequelize.sync().success(function() {
+models.sequelize.sync().then(function() {
models.Rom.find({
include: [
{
@@ -27,7 +27,7 @@ models.sequelize.sync().success(function() {
}
],
order: 'timestamp DESC'
- }).success(function(rom) {
+ }).then(function(rom) {
if (rom && rom.sourceCodeTimestamp) {
console.log(rom.sourceCodeTimestamp.toISOString());
}
@@ -10,7 +10,7 @@ var buildInfo = (new Troll()).options(function(troll) {
var minDate = new Date(-8640000000000000);
-models.sequelize.sync().success(function() {
+models.sequelize.sync().then(function() {
var startTimestamp;
if (!buildInfo.max_age_days || isNaN(buildInfo.max_age_days)) {
@@ -46,7 +46,7 @@ models.sequelize.sync().success(function() {
ne: null,
},
},
- }).success(function(roms) {
+ }).then(function(roms) {
roms.forEach(function(rom) {
if (rom.targetFilesZipName.length > 0) {
console.log(rom.targetFilesZipName);
View
@@ -14,15 +14,14 @@
"dependencies": {
"troll-opt" : ">= 0.7.x",
"config": ">= 0.4.x",
- "restify": ">= 2.8.x",
- "sequelize": ">= 1.7.1"
+ "restify": ">= 3.0.x",
+ "sequelize": ">= 2.0.5"
},
"optionalDependencies": {
- "sqlite3": ">= 2.2.x",
+ "sqlite3": ">= 3.0.5",
"mysql": ">= 2.x",
"mariasql": ">= 0.1.x",
- "pg": ">= 3.4.x",
"wintersmith": ">= 2.1.x",
"fs-extra": ">= 0.10.0",
"filesize": ">= 2.0.0",
View
@@ -66,8 +66,8 @@ module.exports.convertIncremental = function(incremental) {
module.exports.getRealDownloadUrl = function(baseUrl, updateItem) {
var url = baseUrl;
- if (updateItem.romVariant.subdirectory && updateItem.romVariant.subdirectory.length > 0) {
- url += '/' + updateItem.romVariant.subdirectory;
+ if (updateItem.RomVariant.subdirectory && updateItem.RomVariant.subdirectory.length > 0) {
+ url += '/' + updateItem.RomVariant.subdirectory;
}
url += '/' + updateItem.filename;
@@ -79,7 +79,7 @@ module.exports.getProxyDownloadUrl = function(baseUrl, updateItem) {
var url = baseUrl;
url += '/' + updateItem.id;
- url += '?' + querystring.stringify({ directory: updateItem.romVariant.subdirectory, filename: updateItem.filename });
+ url += '?' + querystring.stringify({ directory: updateItem.RomVariant.subdirectory, filename: updateItem.filename });
return url;
}
@@ -6,7 +6,7 @@ block append vars
- var romsForCurrentDevice = []
- for (var i in contents.roms) {
- var romMetadata = contents.roms[i].metadata
- - if (romMetadata.rom.romVariant.device.id == page.metadata.id) {
+ - if (romMetadata.rom.RomVariant.Device.id == page.metadata.id) {
- romsForCurrentDevice.push(romMetadata)
- }
- }
@@ -19,14 +19,14 @@ mixin romtable(romMetadataArray)
- var rom = romMetadata.rom
- var deviceArticle = null
- for (i in contents.devices) {
- - if (contents.devices[i].metadata.id == rom.romVariant.device.id) {
+ - if (contents.devices[i].metadata.id == rom.RomVariant.Device.id) {
- deviceArticle = contents.devices[i]
- break;
- }
- }
- var romVariantArticle = null
- for (i in contents.romvariants) {
- - if (contents.romvariants[i].metadata.id == rom.romVariant.id) {
+ - if (contents.romvariants[i].metadata.id == rom.RomVariant.id) {
- romVariantArticle = contents.romvariants[i]
- break;
- }
@@ -6,7 +6,7 @@ block append vars
- var romsForCurrentVariant = []
- for (var i in contents.roms) {
- var romMetadata = contents.roms[i].metadata
- - if (romMetadata.rom.romVariant.id == page.metadata.id) {
+ - if (romMetadata.rom.RomVariant.id == page.metadata.id) {
- romsForCurrentVariant.push(romMetadata)
- }
- }

0 comments on commit 11988c8

Please sign in to comment.