feat: add core backend modules, inventory services, and patch scripts for AI Pharmacy API

This commit is contained in:
2026-09-15 11:15:15 +05:30
parent 22a03043ea
commit 1f9378d96c
41 changed files with 1413 additions and 130 deletions
+25
View File
@@ -0,0 +1,25 @@
import { pool } from '../src/db/pool';
async function cleanupDuplicates() {
console.log('Cleaning up duplicate tenant batches...');
// 1. Delete stock movements referencing duplicate user batches
await pool.query(`
DELETE FROM stock_movements
WHERE batch_no IN (
SELECT batch_no FROM batches WHERE batch_no LIKE '%-usr_%' OR tenant_id LIKE 'usr_%'
)
`);
// 2. Delete duplicate user batches
const res1 = await pool.query(`DELETE FROM batches WHERE batch_no LIKE '%-usr_%' OR tenant_id LIKE 'usr_%'`);
console.log('Deleted duplicate user batches count:', res1.rowCount);
// 3. Count remaining batches in DB
const countRes = await pool.query(`SELECT COUNT(*) FROM batches`);
console.log('Remaining total batches in DB:', countRes.rows[0].count);
await pool.end();
}
cleanupDuplicates().catch(console.error);