كتابة ترحيلات آمنة
في هذا الدرس 4 موضوعات
هذا الدرس مخطط له. يعرض المخطط أدناه الموضوعات التي سيغطيها، ولم يُنشر الدرس الكامل بعد.
نص الدروس والتمارين باللغة الإنجليزية، بينما تبقى واجهة الموقع وعناوين الدروس بالعربية.
في هذا الدرس
write migrations that are forward-only and low risk.
الموضوعات المخطط لها
- Never edit an applied migration; fix mistakes with a new one.
- Forward-only: do not rely on "down" scripts; to undo, write a new forward migration.
- Add columns as nullable (or with a default), backfill, then add
not nullin a later step. - Keep each migration small and focused; one change per file.
- Test on a copy of real data before production; big changes (rename, drop) need care and are covered in MID-020.
تفاصيل المخطط المبدئي
عرض عملي
-- V2__add_sku.sql
alter table product add column sku text;
update product set sku = 'SKU-' || id where sku is null;
alter table product alter column sku set not null;
create unique index ux_product_sku on product(sku);اختبر فهمك
Your V2 has a typo and already ran. What do you do?
أظهر الإجابة
Write V3 to fix it; never edit V2.
التطبيق
طبّق هذا الدرس بمختبر الوحدة وتمارينها واختبارها.
تعليم الدرس كمكتمل اختياري ويمكنك التراجع عنه في أي وقت. يبقى تقدمك محفوظًا في هذا المتصفح.