Flyway

Quickstart - Flyway Desktop

This brief tutorial will teach you how to get up and running with Flyway Desktop. It will take you through the steps on how to configure it and how to write and execute your first few database migrations.

This tutorial should take you about 5 minutes to complete.

Note:  This Quickstart is using the Flyway Desktop GUI.  Everything below can also be accomplished directly with the Flyway command-line.  If you prefer command lines, please see this Quickstart Guide for the Flyway Command-line.  

Prerequisites

Install Flyway Desktop, which includes the Flyway CLI. 


Configure Flyway Desktop

  1. After installing, search for Flyway Desktop from the Start menu, which launches the following:


  2. Click on New Project...


  3. In the New project details dialog, specify the following:
    1. Project Name: Quickstart Flyway Desktop
    2. Project Location: select the location you want to save the project folder
    3. Create new project folder in this location: leave selected if you want to create a folder within the project location select above
    4. Database Engine: SQLite


  4. Click Create project at the bottom, which will bring you to the Migrations tab:


  5. Next, specify your target database that you want to work with.  Press Add target database on the right:


  6. Enter the following details in the connection form:
    1. Display Name: Development
    2. Username: <Blank for the SQLite example>
    3. Password: <Blank for the SQLite example>
    4. JDBC URL: jdbc:sqlite:FlywayQuickStartFWD.db


  7. Leave Save to project settings selected and click Test and save.

Working with migration scripts

Now that you created your project and configured your target database, you can add your first migration script.

  1. On the Migrations tab, click + Add migration.


  2. Enter the following details:

    1. Category:   Versioned (should already be selected) 
    2. Version: This defaults to 001_yyyymmddhhmmss.  The timestamp is included  by default to prevent multiple users from having the same exact version number.
    3. Description:  Create_person_table
    4. Script:
      create table PERSON (
      ID int not null,
      NAME varchar(100) not null
      );
    5. Click Save.


Now it is time to run your first migration.

  1. On the Migrations tab, you should see the script you just added in a Pending State.


  2. The available Flyway commands appear in the drop down on the right.  Make sure Migrate is selected in the drop down and click Run migrate.


    1. If you wanted to see the actual flyway command line that will execute, expand the View command (x parameters) first.  We hope this helps you learn the different CLI syntax if you ever want to automate this in a CI/CD system.


  3. Flyway Desktop should show the migration was successful. 


  4. Click Close.  You can now see the migration's state is Success and the time it took to execute this migration script against the target database.


  5. Let's repeat this process to add a second migration script.  Click + Add migration.


  6. Enter the following details:
    1. Category:   Versioned (should already be selected) 
    2. Version: This defaults to 002_yyyymmddhhmmss.  If you changed this above, it should just increment by 1.
    3. Description:  Add_people
    4. Script:
      insert into PERSON (ID, NAME) values (1, 'Axel');
      insert into PERSON (ID, NAME) values (2, 'Mr. Foo');
      insert into PERSON (ID, NAME) values (3, 'Ms. Bar');
    5. Press Save.


  7. This new migration should have a Pending state since it has not been applied to our target database yet.


  8. Again, the available Flyway commands appear in the drop down and you can view the CLI command on the right.  Make sure Migrate is selected in the drop down and click Run migrate.


  9. Flyway Desktop should show the migration was successful.  Click Close.


  10. Now, the second migration has a Success state and you can see the time it took to execute this migration script against the target database.


  11. To view the migration scripts on disk, click the blue folder in the top right.


  12. This brings you to the project folder.  Double click on the migrations folder to see your 2 scripts.


  13. If you go back up one level to the project folder, you can access a migration report.  Open report.html.


  14. The Dashboard shows details of the migration script that was just executed:


  15. Click onto the migration tab to see the following view


Configure connection details for the CLI

  1. To make using the CLI easier, go back to the project folder.  Remember, you can use the blue folder in the upper right of Flyway Desktop.


  2. Edit the flyway.conf file:
    flyway.url=jdbc:sqlite:FlywayQuickStartFWD.db
    flyway.user=
    flyway.password=


  3. In Flyway Desktop, use the command prompt at the top right to open a command prompt.

  4. Run flyway info to see how this works in the CLI:
    > flyway info

Summary

In this brief tutorial we saw how to:

  1. Install the Flyway Desktop and the Flyway CLI
  2. Create a project and configure the database connections
  3. Add a few migration scripts into our project and execute them on the target database
  4. See how the flyway info CLI command works 

Next Steps


Didn't find what you were looking for?