0Pricing
Spring Boot 4 Complete Guide · Lezione

Migrazioni del database con Flyway

Gestisca le modifiche allo schema in modo sicuro e ripetibile tra gli ambienti usando migrazioni Flyway versionate in Spring Boot.

Migrazioni del database con Flyway è una lezione Spring Boot 4 Complete Guide gratuita su CoddyKit. Questa è la lezione 4 di 4. Puoi leggere la lezione completa qui gratuitamente — poi esercitati direttamente nel browser con un editor di codice integrato e un tutor IA disponibile 24/7. Fa parte del percorso di apprendimento Spring Boot 4 Complete Guide, e i tuoi progressi si sincronizzano tra il web e l'app CoddyKit. Il corso Spring Boot 4 Complete Guide include 4 lezioni in totale.

Parti di questa lezione non sono ancora state tradotte e vengono mostrate in inglese.

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.

Domande Frequenti

La lezione «Migrazioni del database con Flyway» è gratuita?

Sì — il testo completo di «Migrazioni del database con Flyway» è gratuito qui sul web. Per esercitarvi in modo interattivo (un editor di codice integrato e un tutor IA 24/7) e sbloccare il resto del corso Spring Boot 4 Complete Guide, passa a CoddyKit PRO. Il corso Spring Boot 4 Complete Guide include 4 lezioni in totale.

Cosa imparerò in «Migrazioni del database con Flyway»?

Gestisca le modifiche allo schema in modo sicuro e ripetibile tra gli ambienti usando migrazioni Flyway versionate in Spring Boot. Eserciti Spring Boot 4 Complete Guide con codice pratico che esegui direttamente nel browser, e un tutor IA 24/7 risponde alle tue domande mentre lavori sulla lezione.

Ho bisogno di esperienza per iniziare Spring Boot 4 Complete Guide?

Non è richiesta alcuna esperienza precedente. Spring Boot 4 Complete Guide su CoddyKit è strutturato per principianti e studenti avanzati, quindi puoi iniziare da qui o dall'inizio e procedere al tuo ritmo. Questa è la lezione 4 di 4.

Quanto tempo richiede la lezione «Migrazioni del database con Flyway»?

La maggior parte delle lezioni CoddyKit richiede circa 5–10 minuti. Ogni lezione è breve e interattiva, quindi fai progressi costanti e riprendi esattamente da dove hai lasciato su web e app.

Posso scrivere ed eseguire codice in questa lezione Spring Boot 4 Complete Guide?

Sì. Ogni lezione Spring Boot 4 Complete Guide include un editor di codice integrato, quindi scrivi ed esegui codice reale direttamente nel tuo browser e ricevi feedback istantaneo dall'IA — nessuna configurazione locale necessaria.

Tutte le lezioni di questo corso

  1. Repository Spring Data personalizzati
  2. Integrazione di database NoSQL
  3. Caching con Spring Cache
  4. Migrazioni del database con Flyway
← Torna a Spring Boot 4 Complete Guide