fix(seeder): add table name mapping for location data (regions→continents)
This commit is contained in:
parent
1018da8036
commit
54552b2dcd
1 changed files with 14 additions and 0 deletions
|
|
@ -9,6 +9,14 @@ import { fileURLToPath } from 'url';
|
||||||
const __dirname = dirname(fileURLToPath(import.meta.url));
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
||||||
const SQL_DIR = join(__dirname, '..', '..', 'sql');
|
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
|
* Execute a SQL file directly
|
||||||
*/
|
*/
|
||||||
|
|
@ -44,6 +52,12 @@ async function executeSqlFile(filename, tableName) {
|
||||||
.replace(/`/g, '"')
|
.replace(/`/g, '"')
|
||||||
.replace(/"emojiU"/g, 'emoji_u')
|
.replace(/"emojiU"/g, 'emoji_u')
|
||||||
.replace(/"wikiDataId"/g, 'wiki_data_id');
|
.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);
|
await pool.query(pgStmt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue