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