com um clique
db-seed
Safely apply seed data to database with idempotent operations
Instalar com Codex ou Claude Copie este prompt, cole no Codex, Claude ou outro assistente e deixe que ele revise a página da skill e instale para você.
Menu
Safely apply seed data to database with idempotent operations
Instalar com Codex ou Claude Copie este prompt, cole no Codex, Claude ou outro assistente e deixe que ele revise a página da skill e instale para você.
Baseado na classificação ocupacional SOC
Execute story development with selectable automation modes to accommodate different developer preferences, skill levels, and story complexity.
Set up a Kord-aligned documentation baseline (no legacy frameworks)
Create Next Story Task methodology and workflow
Validate Next Story Task methodology and workflow
advanced-elicitation methodology and workflow
No checklists needed - this task facilitates brainstorming sessions, validation is through user interaction methodology and workflow
| name | db-seed |
| description | Safely apply seed data to database with idempotent operations |
| agent | architect |
| subtask | false |
Safely apply seed data to database with idempotent operations
Parameter:* mode (optional, default: interactive)
Purpose:* Definitive pass/fail criteria for task completion
Checklist:*
acceptance-criteria:
- [ ] Data persisted correctly; constraints respected; no orphaned data
type: acceptance-criterion
blocker: true
validation: |
Assert data persisted correctly; constraints respected; no orphaned data
error_message: "Acceptance criterion not met: Data persisted correctly; constraints respected; no orphaned data"
Strategy:* retry
Common Errors:*
Error:* Connection Failed
Error:* Query Syntax Error
Error:* Transaction Rollback
path (string): Path to SQL seed fileAsk user to confirm:
{path}$SUPABASE_DB_URL (redacted)CRITICAL*: Never seed production without explicit confirmation!
Check that seed file is idempotent:
echo "Validating seed file..."
# Check for dangerous patterns
if grep -qi "TRUNCATE\|DELETE FROM" {path}; then
echo "⚠️ WARNING: Seed contains TRUNCATE/DELETE"
echo " This is destructive. Continue? (yes/no)"
read CONFIRM
[ "$CONFIRM" != "yes" ] && { echo "Aborted"; exit 1; }
fi
# Check for INSERT...ON CONFLICT (idempotent pattern)
if ! grep -qi "ON CONFLICT" {path}; then
echo "⚠️ WARNING: No ON CONFLICT detected"
echo " Seed may not be idempotent. Continue? (yes/no)"
read CONFIRM
[ "$CONFIRM" != "yes" ] && { echo "Aborted"; exit 1; }
fi
echo "✓ Seed file validated"
TS=$(date +%Y%m%d%H%M%S)
mkdir -p supabase/snapshots
echo "Creating pre-seed snapshot..."
pg_dump "$SUPABASE_DB_URL" --schema-only --clean --if-exists \
> "supabase/snapshots/${TS}_before_seed.sql"
echo "✓ Snapshot: supabase/snapshots/${TS}_before_seed.sql"
Run seed in transaction with error handling:
echo "Applying seed data..."
psql "$SUPABASE_DB_URL" \
-v ON_ERROR_STOP=1 \
-f {path}
if [ $? -eq 0 ]; then
echo "✓ Seed data applied successfully"
else
echo "❌ Seed failed"
echo " Rollback snapshot: supabase/snapshots/${TS}_before_seed.sql"
exit 1
fi
Run basic verification:
echo "Verifying seed data..."
# Count inserted rows (example - customize per seed)
psql "$SUPABASE_DB_URL" -c \
"SELECT
'users' AS table, COUNT(*) AS rows FROM users
UNION ALL
SELECT
'categories', COUNT(*) FROM categories
ORDER BY table;"
echo "✓ Verification complete"
Log what was seeded:
cat >> supabase/docs/SEED_LOG.md << EOF
## Seed Applied: ${TS}
- File: {path}
- Date: $(date -u +"%Y-%m-%d %H:%M:%S UTC")
- Environment: ${ENVIRONMENT:-unknown}
- Applied by: ${USER:-unknown}
EOF
echo "✓ Logged to supabase/docs/SEED_LOG.md"
Display summary:
✅ SEED COMPLETE
File: {path}
Timestamp: {TS}
Snapshot: supabase/snapshots/{TS}_before_seed.sql
Log: supabase/docs/SEED_LOG.md
Next steps:
- Verify data manually in database
- Run smoke tests if appropriate
- Commit seed file to git
Best practice example for seed files:
-- ✅ GOOD: Idempotent seed
INSERT INTO categories (id, name, slug)
VALUES
('cat-1', 'Technology', 'technology'),
('cat-2', 'Design', 'design')
ON CONFLICT (id) DO UPDATE SET
name = EXCLUDED.name,
slug = EXCLUDED.slug;
-- ✅ GOOD: Conditional insert
INSERT INTO users (id, email, role)
SELECT 'user-1', 'admin@example.com', 'admin'
WHERE NOT EXISTS (
SELECT 1 FROM users WHERE email = 'admin@example.com'
);
-- ❌ BAD: Not idempotent
INSERT INTO categories (name, slug)
VALUES ('Technology', 'technology'); -- Will fail on retry
If seed fails:
rollback {TS}_before_seedseed {path}ON CONFLICT or INSERT...WHERE NOT EXISTS