Files
cannaiq/backend/check-deeply-rooted.ts
2025-11-28 19:45:44 -07:00

75 lines
2.3 KiB
TypeScript

import pg from 'pg';
const { Pool } = pg;
const pool = new Pool({
connectionString: process.env.DATABASE_URL
});
async function check() {
try {
// Get dispensary info - try different column names
const dispensaryResult = await pool.query(
"SELECT * FROM dispensaries WHERE name ILIKE '%Deeply Rooted%' LIMIT 1"
);
if (dispensaryResult.rows.length === 0) {
console.log('Dispensary not found. Listing all dispensaries:');
const all = await pool.query("SELECT id, name FROM dispensaries LIMIT 10");
all.rows.forEach(d => console.log(` ID ${d.id}: ${d.name}`));
return;
}
const dispensary = dispensaryResult.rows[0];
console.log(`Dispensary: ${dispensary.name} (ID: ${dispensary.id})`);
console.log(`Columns:`, Object.keys(dispensary));
// Get product count
const productCountResult = await pool.query(
`SELECT COUNT(*) as total_products FROM products WHERE dispensary_id = $1`,
[dispensary.id]
);
console.log(`\nTotal products: ${productCountResult.rows[0].total_products}`);
// Get brand count and list
const brandCountResult = await pool.query(
`SELECT COUNT(DISTINCT brand) as brand_count
FROM products
WHERE dispensary_id = $1 AND brand IS NOT NULL AND brand != ''`,
[dispensary.id]
);
console.log(`Total distinct brands: ${brandCountResult.rows[0].brand_count}`);
// List all brands
const brandsResult = await pool.query(
`SELECT DISTINCT brand, COUNT(*) as product_count
FROM products
WHERE dispensary_id = $1 AND brand IS NOT NULL AND brand != ''
GROUP BY brand
ORDER BY product_count DESC`,
[dispensary.id]
);
console.log(`\nBrands with products:`);
brandsResult.rows.forEach(row => {
console.log(` - ${row.brand} (${row.product_count} products)`);
});
// Count products without brands
const noBrandResult = await pool.query(
`SELECT COUNT(*) as no_brand_count
FROM products
WHERE dispensary_id = $1 AND (brand IS NULL OR brand = '')`,
[dispensary.id]
);
console.log(`\nProducts without brand: ${noBrandResult.rows[0].no_brand_count}`);
} catch (error) {
console.error('Error:', error);
} finally {
await pool.end();
}
}
check();