0Pricing
Flask Academy · درس

مراجعة البرامج النصية المُنشأة وتحريرها

أصلح عمليات الترحيل المُنشأة تلقائيًا قبل تطبيقها.

مراجعة البرامج النصية المُنشأة وتحريرها درس مجاني في Flask Academy على CoddyKit. هذا هو الدرس 4 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في Flask Academy، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة Flask Academy 4 دروس في المجموع.

بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.

Autogenerate Is Not Perfect

Autogenerate is a great first draft, not a final answer. Always review the script before you apply it anywhere. 🔍

Open the Versions File

Each script lives in the versions folder. Open it and read the upgrade and downgrade functions like any other code.

The op Object

Inside the functions you will see calls on the op object, like op.create_table and op.add_column, each describing one schema change.

op.add_column("user", sa.Column("age", sa.Integer()))

What Alembic Misses

Autogenerate often misses renames, seeing them as a drop plus an add. That would silently delete the column data.

Fix Renames by Hand

When a column is really being renamed, replace the drop and add with a single alter_column that preserves the data.

op.alter_column("user", "name", new_column_name="full_name")

Check the downgrade

Confirm the downgrade truly reverses the upgrade. A broken downgrade leaves you stuck if you ever need to roll back.

Watch NOT NULL Columns

Adding a non-nullable column to a table with rows will fail. Add it nullable first, fill values, then make it required.

Add Data Steps Yourself

Need to backfill values? Add an op.execute call with raw SQL between the schema steps to migrate existing data safely.

op.execute("UPDATE user SET age = 0")

Test on a Copy First

Before touching production, run the migration on a copy of real data. It surfaces failures while they are still cheap to fix.

One Change per Migration

Keep each migration focused on one logical change. Small scripts are far easier to review, test, and roll back cleanly.

Commit the Final Script

Once edited and tested, commit the script. Never change a migration that has already shipped to production history.

Quick Check

You renamed a column, but autogenerate wrote a drop and an add. What is the danger?

Recap

You learned to review generated scripts, fix renames with alter_column, handle non-null columns, and test before shipping. 🎉

الأسئلة الشائعة

هل درس «مراجعة البرامج النصية المُنشأة وتحريرها» مجاني؟

نعم — نص درس «مراجعة البرامج النصية المُنشأة وتحريرها» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة Flask Academy، انتقل إلى CoddyKit PRO. تتضمن دورة Flask Academy 4 دروس في المجموع.

ماذا ستتعلم في «مراجعة البرامج النصية المُنشأة وتحريرها»؟

أصلح عمليات الترحيل المُنشأة تلقائيًا قبل تطبيقها. تتمرن على Flask Academy مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.

هل أحتاج إلى خبرة سابقة لأبدأ Flask Academy؟

لا تُشترط خبرة سابقة. Flask Academy على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 4 من أصل 4.

كم من الوقت يستغرق درس «مراجعة البرامج النصية المُنشأة وتحريرها»؟

معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.

هل يمكنني كتابة وتشغيل أكواد في درس Flask Academy هذا؟

نعم. كل درس في Flask Academy يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.

جميع الدروس في هذه الدورة

  1. لماذا تحتاج إلى عمليات الترحيل بدلًا من create_all
  2. تهيئة عملية ترحيل وإنشاؤها تلقائيًا
  3. تطبيق الترحيل والتراجع عنه باستخدام upgrade
  4. مراجعة البرامج النصية المُنشأة وتحريرها
← العودة إلى Flask Academy