Neon is now SOC 2 Type 2 compliant 🚀Read more
Guides/Schema migration/Flyway

Get started with Flyway and Neon

Learn how to manage schema changes in Neon with Flyway

Flyway is a database migration tool that facilitates version control for databases. It allows developers to manage and track changes to the database schema, ensuring that the database evolves consistently across different environments.

This guide steps you through installing the Flyway command-line tool, configuring Flyway to connect to a Neon database, and running database migrations. The guide follows the setup described in the Flyway command-line quickstart.

Prerequisites

Download and extract Flyway

  1. Download the latest version of the Flyway command-line tool.

  2. Extract the Flyway files. For example:

  3. Open a command prompt to view the contents of your Flyway installation:

Set your path variable

Add the Flyway directory to your PATH so that you can execute Flyway commands from any location.

bash
zsh

Retrieve your Neon database connection string

From the Neon Dashboard, retrieve your password and a Java connection string from the Connection Details widget.

Your Java connection string should look something like this:

Configure flyway

To configure Flyway to connect to your Neon database, create a flyway.conf file in the /conf directory. Include the following items, modified to use the connection details you retrieved in the previous step.

Create the first migration

Create an sql directory to hold your first migration file. We'll name the file V1__Create_person_table.sql and include the following command, which creates a person table in your database.

Migrate the database

Run the flyway migrate command to migrate your database:

If the command was successful, you’ll see output similar to the following:

To verify that the person table was created, you can view it on the Tables page in the Neon console. Select Tables from the sidebar and select your database.

Add a second migration

Run another migration to add data to the table. Add a second migration file to the /sql directory called V2__Add_people.sql and add the following statements:

Run the migration:

If the command was successful, you’ll see output similar to the following:

You can verify that the data was added by viewing the table on the Tables page in the Neon console. Select Tables from the sidebar and select your database.

View your schema migration history

When you run the flyway migrate command, Flyway registers the schema changes in the flyway_schema_history table, which Flyway automatically creates in your database. You can view the table by running the flyway info command.

You can also view the table on the Tables page in the Neon console. Select Tables from the sidebar and select your database.

Next steps

Learn how you can use Flyway with multiple database environments. See Use Flyway with multiple database environments.

References

Last updated on

Edit this page
Was this page helpful?