Tag: Redgate

  • Friday Flyway Tips: Chaining Commands for State-based Deployments

    One of the cool things I’ve seen with the new Flyway CLI is that I can combine multiple actions together in one call, which can make the process of writing automations streamlined.

    I’m not sure I love this, but I’ll show how this works.

    I’ve been working with Flyway Desktop for work more and more as we transition from older SSMS plugins to the standalone tool. This series looks at some tips I’ve gotten along the way.

    Making a State-Based Deployment from the CLI

    In a previous post, I showed how to use the new prepare and deploy verbs to create a deployment script and then apply it to a database. This is a great way to handle simpler deployments if you want to work in a state-based fashion with Flyway.

    That post showed two different CLI calls, which are shown below:

    flyway prepare -prepare.source=schemaModel -prepare.target="env:qa" -prepare.scriptFilename="deployments\FWState__deployment.sql"

    flyway deploy -scriptFilename="deployments\FWState__deployment.sql" -environment=qa -executeInTransaction=true

    Easy enough, and I like this structure as I’d likely build a pipeline that looks like this, where I prepare the script, then have a manual approval step to check this before deployment:

    2024-12_0228

    However, you might argue that someone would check the script in a QA or other deployment, so maybe you streamline things later, or you use this as a QA/test deployment and want everything to run smoothly after a PR.

    In that case …

    Chaining Commands

    I can run this code instead.

    flyway prepare deploy …

    Let’s see this work. If you look, I have a couple of changes that I can see in Flyway Desktop. There is a table alter and a new stored procedure.

    2024-12_0232

    I can streamline the automation of these two changes in the CLI with the code style above with this code:

    flyway prepare deploy -prepare.source=schemaModel -prepare.target=”env:qa” -environment=qa -executeInTransaction=true

    Here is the pre-execution look at my database:

    2024-12_0233

    The execution, which didn’t use a transaction. I’ll have to figure that one out:

    2024-12_0234

    And the post database view with the table and proc changes deployed.

    2024-12_0235

    I built and deployed the script in one command, and it also appeared to have added my script to the deployments folder. No idea why that happened either.

    2024-12_0236

    If you want commands chained, you can do it.

    Summary

    This post showed how you can chain your prepare and deploy commands together in one command, which might be preferable in some situations.

    I don’t know if I like this, or would do it, but it’s not a bad idea. Ultimately, I’d really like this deployment script to be saved back to the repo so I could track it, but that’s going to be some work, and likely that means not chaining commands.

    Flyway is an incredible way of deploying changes from one database to another, and now includes both migration-based and state-based deployments. You get the flexibility you need to control database changes in your environment. If you’ve never used it, give it a try today.

  • Using Flyway Prepare for State-Based Deployments

    One of the neat enhancements made to Flyway was the addition of state-based workflows and tooling. A lot of people have loved SQL Compare or SQL Source Control for deployments. As I’ve worked with customers, they’ve asked for this, and the v11 version of Flyway includes this for the Enterprise edition.

    This post will look at using these two commands to deploy a change to a database from the command line instead of Flyway Desktop.

    If you want to know more about Flyway, all my posts are together in one feed.

    My Current Environment

    I have Flway v11.0 installed and I have two databases: FWState_1_Dev and FWState_3_QA. These two databases are in my flyway.toml file, where I see them configured as development and qa.

    2024-12_0208

    I also created a “deployments” folder under my project, which is where I want deployment scripts. I’ll do this manually, but in a pipeline, I’d do this in an automated fashion. As you can see, this is an empty folder.

    2024-12_0209

    In Flyway Desktop (FWD), you can see that I have a change made in my dev db that’s ready to deploy. I could click “deploy” and run this from FWD, but I want to experiment with automation here, so I’m practicing at the command line.

    2024-12_0203

    I can verify this change isn’t deployed by checking the database.

    2024-12_0210

    Let’s get started.

    Flyway Prepare

    The prepare command is designed to create the deployment script. It can use a variety of sources, but in this case, I’ll use the schema model that I’ve saved in my git repo. This is where I (in general) want to pull from, using PRs and branches to manage work. In this case, I’ll pull from main, where I’ve got that change.

    To get my changes, I’ll use a few parameters with Flyway. One thing to note, each of these parameters includes a namespace. I think this will go away at some point, but it’s good to be explicit in any case as we have lots of “source” parameters in different namespaces.

    Second, use a single hyphen. That somewhat offends my unix/linux’y self, as the parameter names are more than one character. I’m used to 2 hyphens, which generate an error in Flyway.

    2024-12_0211

    The basic parameters I’m using are:

    • prepare.source – the location of my source. In this case, the schemaModel defined in my flyway.toml file as “schema-model” in the file system.
    • prepare-target – the target to look at to build the script. For me this is an environment preconfigured (see above) as qa, so “env:qa”
    • prepare.scriptFilename – the default is D__deployment.sql, but I want it in a subfolder, so I’ll explicitly put this in.

    My CLI call is this:

    flyway prepare -prepare.source=schemaModel -prepare.target=”env:qa” -prepare.scriptFilename=”deployments\FWState__deployment.sql”

    When I run this in my project folder, I see these results:

    2024-12_0212

    If I look in my deployments folder, I see the file:

    2024-12_0213

    The contents of the file are here:

    2024-12_0214

    This looks like what I’d get in FWD if I clicked “Deploy”.

    2024-12_0204

    This step just created the file. I need another call to deploy this.

    Flyway Deploy

    The Flyway Deploy command will execute a deployment script against a target. The idea here is that one script is created from a state-based project and deployed with this command.

    As with prepare, I’ll use a few parameters here. The ones I need are:

    • scriptFilename – the file to deploy. I’ll use the same one as above.
    • environment – the name of the environment where I am deploying, in this case, no need for the prefix.
    • executeInTransaction – this should default to true, but I’ll be explicit as I might change this in different platforms (postgreSQL, Oracle, etc.) and so if someone copies this pipeline, I want this to be clear.

    This gives me this command:

    flyway deploy -scriptFilename=”deployments\FWState__deployment.sql” -environment=qa -executeInTransaction=true

    When I run this, it works.

    2024-12_0215

    I can verify this in SSMS.

    2024-12_0216

    I’ve deployed changes, and if I look at the FWD deploy tab, I see no changes.

    2024-12_0217

    I could put these two commands in a pipeline and have them work in an automated fashion.

    If you do that, use variables in your pipeline, or ensure people commit (and merge) changes to the flyway.toml file that is used for the various options.

    Summary

    This post showed a quick way to start automated state-based deployments in Flyway, using the new prepare and deploy commands. A few options were used to control these deployments from a command line.

    There are more options that you can include to control deployments and I’ll look at some other ways of doing this in the future. For now, this gets my deployments working easily.

    Flyway is an incredible way of deploying changes from one database to another, and now includes both migration-based and state-based deployments. You get the flexibility you need to control database changes in your environment. If you’ve never used it, give it a try today.

  • Monday Monitor Tips: Lots of Postgres Options

    Redgate Monitor is growing to include more than just Microsoft SQL Server monitoring. We added PostgreSQL support in 2023 and that continues to grow. This post looks at a few changes we’ve added.

    This is part of a series of posts on Redgate Monitor. Click to see the other posts

    PostgreSQL Monitoring

    When we added PostgreSQL support to Redgate Monitor, I assumed that we could monitor most types of PostgreSQL installs. I was very wrong. Apparently everyone that’s forked or used PostgreSQL in different ways has changed how a DBA might need to monitor the system. At first we monitored on-premises installs only, but that’s grown.

    AWS

    We now support RDS. If you search for bluebox, you’ll see a PostgreSQL RDS instance. If you click in the card, you can see the workload, and more specifics on this RDS database.

    2024-12_0220

    We also support Aurora, if you use that version. Search for pizza and these cards appear, the right one being Aurora. This is an AWS Aurora database, based on PostgreSQL.

    2024-12_0222

    Azure

    We also support Azure Flex PostgreSQL database. Search for the pgtips database and you’ll see this card.

    2024-12_0221

    If you’re in the cloud with AWS or Azure, we have some PostgreSQL monitoring available for you, with more coming all the time.

    Give Redgate Monitor a Try

    Redgate Monitor continues to change and grow. Look at our demo system at monitor.red-gate.com and click the What’s New in the upper right, where you’ll see all the new features, like the PostgreSQL support changes.

    2024-12_0218

    You can also see the release timeline for more specific features in each version.

    2024-12_0219

    Redgate Monitor is a world class monitoring solution for your database estate. Download a trial today and see how it can help you manage your estate more efficiently.

  • Monday Monitor Tips: CIS Compliant

    A new feature added to Redgate Monitor Enterprise automatically. CIS compliance is something many enterprises think about as their auditors use this as a benchmark.

    If you’ve never looked at the Center for Internet Security, you ought to glance at them, and check out the benchmarks they have for many systems.

    This is part of a series of posts on Redgate Monitor. Click to see the other posts

    The CIS SQL Server Benchmark

    You might get asked by an auditor how you know your SQL Server estate is secure. There are lots of things you can do, but an easy one is being CIS compliant. There are benchmarks from CIS for many SQL Server versions. You can download the benchmark from CIS as a PDF, go through it, and then start to compare that to your SQL Server instances.

    2024-12_0195

    That’s not complex, but it is complicated. Lots of moving parts, where do you keep the benchmark data, how do you compare it to your instances, how do you ensure it’s up to date or get notified if it’s not?

    This is a simple job, but labor intensive, boring, and tedious. There’s a better way.

    Redgate Monitor Compliance

    We’ve added a compliance section to Redgate Monitor, which I’ve written about in terms of looking for older versions. However, we also have added to this section with a CIS Benchmark template.

    At the top of Redgate Monitor, there is a Security section and Compliance is under this.

    2024-12_0196

    When I get to the compliance screen, on the right side, I have a drop down for the templates. We’ve pre-loaded the CIS Benchmark in here. I can select that to see how compliant I am.

    2024-12_0197

    In this case, I’ve filtered to the SSC servers and when I do that, I see that I’m mostly compliant, but just barely. I say me, but this is our IT group that manages the config.

    2024-12_0198

    There is a disclaimed at the top, which you should note. It links here, where the docs note that this is a template that cannot be deleted or changed. It can be duplicated. Note, this is only for SQL Server 2022.

    If I click a server, I see the details of where and where not I am compliant. In tis case, things like database mail ought to be disabled.

    2024-12_0200

    I can’t change things from here, but I can export this as a report and work on remediation. If I want to set a template that is like CIS, but I have a good reason for an exception, such as the Cost threshold for parallelism set to something different, I can duplicate this template and alter it.

    Summary

    Auditing and compliance are becoming more important at many organizations, especially in light of the main data breaches and other issues that many organizations have experienced. This might even be required by insurance companies who want to ensure that you have not left open configurations that might become attack vectors.

    If you haven’t tried the compliance templates in Redgate Monitor, give it a try, or have a play at monitor.red-gate.com..

    Redgate Monitor is a world class monitoring solution for your database estate. Download a trial today and see how it can help you manage your estate more efficiently.