fix(seeder): add table name mapping for location data (regions→continents)

This commit is contained in:
Tiago Yamamoto 2025-12-24 15:07:25 -03:00
parent 1018da8036
commit 54552b2dcd

View file

@ -9,6 +9,14 @@ import { fileURLToPath } from 'url';
const __dirname = dirname(fileURLToPath(import.meta.url));
const SQL_DIR = join(__dirname, '..', '..', 'sql');
/**
* Table name mapping from SQL dumps to our schema
*/
const TABLE_MAPPING = {
'public.regions': 'continents',
'regions': 'continents',
};
/**
* Execute a SQL file directly
*/
@ -44,6 +52,12 @@ async function executeSqlFile(filename, tableName) {
.replace(/`/g, '"')
.replace(/"emojiU"/g, 'emoji_u')
.replace(/"wikiDataId"/g, 'wiki_data_id');
// Apply table name mapping
for (const [oldName, newName] of Object.entries(TABLE_MAPPING)) {
pgStmt = pgStmt.replace(new RegExp(`INSERT INTO ${oldName}`, 'gi'), `INSERT INTO ${newName}`);
}
await pool.query(pgStmt);
}