u
This commit is contained in:
52
check-image-rv.mjs
Normal file
52
check-image-rv.mjs
Normal file
@@ -0,0 +1,52 @@
|
||||
import sql from 'mssql';
|
||||
import 'dotenv/config';
|
||||
|
||||
const config = {
|
||||
server: process.env.MSSQL_SERVER || 'localhost',
|
||||
port: Number(process.env.MSSQL_PORT) || 1433,
|
||||
database: process.env.MSSQL_DATABASE || 'Mandant_3',
|
||||
user: process.env.MSSQL_USER,
|
||||
password: process.env.MSSQL_PASSWORD,
|
||||
options: {
|
||||
encrypt: process.env.MSSQL_ENCRYPT !== 'false',
|
||||
trustServerCertificate: process.env.MSSQL_TRUST_SERVER_CERTIFICATE !== 'false',
|
||||
},
|
||||
};
|
||||
|
||||
async function main() {
|
||||
try {
|
||||
const pool = await sql.connect(config);
|
||||
|
||||
const result = await pool.request().query(`
|
||||
SELECT
|
||||
a.kArtikel as id, a.cArtNr as sku,
|
||||
CONVERT(BIGINT, a.bRowversion) as articleRV,
|
||||
MAX(CONVERT(BIGINT, abp.bRowversion)) as maxImageRV,
|
||||
CASE
|
||||
WHEN MAX(CONVERT(BIGINT, abp.bRowversion)) IS NOT NULL
|
||||
AND MAX(CONVERT(BIGINT, abp.bRowversion)) > CONVERT(BIGINT, a.bRowversion)
|
||||
THEN MAX(CONVERT(BIGINT, abp.bRowversion))
|
||||
ELSE CONVERT(BIGINT, a.bRowversion)
|
||||
END as effectiveLastChanged
|
||||
FROM dbo.tArtikel a
|
||||
INNER JOIN dbo.tArtikelBeschreibung ab ON ab.kArtikel = a.kArtikel AND ab.kSprache = 1
|
||||
LEFT JOIN dbo.tArtikelbildPlattform abp ON abp.kArtikel = a.kArtikel AND abp.kShop = 1
|
||||
WHERE a.cAktiv = 'Y'
|
||||
GROUP BY a.kArtikel, a.cArtNr, a.bRowversion
|
||||
ORDER BY a.kArtikel
|
||||
`);
|
||||
|
||||
console.log('Product effective lastChanged (with image RV for shop 1):');
|
||||
for (const row of result.recordset) {
|
||||
const diff = row.maxImageRV && row.maxImageRV > row.articleRV ? ' (IMAGE RV HIGHER!)' : '';
|
||||
console.log(' ID: ' + row.id + ', SKU: ' + row.sku + ', articleRV: ' + row.articleRV + ', maxImageRV: ' + (row.maxImageRV || 'none') + ', effective: ' + row.effectiveLastChanged + diff);
|
||||
}
|
||||
|
||||
await pool.close();
|
||||
} catch (err) {
|
||||
console.error('Error:', err.message);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
main();
|
||||
Reference in New Issue
Block a user