0Pricing
Spring Boot 4 Complete Guide · درس

ترحيل قواعد البيانات باستخدام Flyway

أديروا تغييرات المخطط بأمان وبصورة قابلة للتكرار عبر البيئات باستخدام عمليات ترحيل Flyway المُدارة بالإصدارات في Spring Boot.

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

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

The Problem with Manual Schema Changes

Editing the database by hand is error-prone and hard to reproduce across dev, test, and production. Migrations turn schema changes into versioned, repeatable scripts.

What Is Flyway?

Flyway is a migration tool that applies SQL scripts in order, tracking which have run in a history table so each runs exactly once.

Adding Flyway

Spring Boot auto-detects Flyway on the classpath and runs migrations at startup. Just add the dependency.

<dependency>
  <groupId>org.flywaydb</groupId>
  <artifactId>flyway-core</artifactId>
</dependency>

Migration File Naming

Versioned scripts follow the pattern V1__description.sql. The version number after V determines execution order.

  • V1__create_users.sql
  • V2__add_email_column.sql

Where Migrations Live

By default Flyway looks in src/main/resources/db/migration. Place your SQL files there and they are picked up automatically.

A First Migration

Your first script typically creates a table. Once applied, Flyway records it and never runs it again.

CREATE TABLE users (
  id BIGINT PRIMARY KEY,
  name VARCHAR(100) NOT NULL
);

The Schema History Table

Flyway maintains a flyway_schema_history table recording each applied version, its checksum, and timestamp. This is how it knows what is pending.

Never Edit Applied Migrations

Once a migration has run anywhere, treat it as immutable. Editing it changes the checksum and Flyway will fail validation. Always add a new migration instead.

ALTER TABLE users ADD COLUMN email VARCHAR(200);

Repeatable Migrations

Scripts prefixed with R__ instead of a version run whenever their content changes. They are ideal for views and stored procedures.

Flyway and JPA Together

Disable Hibernate's auto schema generation and let Flyway own the schema. This gives you a single, reliable source of truth for structure.

spring.jpa.hibernate.ddl-auto=validate

Benefits in CI/CD

Because migrations run automatically and deterministically, every environment converges to the same schema, making deployments predictable and rollbacks easier to reason about.

Quick Check

Test your understanding of Flyway migrations.

Recap

You learned to version schema changes with Flyway: naming conventions, the history table, immutability of applied scripts, repeatable migrations, and pairing Flyway with JPA validation for reliable deployments.

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

هل درس «ترحيل قواعد البيانات باستخدام Flyway» مجاني؟

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

ماذا ستتعلم في «ترحيل قواعد البيانات باستخدام Flyway»؟

أديروا تغييرات المخطط بأمان وبصورة قابلة للتكرار عبر البيئات باستخدام عمليات ترحيل Flyway المُدارة بالإصدارات في Spring Boot. تتمرن على Spring Boot 4 Complete Guide مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.

هل أحتاج إلى خبرة سابقة لأبدأ Spring Boot 4 Complete Guide؟

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

كم من الوقت يستغرق درس «ترحيل قواعد البيانات باستخدام Flyway»؟

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

هل يمكنني كتابة وتشغيل أكواد في درس Spring Boot 4 Complete Guide هذا؟

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

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

  1. مستودعات Spring Data مخصّصة
  2. دمج قواعد بيانات NoSQL
  3. التخزين المؤقت باستخدام Spring Cache
  4. ترحيل قواعد البيانات باستخدام Flyway
← العودة إلى Spring Boot 4 Complete Guide