Database Migration
ترحيل قاعدة البيانات
Definition
A controlled, documented change to a database's structure or data — adding a field, renaming a collection, or backfilling existing documents with new values.
تغيير مُتحكَّم فيه وموثَّق لبنية قاعدة البيانات أو بياناتها — إضافة حقل أو إعادة تسمية مجموعة أو ملء المستندات الموجودة بقيم جديدة مسبقاً.
Why It Matters
404Fault has 155+ glossary terms without `createdByUid` or `ownershipType` fields. Adding these fields requires a backfill migration that reads all glossary documents, determines which were admin-created (all of them), and writes the attribution fields. Without this migration, the profile attribution fix cannot work.
لدى 404Fault 155+ مصطلح قاموس بدون حقول `createdByUid` أو `ownershipType`. إضافة هذه الحقول يتطلب ترحيل ملء مسبق يقرأ جميع مستندات القاموس ويُحدّد أيها أنشأه المسؤول (جميعها) ويكتب حقول النسب. بدون هذا الترحيل، لا يمكن عمل إصلاح نسب الملف الشخصي.
Full Definition
Example Usage
“Admin backfill migration pattern: `async function backfillAttributionFields() { const snap = await db.collection('glossary').get(); const batch = db.batch(); snap.docs.forEach(doc => { if (!doc.data().createdByUid) { batch.update(doc.ref, { createdByUid: ADMIN_UID, ownershipType: 'platform', createdVia: 'seed' }); } }); await batch.commit(); console.log('Backfilled', snap.size, 'documents'); }` — idempotent: skips docs that already have the field.”
“نمط ترحيل الملء المسبق للمسؤول: `async function backfillAttributionFields() { const snap = await db.collection('glossary').get(); const batch = db.batch(); snap.docs.forEach(doc => { if (!doc.data().createdByUid) { batch.update(doc.ref, { createdByUid: ADMIN_UID, ownershipType: 'platform', createdVia: 'seed' }); } }); await batch.commit(); console.log('Backfilled', snap.size, 'documents'); }` — متعدد: يتخطى المستندات التي تمتلك الحقل بالفعل.”
AI Builder Tips
Avoid these mistakes when using Database Migration:
Not making migrations idempotent — if a migration fails halfway and must be re-run, it must be safe to run again without duplicating data
Running migrations during peak traffic — large Firestore batch operations consume write capacity; run migrations during low-traffic windows
Not testing migrations on a copy of production data first — migrations that look correct in dev can have edge cases with real production data
Sign in to unlock guided AI explanations from AI Teacher.
Generate a Prompt
Copy this prompt and use it directly with any AI model — no setup needed.
Help me build a project using Database Migration. Explain: 1. What is Database Migration and why it matters 2. The core architecture and required tools 3. Step-by-step implementation plan 4. Common mistakes to avoid: Not making migrations idempotent — if a migration fails halfway and must be re-run, it must be safe to run again without duplicating data, Running migrations during peak traffic — large Firestore batch operations consume write capacity; run migrations during low-traffic windows, Not testing migrations on a copy of production data first — migrations that look correct in dev can have edge cases with real production data 5. Best practices and production tips