Tag: Flyway

  • Getting Started Connecting to a Database with Flyway

    In a previous post, I got Flyway installed as a CLI utility (command line interface). This post will look at the first connection to a database.

    If you need to install Flyway on Windows, see my previous post.

    Concepts

    Flyway is a command line executable that takes various parameters to control what it does. Essentially, these are command verbs and decide what action is running. The previous post looked at the version command.

    There are also parameters that can be included before the command. There are lots of parameters.

    However, much of the way Flyway works is controlled by the flyway.conf file, which is inside a conf folder where you installed Flyway. If this file is found in the current folder, then Flyway will use configuration parameters from this file.

    Note, the inline parameters should override those in the conf file.

    Configuration

    I find it much easier to use the configuration files. While you can specify this with the configFiles parameter, I often ensure that I run Flyway from within a particular folder that has a flyway.conf file. This has worked well.

    Copy your flyway.conf from your install folder (under conf) to a new folder where you will experiment. For me, I set up a new folder called “smoketests” where I’m doing a little experimenting. As you can see, I only have two files in here:

    2022-12-27 11_06_23-cmd

    The default conf file can get a little confusing. It’s full of many options, which are somewhat documented. My default looks like this when I open it:

    2022-12-27 11_07_28-flyway.conf - flywaysimpletalk - Visual Studio Code

    Most everything is commented out, which makes it harder to figure out what to do.

    The thing to remember is that you uncomment those settings that you want to set. For example, the drivers section is extensive. Some of theses are included, some you need to download. Since this are all Java based JDBC drivers, it can look strange to a SQL Server person.

    2022-12-27 11_15_29-flyway.conf - flywaysimpletalk - Visual Studio Code

    The thing that gets lost in here for me is that I don’t comment out the line that starts with SQL Server. Instead, I need to copy and paste the jdbc part to the flyway.url= line. My valid connection would look like this:

    2022-12-27 11_17_26-● flyway.conf - flywaysimpletalk - Visual Studio Code

    Let’s try connecting with the info command. When I run Flyway info, I get asked for a user and password. Annoying, but not that bad. However, I then get an error:

    2022-12-27 11_19_53-cmd

    This is a secure connection error. I do have TCP/IP enabled, which I know Java needs. This is more about a change the SQL Server team made, which requires secure connections.

    Let’s add this to our connection string: ;trustServerCertificate=true

    This gives me this string:

    flyway.url=jdbc:sqlserver://aristotle\SQL2022;databaseName=FWPOC_1_Dev;trustServerCertificate=true

    Now when I connect, things work. I still have to enter a name and password, but I can connect and I get back something.

    2022-12-27 11_22_56-cmd

    I see some info on flyway versions. There’s a new version available. I’m also licensed for Flyway Enterprise.

    Then I see the filesystem folder, sql, is missing. This is where the migrations are stored, so if I want to add migration scripts, I need to add a folder.

    Next, I get the complete connection string. Lots of options here, of which most are defaults.

    Then I see the schema is empty. Flyway works off schemas, which is what many platforms require. We get lazy in SQL Server and often just use dbo, but most other platforms want schemas set up.

    Finally I see that there are no migrations run in this database, and I see an empty status table.

    That’s a lot, and I connected to the database. Nothing changed in the database, and no flyway_schema_history table was added. This essentially let me know Flyway was working.

    The last thing I’ll do is add this to my connection string: integratedSecurity=true

    This lets get away from the name and password on Windows, but using Windows Auth for SQL Server.

    2022-12-27 11_30_50-cmd

    That’s it. I’ll keep working on different commands in Flyway and getting to know the CLI.

  • Installing Flyway Community on Windows

    One of the things I’ve been trying to do is dig in more deeply to the Flyway command line (CLI) as part of my work with Redgate. While Flyway Desktop is amazing, it’s a wrapper, and my inclination is to ensure I understand the underlying technology.

    When I first downloaded Flyway, it wasn’t obvious what needed to be done to connect in different ways, so I decided on a short tutorial that would help me remember how and teach others a few things. This post goes over downloading Flyway and getting started.

    Setup

    The setup for Flyway is easy. The Community version is free, though there are also Teams and Enterprise editions.

    2022-12-27 10_42_52-Download   pricing - Flyway — Mozilla Firefox

    Flyway Community works on many platforms. I’ll choose Windows below.

    2022-12-27 10_44_47-Community edition - Flyway — Mozilla Firefox

    The Windows version is a zip file. Click this, and it will download.

    2022-12-27 10_45_35-Command-line - Command-line tool - Flyway by Redgate • Database Migrations Made

    Then unzip this. I have a c:\Utilities folder where I keep stuff and I’ve added a flyway folder there. I unzip the latest into this folder.

    2022-12-27 10_46_47-flyway

    If you care about versioning, you might drop Flyway into a version named folder, but I typically don’t on this machine. For production deployments, I would be more careful.

    You then need to add this to your PATH. If you are on Windows 10 or 11, then in the Control Panel (Windows+I), search for environment. Edit the variables for your account.

    2022-12-27 10_47_57-Settings

    Once the new dialog appears, find the PATH variable and click Edit.

    2022-12-27 10_48_04-Environment Variables

    Now add an entry for the folder where you extracted the Flyway files. For me, this is c:\utilities\flyway.

    2022-12-27 10_48_12-Edit environment variable

    That’s it, Flyway is installed.

    We can check at the command line with “flyway version”.

    2022-12-27 10_51_19-cmd

    If you have entered a license key, then you’ll see that message.

    2022-12-27 10_50_47-cmd

  • Paid Flyway Advantages–Undo and Check

    The Community edition of Flyway has some nice basic features, and it works well for many people. However, it requires you to do a lot of the heavy lifting of building and deploying scripts. There are some advantages of the paid editions, and one of those is the Undo and Baseline script additions in Flyway Desktop, which we’ll look at in this post.

    This is part of a series of posts that looks at Flyway and the feature differences between editions.

    Flyway Desktop

    The GUI for Flyway is Flyway Desktop. This works for all editions, though some features are not visible when you aren’t licensed for them. Here is the GUI we see the Flyway Community. Note there really is only one thing, which is a list of migrations.

    2022-10-27 17_39_14-Flyway Desktop

    This is useful, and it’s certainly nicer than Explorer. Plus, I can see what is run on a particular instance if I add one.

    If I look at my Flyway commands, I see this:

    2022-10-27 17_43_04-Flyway Desktop

    This lets me do the basics of what a script runner does. I can follow a simple, happy path with this functionality.

    Teams

    Flyway Teams is the mid-tier, and this adds a few nice things. In this case, I now see objects changed in the schema, and I get version control. Both valuable tools. 2022-10-27 17_41_08-Flyway Desktop

    However, for the Flyway functionality, I also get Undo and Baseline, both things that I do often.

    2022-10-27 17_41_58-Flyway Desktop

    The undo is huge, as there are times I need to get rid of something, or fix a script. Hopefully not in production, but definitely in dev and test.

    I can also dry run and see the script that will get executed here, something I’ve always wanted to do as a DBA.

    Enterprise

    The really useful tier is Enterprise. I know it’s pricey, but it also does the things I really need most in a mixed team of different skill levels.

    I get the Generate capability, which really automates the things from SQL Compare that hundreds of thousands of you have found valuable.

    2022-10-27 17_45_53-Flyway Desktop

    I also get the Check command, which lets me look for potential problems.

    2022-10-27 17_46_09-Flyway Desktop

    They All Work

    All tiers work, but the paid versions save you time and handle more of the work for you. If you have a team of gurus, you might like Community, but if your staff could use some help, think about trying the paid editions.

  • Flyway Mistakes

    I have been doing some testing with Redgate’s Flyway Desktop as a new way of managing code for databases. However, just like Git, I appreciate clients, but I want to know how the CLI (command line interface) works. I spent time learning git add, git push, git checkout and more. Now I have more comfort understanding how SourceTree or GitKraken work.

    I wanted to do the same thing with Flyway, just to be sure that I know what the options, switches, and behavior for Flyway operations would be.

    The Scenario

    I had an existing database, and I wanted to play around with adding this to a DevOps flow. I was looking for a basic experiment, and decided to create a new repo. I copied the default flyway.conf file into this folder and changed it.

    The only thing I did was alter the Flyway conf file in my folder to work with SQL Server. I copied the connection string into the flyway.url parameter and set it as follows:

    flyway.url=jdbc:sqlserver://aristotle:1433;instanceName=SQL2017;databaseName=AdventureWorks2017;integratedSecurity=true

    When I ran the info command, it failed.

    fw_fail

    When I ran the same command with a different database, it worked:fw_succeed

    I was highly confused. I tried a number of different databases, and some of them worked, not I couldn’t see a pattern.

    I checked a number of things, including the database owners, a few of which I changed. I thought it might be some permissions and dropped my sysadmin account and added it back.

    I tried connecting with SSMS and with sqlcmd. Both of those tools seemed to work.

    I was really stumped.

    A Small Conflict

    Finally, after a bit of back and forth with a few developers, someone noted that I shouldn’t need the port included in the string. Sure enough, when I removed it, things started working.

    Apparently, the JDBC documentation notes the issue. I kept looking at Flyway docs, but they just pass things along to the JDBC driver from the various parameters and environment variables.

    There is a note that says provide the port number to stop a round trip to the browser to determine the port number for a named instance. If the port number and name are included, the port takes precedence.

    I have two instances, some of which have the same databases on each. The databases that worked were on a different instance (which responds to 1433). The ones that didn’t, weren’t on that instance. I kept examining the \SQL2017 instance, but that wasn’t the one I was logging into with my string.

    A silly mistake, but a good one to note. The port is a higher priority than the instance in a Java connection string.

    I can’t find a priority in the docs for OLEDB or the native client, but they do all say the address takes precedence over the address parameter.