diff --git a/seeder-api/src/seeders/location-loader.js b/seeder-api/src/seeders/location-loader.js index dae0793..7346d38 100644 --- a/seeder-api/src/seeders/location-loader.js +++ b/seeder-api/src/seeders/location-loader.js @@ -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); }