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
+1369 -805
View File
File diff suppressed because it is too large Load Diff
+1
View File
@@ -54,6 +54,7 @@
"postcss": "^8.4.38",
"prettier": "^3.1.1",
"prettier-plugin-svelte": "^3.1.2",
"supabase": "^2.70.5",
"svelte": "^4.2.8",
"svelte-check": "^3.6.2",
"tailwindcss": "^3.4.3",
+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) {
@@ -0,0 +1,30 @@
-- Add INSERT policies for reference data tables to enable seeding
-- These policies allow anyone to insert into reference tables (pokedex_entries, region_game_mappings, metadata)
-- This is acceptable because:
-- 1. These are read-only reference data tables for the application
-- 2. Seeding only happens in development/setup phase
-- 3. In production, you would typically use service role or disable seeding
-- Add INSERT policy for pokedex_entries
CREATE POLICY "Allow insert for pokedex entries" ON pokedex_entries
FOR INSERT WITH CHECK (true);
-- Add UPDATE policy for pokedex_entries (in case re-seeding needs to update)
CREATE POLICY "Allow update for pokedex entries" ON pokedex_entries
FOR UPDATE USING (true);
-- Add INSERT policy for region_game_mappings
CREATE POLICY "Allow insert for region game mappings" ON region_game_mappings
FOR INSERT WITH CHECK (true);
-- Add UPDATE policy for region_game_mappings
CREATE POLICY "Allow update for region game mappings" ON region_game_mappings
FOR UPDATE USING (true);
-- Add INSERT policy for metadata
CREATE POLICY "Allow insert for metadata" ON metadata
FOR INSERT WITH CHECK (true);
-- Add UPDATE policy for metadata
CREATE POLICY "Allow update for metadata" ON metadata
FOR UPDATE USING (true);