Skip to content
This repository has been archived by the owner on Jul 9, 2019. It is now read-only.

Commit

Permalink
Port to sequelize 2.x.
Browse files Browse the repository at this point in the history
  • Loading branch information
xdarklight committed Apr 3, 2015
1 parent ca828df commit 11988c8
Show file tree
Hide file tree
Showing 12 changed files with 48 additions and 49 deletions.
16 changes: 8 additions & 8 deletions add-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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);
Expand Down Expand Up @@ -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));
});
}
Expand All @@ -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: [
{
Expand All @@ -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: [
Expand All @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions add-incremental.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
});
}
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion cm-update-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down
6 changes: 3 additions & 3 deletions disable-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
{
Expand All @@ -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));
});

Expand Down
36 changes: 18 additions & 18 deletions generate-website.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down Expand Up @@ -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: [
Expand All @@ -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';
Expand All @@ -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: [
Expand All @@ -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();

Expand Down Expand Up @@ -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);
Expand All @@ -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: [
{
Expand Down Expand Up @@ -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 = {
Expand Down
4 changes: 2 additions & 2 deletions get-sourcecode-timestamp.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
{
Expand All @@ -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());
}
Expand Down
4 changes: 2 additions & 2 deletions get-target-file-zipnames.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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);
Expand Down
7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 3 additions & 3 deletions result-converter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion website/templates/device.jade
Original file line number Diff line number Diff line change
Expand Up @@ -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)
- }
- }
Expand Down
4 changes: 2 additions & 2 deletions website/templates/romtable.jade
Original file line number Diff line number Diff line change
Expand Up @@ -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;
- }
Expand Down
2 changes: 1 addition & 1 deletion website/templates/romvariant.jade
Original file line number Diff line number Diff line change
Expand Up @@ -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)
- }
- }
Expand Down

0 comments on commit 11988c8

Please sign in to comment.