const { Client } = require('pg');
require('dotenv').config({ path: '/root/miaojingAI/.env.local' });
const c = new Client({ connectionString: process.env.LOCAL_DB_URL });
(async () => {
  await c.connect();
  const queries = [
    ['profiles_count', 'select count(*)::int as n from profiles'],
    ['profiles', 'select id,email,nickname,role,membership_tier,is_active,created_at from profiles order by created_at desc limit 20'],
    ['jobs_count', 'select count(*)::int as n from generation_jobs'],
    ['jobs', 'select id,user_id,type,status,created_at from generation_jobs order by created_at desc limit 20'],
    ['jobs_join_profiles', `select j.id,j.user_id,p.email,p.nickname,p.role,j.type,j.status,j.created_at from generation_jobs j left join profiles p on p.id=j.user_id order by j.created_at desc limit 20`]
  ];
  for (const [name, sql] of queries) {
    const r = await c.query(sql);
    console.log('--- ' + name);
    console.table(r.rows);
  }
  await c.end();
})().catch(e => { console.error(e); process.exit(1); });
