Spring Boot 4 Complete Guide · レッスン

Flywayによるデータベースマイグレーション

バージョン管理されたFlywayマイグレーションをSpring Bootで使い、環境をまたぐスキーマ変更を安全かつ繰り返し適用する方法を学びます。

レッスン 4/413 ステップ

「Flywayによるデータベースマイグレーション」はCoddyKit上の無料Spring Boot 4 Complete Guideレッスンです。 これはレッスン4/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これは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.

無料で開始

AI チューターと学ぶ Java — 無料

ブラウザでリアルコードを書いて実行し、24/7 の AI チューターから瞬時にサポートを受け、ウェブまたはアプリで続きから学習できます。

コース
21
レッスン
84

よくある質問

「Flywayによるデータベースマイグレーション」レッスンは無料ですか?

はい。「Flywayによるデータベースマイグレーション」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Spring Boot 4 Complete Guideコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Spring Boot 4 Complete Guideコースには全4レッスンが含まれています。

「Flywayによるデータベースマイグレーション」で何を学びますか?

バージョン管理されたFlywayマイグレーションをSpring Bootで使い、環境をまたぐスキーマ変更を安全かつ繰り返し適用する方法を学びます。 ブラウザで直接実行するハンズオンコードでSpring Boot 4 Complete Guideを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。

Spring Boot 4 Complete Guideを始めるのに経験は必要ですか?

事前経験は必要ありません。CoddyKitのSpring Boot 4 Complete Guideは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン4/4です。

「Flywayによるデータベースマイグレーション」レッスンにはどのくらい時間がかかりますか?

ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。

このSpring Boot 4 Complete Guideレッスンでコードを書いて実行できますか?

はい。すべてのSpring Boot 4 Complete Guideレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。

このコースのすべてのレッスン

  1. カスタムSpring Dataリポジトリ
  2. NoSQLデータベースの統合
  3. Spring Cacheによるキャッシュ
  4. Flywayによるデータベースマイグレーション
← Spring Boot 4 Complete Guideに戻る