mirror of
https://github.com/jcreek/LivingDexTracker.git
synced 2026-07-13 02:53:45 +00:00
feat(#69): Improve seeding process
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user