fix(seeder): use companies/users tables instead of core_* for jobs

- jobs.company_id is INT referencing companies.id (SERIAL)
- jobs.created_by is INT referencing users.id (SERIAL)
- Was incorrectly querying core_companies/core_users (UUID)
This commit is contained in:
Tiago Yamamoto 2025-12-24 10:55:05 -03:00
parent d2266eb0f9
commit af2719f2e6

View file

@ -55,28 +55,26 @@ function getRandomInt(min, max) {
export async function seedJobs() {
console.log('💼 Seeding jobs (25 per company)...');
// Get company IDs from core_companies (jobs.company_id references core_companies.id)
const companiesRes = await pool.query('SELECT id, name FROM core_companies ORDER BY name');
// Get company IDs from companies table (jobs.company_id references companies.id which is INT)
const companiesRes = await pool.query('SELECT id, name FROM companies ORDER BY name');
const companies = companiesRes.rows;
if (companies.length === 0) {
console.log(' ⚠️ No core_companies found. Please seed companies first.');
console.log(' ⚠️ No companies found. Please seed companies first.');
return;
}
// Get a user from core_users for created_by FK
const seedUserRes = await pool.query("SELECT id FROM core_users LIMIT 1");
// Get a user from users table for created_by FK (INT)
const seedUserRes = await pool.query("SELECT id FROM users LIMIT 1");
if (seedUserRes.rows.length === 0) {
console.log(' ⚠️ No core_users found. Creating a system user...');
const systemUserId = crypto.randomUUID();
console.log(' ⚠️ No users found. Creating a system user...');
await pool.query(`
INSERT INTO core_users (id, name, email, password_hash, status)
VALUES ($1, 'System Seeder', 'system@gohorsejobs.com', '$2b$10$placeholder', 'ACTIVE')
ON CONFLICT (id) DO NOTHING
`, [systemUserId]);
INSERT INTO users (name, email, password_hash, role, status)
VALUES ('System Seeder', 'system@gohorsejobs.com', '$2b$10$placeholder', 'admin', 'active')
ON CONFLICT DO NOTHING
`);
}
const userRes = await pool.query("SELECT id FROM core_users LIMIT 1");
const userRes = await pool.query("SELECT id FROM users LIMIT 1");
const seedUserId = userRes.rows[0]?.id;
let totalJobs = 0;