feat(seeder): interleave users and companies before heavy city seeding
This commit is contained in:
parent
4b3eb2feee
commit
3ab04c5fd7
2 changed files with 51 additions and 8 deletions
|
|
@ -1,5 +1,5 @@
|
|||
import { pool, testConnection, closePool } from './db.js';
|
||||
import { seedLocationData, seedLocationDataLite } from './seeders/location-loader.js';
|
||||
import { seedBaseLocations, seedDetailedLocations, seedLocationDataLite } from './seeders/location-loader.js';
|
||||
import { seedUsers } from './seeders/users.js';
|
||||
import { seedCompanies } from './seeders/companies.js';
|
||||
import { seedJobs } from './seeders/jobs.js';
|
||||
|
|
@ -63,14 +63,23 @@ async function seedDatabase() {
|
|||
console.log('');
|
||||
|
||||
// Seed in order (respecting foreign key dependencies)
|
||||
// 1. Location data first (continents -> subregions -> countries -> states -> cities)
|
||||
console.time('🌍 Total Location Seeding');
|
||||
await seedLocationData();
|
||||
console.timeEnd('🌍 Total Location Seeding');
|
||||
// 1. Base Location data (Continents, Countries) - Fast & Required for Companies
|
||||
console.time('🌍 Base Location Seeding');
|
||||
await seedBaseLocations();
|
||||
console.timeEnd('🌍 Base Location Seeding');
|
||||
|
||||
// 2. Then companies (need countries)
|
||||
await seedCompanies();
|
||||
|
||||
// 3. Then users (need companies)
|
||||
await seedUsers();
|
||||
|
||||
// 4. Detailed Location data (States, Cities) - Heavy
|
||||
console.time('🌍 Detailed Location Seeding');
|
||||
await seedDetailedLocations();
|
||||
console.timeEnd('🌍 Detailed Location Seeding');
|
||||
|
||||
// 5. Jobs & Applications (need users & companies)
|
||||
await seedJobs();
|
||||
await seedAcmeCorp(); // 🏭 ACME Corp + 69 vagas hilariantes
|
||||
await seedWileECoyote(); // 🐺 Wile E. Coyote user
|
||||
|
|
|
|||
|
|
@ -456,9 +456,12 @@ async function executeGzippedSqlFile(filename, tableName) {
|
|||
/**
|
||||
* Seed all location data from SQL dumps
|
||||
*/
|
||||
export async function seedLocationData() {
|
||||
console.log('🌍 Seeding comprehensive location data...');
|
||||
console.log(' Source: GeoDB Cities (https://github.com/dr5hn/countries-states-cities-database)\n');
|
||||
/**
|
||||
* Seed base location data (Continents, Subregions, Countries)
|
||||
* This is fast and required for Company seeding
|
||||
*/
|
||||
export async function seedBaseLocations() {
|
||||
console.log('🌍 Seeding base location data (Continents -> Countries)...');
|
||||
|
||||
try {
|
||||
// 1. Continents (from regions.sql - 6 records)
|
||||
|
|
@ -479,6 +482,20 @@ export async function seedLocationData() {
|
|||
await executeSqlFile('countries.sql', 'countries');
|
||||
console.timeEnd(' ⏱️ Countries');
|
||||
|
||||
} catch (error) {
|
||||
console.error('❌ Base location seeding failed:', error.message);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Seed detailed location data (States, Cities)
|
||||
* This is slower/heavy and should be run after Users/Companies are ready
|
||||
*/
|
||||
export async function seedDetailedLocations() {
|
||||
console.log('🌍 Seeding detailed location data (States -> Cities)...');
|
||||
|
||||
try {
|
||||
// 4. States (~5400 records)
|
||||
console.log('4️⃣ Seeding States...');
|
||||
console.time(' ⏱️ States');
|
||||
|
|
@ -491,6 +508,23 @@ export async function seedLocationData() {
|
|||
await executeGzippedSqlFile('cities.sql.gz', 'cities');
|
||||
console.timeEnd(' ⏱️ Cities (Bulk Insert)');
|
||||
|
||||
} catch (error) {
|
||||
console.error('❌ Detailed location seeding failed:', error.message);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Seed all location data from SQL dumps (Legacy wrapper)
|
||||
*/
|
||||
export async function seedLocationData() {
|
||||
console.log('🌍 Seeding comprehensive location data...');
|
||||
console.log(' Source: GeoDB Cities (https://github.com/dr5hn/countries-states-cities-database)\n');
|
||||
|
||||
try {
|
||||
await seedBaseLocations();
|
||||
await seedDetailedLocations();
|
||||
|
||||
console.log('\n ✅ Location data seeding complete!');
|
||||
|
||||
// Print counts
|
||||
|
|
|
|||
Loading…
Reference in a new issue