30 lines
792 B
TypeScript
30 lines
792 B
TypeScript
import { pool } from '../src/db/pool';
|
|
|
|
async function updateManufacturers() {
|
|
const mfrs = [
|
|
'Cipla Ltd',
|
|
'Sun Pharma',
|
|
"Dr. Reddy's Laboratories",
|
|
'Lupin Ltd',
|
|
'Abbott Healthcare',
|
|
'Mankind Pharma',
|
|
'Alkem Laboratories',
|
|
'Torrent Pharma',
|
|
'Zydus Healthcare',
|
|
'GlaxoSmithKline'
|
|
];
|
|
|
|
const res = await pool.query('SELECT id FROM products');
|
|
console.log('Total products in DB:', res.rows.length);
|
|
|
|
for (let i = 0; i < res.rows.length; i++) {
|
|
const mfr = mfrs[i % mfrs.length];
|
|
await pool.query('UPDATE products SET manufacturer = $1 WHERE id = $2', [mfr, res.rows[i].id]);
|
|
}
|
|
|
|
console.log('Successfully updated manufacturer for all products in database!');
|
|
await pool.end();
|
|
}
|
|
|
|
updateManufacturers().catch(console.error);
|