feat(#69): Improve seeding process

This commit is contained in:
Josh Creek
2026-01-02 20:17:13 +00:00
parent 073ba77dee
commit 2f5c0d68be
4 changed files with 1408 additions and 814 deletions
+8 -9
View File
@@ -14,16 +14,16 @@ export const GET = async () => {
try {
// Seed Pokédex entries
const { data: existingEntries, error: countError } = await supabase
const { count: entriesCount, error: countError } = await supabase
.from('pokedex_entries')
.select('id', { count: 'exact', head: true });
.select('*', { count: 'exact', head: true });
if (countError) {
throw new Error(`Failed to check existing entries: ${countError.message}`);
}
// Only seed if table is empty
if (!existingEntries || existingEntries.length === 0) {
if (!entriesCount || entriesCount === 0) {
console.log('Seeding Pokédex entries...');
// Transform data to match database schema
@@ -57,11 +57,11 @@ export const GET = async () => {
}
// Seed region-game mappings (check if table exists first)
const { data: existingMappings, error: mappingCountError } = await supabase
const { count: mappingsCount, error: mappingCountError } = await supabase
.from('region_game_mappings')
.select('id', { count: 'exact', head: true });
.select('*', { count: 'exact', head: true });
if (!mappingCountError && (!existingMappings || existingMappings.length === 0)) {
if (!mappingCountError && (!mappingsCount || mappingsCount === 0)) {
console.log('Seeding region-game mappings...');
const { error: mappingInsertError } = await supabase
@@ -80,9 +80,8 @@ export const GET = async () => {
return json({
message: 'Seeding completed successfully',
seeded: {
pokemonEntries: !existingEntries || existingEntries.length === 0,
regionGameMappings:
!mappingCountError && (!existingMappings || existingMappings.length === 0)
pokemonEntries: !entriesCount || entriesCount === 0,
regionGameMappings: !mappingCountError && (!mappingsCount || mappingsCount === 0)
}
});
} catch (error) {