✨ Update database queries
This commit is contained in:
parent
89faa530ec
commit
e9a58152d7
5 changed files with 28 additions and 56 deletions
|
@ -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;
|
|
|
@ -1,6 +1,5 @@
|
||||||
import { getSolidpkg, Product } from 'ssn';
|
import { getSolidpkg, Product } from 'ssn';
|
||||||
import products from './getConfig';
|
import IDatabaseRow from './interfaces/IDatabaseRow';
|
||||||
import IProductData from './interfaces/IProductData';
|
|
||||||
import * as model from './model/model';
|
import * as model from './model/model';
|
||||||
import * as database from './model/database';
|
import * as database from './model/database';
|
||||||
|
|
||||||
|
@ -8,12 +7,13 @@ import * as database from './model/database';
|
||||||
|
|
||||||
const newPatches: any[] = [];
|
const newPatches: any[] = [];
|
||||||
|
|
||||||
model.init().then(() => {
|
model.init().then(function(result: any) {
|
||||||
|
console.log(result);
|
||||||
database.exit();
|
database.exit();
|
||||||
});
|
});
|
||||||
|
|
||||||
/*//for each product, check new versions
|
/*//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;
|
const curVersion = 100;
|
||||||
//Check patch to next release
|
//Check patch to next release
|
||||||
for (let i = curVersion; i < curVersion + 3; i += 1) {
|
for (let i = curVersion; i < curVersion + 3; i += 1) {
|
||||||
|
|
10
src/interfaces/IDatabaseRow.ts
Normal file
10
src/interfaces/IDatabaseRow.ts
Normal 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;
|
||||||
|
}
|
|
@ -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;
|
|
||||||
}
|
|
|
@ -3,6 +3,9 @@ import * as database from './database';
|
||||||
import products from './products';
|
import products from './products';
|
||||||
import writeLog from '../logger/writeLog';
|
import writeLog from '../logger/writeLog';
|
||||||
import createStatement from './createStatement';
|
import createStatement from './createStatement';
|
||||||
|
import IDatabaseRow from '../interfaces/IDatabaseRow';
|
||||||
|
|
||||||
|
const state: any = {};
|
||||||
|
|
||||||
export async function init() {
|
export async function init() {
|
||||||
await database.init();
|
await database.init();
|
||||||
|
@ -11,29 +14,22 @@ export async function init() {
|
||||||
const createIfNotExists = createStatement.replace(/^CREATE TABLE/, 'CREATE TABLE IF NOT EXISTS');
|
const createIfNotExists = createStatement.replace(/^CREATE TABLE/, 'CREATE TABLE IF NOT EXISTS');
|
||||||
await database.query(createIfNotExists);
|
await database.query(createIfNotExists);
|
||||||
|
|
||||||
/**Products that are missing from the database and need to be inserted. */
|
const { results: existingRows }: { results: IDatabaseRow[]} = await database.query('SELECT * FROM ssn_versions');
|
||||||
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 } = await database.query('SELECT * FROM ssn_versions');
|
existingRows.forEach(function(row: IDatabaseRow) {
|
||||||
console.log(existingRows);
|
if (!products.includes(row.product)) {
|
||||||
return;
|
writeLog(`Product ${row.product} in database table is invalid.`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
existingRows.forEach((row: any) => {
|
state[row.product] = { http: row.http, manifest: row.manifest };
|
||||||
//TODO: match with products
|
|
||||||
});
|
});
|
||||||
|
|
||||||
//If row does not exist, INSERT into table
|
//If row does not exist, INSERT into table
|
||||||
await Promise.all(missingProducts.map((product) => {
|
await Promise.all(products.filter((product) => state[product] === undefined).map(function(product) {
|
||||||
return database.query(`INSERT INTO ssn_versions ${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
|
return state;
|
||||||
erroneousProducts.forEach((product) => {
|
|
||||||
writeLog(`Product ${product} in database table is invalid.`);
|
|
||||||
});
|
|
||||||
|
|
||||||
//TODO: insert products
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue