Update database queries

This commit is contained in:
C-3PO 2018-11-09 01:09:45 +01:00
parent 89faa530ec
commit e9a58152d7
Signed by: c3po
GPG key ID: 62993C4BB4D86F24
5 changed files with 28 additions and 56 deletions

View file

@ -1,28 +0,0 @@
import { Product } from 'ssn';
import IProductData from './interfaces/IProductData';
const data: { [key in Product]: IProductData } = {
assets_swtor_main: { manifestVersion: 294, httpVersion: 294 },
assets_swtor_de_de: { manifestVersion: 297, httpVersion: 297 },
assets_swtor_en_us: { manifestVersion: 299, httpVersion: 299 },
assets_swtor_fr_fr: { manifestVersion: 299, httpVersion: 299 },
assets_swtor_test_main: { manifestVersion: 292, httpVersion: 292 },
assets_swtor_test_de_de: { manifestVersion: 295, httpVersion: 295 },
assets_swtor_test_en_us: { manifestVersion: 295, httpVersion: 295 },
assets_swtor_test_fr_fr: { manifestVersion: 295, httpVersion: 295 },
retailclient_swtor: { manifestVersion: 247, httpVersion: 247 },
retailclient_publictest: { manifestVersion: 269, httpVersion: 269 },
retailclient_betatest: { manifestVersion: 13, httpVersion: 13 },
retailclient_liveqatest: { manifestVersion: 203, httpVersion: 205 },
retailclient_liveeptest: { manifestVersion: 133, httpVersion: 199 },
retailclient_cstraining: { manifestVersion: 141, httpVersion: 141 },
retailclient_squadron157: { manifestVersion: 11, httpVersion: -1 },
eualas: { manifestVersion: 0, httpVersion: 0 },
patcher2014: { manifestVersion: 8, httpVersion: 7 },
patcher2017: { manifestVersion: 0, httpVersion: 0 },
movies_de_de: { manifestVersion: 5, httpVersion: 5 },
movies_en_us: { manifestVersion: 5, httpVersion: 5 },
movies_fr_fr: { manifestVersion: 5, httpVersion: 5 },
};
export default data;

View file

@ -1,6 +1,5 @@
import { getSolidpkg, Product } from 'ssn';
import products from './getConfig';
import IProductData from './interfaces/IProductData';
import IDatabaseRow from './interfaces/IDatabaseRow';
import * as model from './model/model';
import * as database from './model/database';
@ -8,12 +7,13 @@ import * as database from './model/database';
const newPatches: any[] = [];
model.init().then(() => {
model.init().then(function(result: any) {
console.log(result);
database.exit();
});
/*//for each product, check new versions
Object.entries(products).forEach(([product, { manifestVersion, httpVersion }]: [string, IProductData]) => {
Object.entries(products).forEach(([product, { manifestVersion, httpVersion }]: [string, IDatabaseRow]) => {
const curVersion = 100;
//Check patch to next release
for (let i = curVersion; i < curVersion + 3; i += 1) {

View file

@ -0,0 +1,10 @@
import { Product } from "ssn";
export default interface IDatabaseRow {
/** Name of the product. */
product: Product;
/** Latest release number of this product according to the manifest. */
manifest: number;
/** Latest release number of this product available from the patch server. */
http: number;
}

View file

@ -1,6 +0,0 @@
export default interface IProductData {
/** Latest release number of this product according to manifest. */
manifestVersion: number;
/** Latest release number of this product available from the patch server. */
httpVersion: number;
}

View file

@ -3,6 +3,9 @@ import * as database from './database';
import products from './products';
import writeLog from '../logger/writeLog';
import createStatement from './createStatement';
import IDatabaseRow from '../interfaces/IDatabaseRow';
const state: any = {};
export async function init() {
await database.init();
@ -11,29 +14,22 @@ export async function init() {
const createIfNotExists = createStatement.replace(/^CREATE TABLE/, 'CREATE TABLE IF NOT EXISTS');
await database.query(createIfNotExists);
/**Products that are missing from the database and need to be inserted. */
const missingProducts: Product[] = [];
/** Products inside the database table that are not valid products. Will be printed to error log and ignored */
const erroneousProducts: Product[] = [];
const { results: existingRows }: { results: IDatabaseRow[]} = await database.query('SELECT * FROM ssn_versions');
const { results: existingRows } = await database.query('SELECT * FROM ssn_versions');
console.log(existingRows);
return;
existingRows.forEach(function(row: IDatabaseRow) {
if (!products.includes(row.product)) {
writeLog(`Product ${row.product} in database table is invalid.`);
return;
}
existingRows.forEach((row: any) => {
//TODO: match with products
state[row.product] = { http: row.http, manifest: row.manifest };
});
//If row does not exist, INSERT into table
await Promise.all(missingProducts.map((product) => {
return database.query(`INSERT INTO ssn_versions ${product}`);
await Promise.all(products.filter((product) => state[product] === undefined).map(function(product) {
state[product] = { http: -1, manifest: -1 };
return database.query(`INSERT INTO \`ssn_versions\` (\`product\`, \`manifest\`, \`http\`) VALUES ('${product.replace(/'/g, '\\\'')}', '-1', '-1');`)
}));
//If row exists that is not in products, ignore it and output error
erroneousProducts.forEach((product) => {
writeLog(`Product ${product} in database table is invalid.`);
});
//TODO: insert products
return state;
}