Tag: Redgate

  • Webinar – Navigating the database landscape in 2024: Shifting skills to match constant demands

    Next week on Jan 23, I’m part of a webinar titled “Navigating the database landscape in 2024: Shifting skills to match constant demands”. You can register today and join me live or see the recording.

    Redgate has run various surveys in the past, often with a professional survey company that reaches a wide audience. At the end of 2023, we surveyed lots of people about the state of the database landscape, with a emphasis on how the world of the database professional is changing.

    Ryan Booz, Beca Parker, and I will be discussing what we think of the results, as technical professionals. This is more of an informal chat, a discussion about some of the data that came back from over 3,000 professionals.

    Join us Tuesday the 23rd for a discussion and feel free to ask your own questions of us.

  • Friday Flyway Tips–The Version Control Blade

    The Flyway Desktop Version Control tab is gone and a new blade has appeared in its place. This post looks at the changes and what that means for a developer.

    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.

    The Version Control Tab

    It’s gone. Here’s an old screenshot of what this looked like. It was one of four tabs across the top of a project. Note that this just had the title, with no information.

    2023-12-13 18_01_48-Flyway Desktop

    That’s unlike most other tools that provide VCS features, in that there usually is some status. On the tab, you can see the files to be committed, and push/pull/etc., but you have to select the tab.

    2023-12-13 18_02_45-Flyway Desktop

    We wanted to do better.

    A Version Control Blade and Status Bar

    We realized that version control isn’t really part of the workflow of Flyway Desktop; it’s a separate function. We also had lots of requests to help developers know there are changes in the repo to commit, push, etc.

    We’ve been testing this for some time as a feature flag, which was annoying because I’d see the tab and the blade, but it released recently. I’m not sure which version got this, but it is in 7.0.3.

    You can see it below, on the right side. Note that we have an arrow at the top to expand this. We also have a branch icon, a refresh, which tells you the last time something push/pull/fetch’d, and then there are down arrow (remote commits not pulled), a circle with a line (uncommitted changes), and an up arrow (commits to push).

    2024-01-05 16_39_26-Flyway Desktop

    If I select the object listed, and click Save, I’ll see this after the operation completes I have an uncommitted change. Notice the “1” in the middle of the blade.

    2024-01-05 16_41_53-Flyway Desktop

    I can expand the blade, but I can just click the one (or icon) and I see the blade expand. From here, I can add a commit message and commit this change (if I select it).

    2024-01-05 16_42_01-Flyway Desktop

    I’ll make another change, generating a migration script. Now my expansion shows 3 changes, the schema file, the migration script and the undo script.

    2024-01-05 16_44_44-Flyway Desktop

    I’ll commit these three as one item. My blade closes after this and I see a committed change to push.

    2024-01-05 16_45_40-advocates - Redgate - Slack

    I’ll generate another migration script. In this case, I now see multiple changes. I see my two new migration scripts added, and I still have a commit to push.

    2024-01-05 16_48_43-Flyway Desktop

    If I expand the blade, I can see the details. For example, on the push tab, I can see the commit and files included. For a small screen, or small window, I get a tooltip if I hover and can see the full file name and path.

    Screenshot 2024-01-05 165157

    If I make a change in the remote, likewise, I’ll also see a commit to pull.

    2024-01-05 16_53_57-Flyway Desktop

    I’ll push and pull (and commit) and then I’ll see a clean list nothing in my VCS blade.

    Summary

    This isn’t a big change, and I’d argue this makes FWD much easier to use and more comfortable for many people. Developers are less likely to have their local repo out of synch with a remote.

    Try Flyway Desktop out today. If you haven’t worked with Flyway Desktop, download it today. There is a free version that organizes migrations and paid versions with many more features.

    Video Walkthrough

    I made a quick video showing this as well. You can watch it below, or check out all the Flyway videos I’ve added:

  • Prompt EAP AI Experiments: Creating a History Table

    SQL Prompt has an EAP using an AI model to help write code. I’ve been lightly experimenting with it, since I think AI is an interesting tech and it’s going to change our jobs. Maybe for the better, maybe for the worse, but I want to know if this will help me get work done sooner.

    This post looks at one experiment.

    This is part of a series of experiments with AI systems.

    Building a New Table

    I’ve written a lot of SQL code in my career. I know how to structure things and I can often whip something up quickly in response to requests from users or customers. Recently I was trying to mock up a change for a scenario and I decided to use the SQL Prompt AI beta.

    In this case, I wanted a create a history table, similar to a temporal table. I started writing some code, but decided to use the AI to see if things were easier. I tried two experiments here, one using temporal tables, one using just normal T-SQL. Here’s what happened.

    Create a Temporal Table

    As I started documenting this, I decided to ask for a temporal table. You can see my basic code I sketched, but stopped before I created the table. Then I asked SQL Prompt to create the temporal able.

    2024-01-02 14_30_35-SQLQuery2.sql - ARISTOTLE.dlm_1_dev (ARISTOTLE_Steve (64))_ - Microsoft SQL Serv

    Here’s what I got:

    2024-01-02 14_32_42-SQLQuery2.sql - ARISTOTLE.dlm_1_dev (ARISTOTLE_Steve (64))_ - Microsoft SQL Serv

    The actual code is:

    /* Assuming the ArticlePayment table schema is unaltered before the creation of the history table */
    

    /* Step 1: Add period columns to the original table */
    ALTER TABLE dbo.ArticlePayment
    ADD
       StartDate datetime2(2) GENERATED ALWAYS AS ROW START
    , EndDate datetime2(2) GENERATED ALWAYS AS ROW END
    , PERIOD FOR SYSTEM_TIME(StartDate, EndDate);

    /* Step 2: Change the original table to be a system-versioned temporal table. This will create a new history table with a similar structure as the original table. */
    ALTER TABLE dbo.ArticlePayment SET (SYSTEM_VERSIONING = ON (HISTORY_TABLE=dbo.ArticlePayment_History));

    That’s pretty good. I don’t usually remember what to do and often end up scanning an article like this one. An AI that provides this code might be a nice time saver, especially if I needed to do a few tables.

    Building an Audit Copy

    The way I’ve often tracked history in the past is essentially copying a table and adding some date columns.

    2024-01-02 14_37_03-SQLQuery2.sql - ARISTOTLE.dlm_1_dev (ARISTOTLE_Steve (64))_ - Microsoft SQL Serv

    This is helpful and quick. It gets the datatypes and names, and replicates what’s in the original dbo.ArticlePayment table.

    2024-01-02 14_37_37-SQLQuery2.sql - ARISTOTLE.dlm_1_dev (ARISTOTLE_Steve (64))_ - Microsoft SQL Serv

    I want to add nullability, so I asked above. You can see the results below.

    2024-01-02 14_37_51-SQLQuery2.sql - ARISTOTLE.dlm_1_dev (ARISTOTLE_Steve (64))_ - Microsoft SQL Serv

    One more prompt:

    2024-01-02 14_40_20-SQLQuery2.sql - ARISTOTLE.dlm_1_dev (ARISTOTLE_Steve (64))_ - Microsoft SQL Serv

    The result includes a new column with a default, which I like.

    2024-01-02 14_40_43-SQLQuery2.sql - ARISTOTLE.dlm_1_dev (ARISTOTLE_Steve (64))_ - Microsoft SQL Serv

    I can click the check in the upper left of the Prompt dialog to get this code accepted in my query window. From there, I can run this and then check the code into my VCS with Flyway Winking smile

    Comparison with ADS

    In many cases, I struggle to use an AI well. The public ones don’t see my schema, so if I were to prompt this in Copilot or some equivalent, I’d have to include my schema. If I don’t, I get something like this:

    2024-01-02 14_43_10-● SQLQuery_1 - SQL 2019 sandbox - Azure Data Studio

    If I include the schema (annoying, pasted from SSMS scripting and then commented out and edited, I get something that works, but I get a line at a time and have to accept each line.

    2024-01-02 14_45_10-● SQLQuery_1 - SQL 2019 sandbox - Azure Data Studio

    Thoughts on the Prompt EAP AI

    The EAP AI version of SQL Prompt is reading my schema, as SQL Prompt does, and then running my prompt through an AI LLM with the schema to decide what I mean. In this case, it knows temporal tables are system versioned ones. It produces good code there. Really, this has done the search engine lookup of how to convert a table to temporal, copied the code, and then edited it for my situation.

    If I ignore the temporal aspect and ask for a history table, it creates what I’d do, which is a copy of the table. If I need this altered, it does a good job if doing the edits. Using a little English here, instead of manually editing, actually worked pretty efficiently for me. I’d know what prompts to use now, and I can go back in my prompts copy them, and alter them for other tables.

    Even better, I asked: “create history tables for all article tables”

    I got the code below, which is pretty cool. This is a subset of related tables to articles, not all the tables in my database. Comments from Prompt at the top and then the code.

    /*  

                These scripts will create new tables named 'ArticlePaymentHistory', 'ArticlesHistory', 'ArticleAuthorHistory', 'RatingsHistory', 'UserRatingHistory' which are copies of 'ArticlePayment', 'Articles', 'ArticleAuthor', 'Ratings', 'UserRating'.

                It assume that you want exactly the same structure as the respective tables including all the columns and their types.

                The difference is that all columns in these history tables will NOT BE NULLABLE with an additional column 'ModifiedDate' that defaults to the current date and time.

                It does not copy the data from the original tables. If you need that too then make sure first none of your records from these tables have null

                records for any of the columns because now we have made all columns as 'NOT NULL' in the history tables.

            */

    CREATE TABLE dbo.ArticlePaymentHistory
    ( ArticlePaymentKey  int       NOT NULL
    , ArticleID          int       NOT NULL
    , ContactID          int       NOT NULL
    , PublishDate        date      NOT NULL
    , PaymentDate        date      NOT NULL
    , AuthorPaid         bit       NOT NULL
    , ArticlePaymentRate numeric   NOT NULL
    , ModifiedDate       datetime2 NOT NULL DEFAULT GETDATE ());
    CREATE TABLE dbo.ArticlesHistory
    ( ArticlesID          int       NOT NULL
    , AuthorID            int       NOT NULL
    , Title               char      NOT NULL
    , Description         varchar   NOT NULL
    , Article             varchar   NOT NULL
    , PublishDate         datetime  NOT NULL
    , ModifiedDate        datetime  NOT NULL
    , URL                 char      NOT NULL
    , Comments            int       NOT NULL
    , ReadingTimeEstimate time
    , CreatedDate         datetime2 NOT NULL
    , ModifiedBy          nvarchar  NOT NULL
    , HistoryModifiedDate datetime2 NOT NULL DEFAULT GETDATE ());
    CREATE TABLE dbo.ArticleAuthorHistory
    ( ArticleAuthorKey int       NOT NULL
    , ArticleID        int       NOT NULL
    , ContactID        int       NOT NULL
    , AuthorOrder      tinyint   NOT NULL
    , ModifiedDate     datetime2 NOT NULL DEFAULT GETDATE ());
    CREATE TABLE dbo.RatingsHistory
    ( RatingKey    int       NOT NULL
    , ArticlesID   int       NOT NULL
    , RatingDate   datetime2
    , Rating       tinyint   NOT NULL
    , UserKey      int       NOT NULL
    , ModifiedDate datetime2 NOT NULL DEFAULT GETDATE ());
    CREATE TABLE dbo.UserRatingHistory
    ( UserRatingKey int       NOT NULL
    , UserID        int       NOT NULL
    , ArticleID     int       NOT NULL
    , Rating        numeric   NOT NULL
    , ModifiedDate  datetime2 NOT NULL DEFAULT GETDATE ());

  • Friday Flyway Tips–Linking Commits to an Azure DevOps Work Item

    Recently I was doing a demo and a customer asked how I had linked my commit in Azure DevOps to the work item that existed. It’s easy, and tldr; it’s with the commit comment. This post shows how that 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.

    Creating a Work Item

    In Azure DevOps, there is a board menu. Under here, one of the subitems is Work Items. You can see these below:

    2023-12-13 17_52_28-Work items - Boards

    I tend to work from the “Boards” item, which looks like this:

    2023-12-13 17_52_22-Westwind Team Features Board - Boards

    Let’s assume we have a new item, so I’ll click the “New Item” at the top of the left column. This gives me an edit box, which I’ll type in a name.

    2023-12-13 17_54_25-Westwind Team Features Board - Boards

    When I hit enter, this gives me a new work item, which you see below, as 250 create products entitty.

    2023-12-13 17_55_19-Westwind Team Features Board - Boards

    Since I don’t want to leave a spelling error, I’ll edit the title to look better.  Now I have a work item.

    Linking A Commit in FWD

    In SSMS, I’ll create the products table. Once I do this, I’ll go to Flyway Desktop and refresh the schema model. When I do this, I see my change. I’ll select this and save to the file system.

    2023-12-13 18_01_48-Flyway Desktop

    Once this is done, I’ll go to the Version Control tab, and I again see my file changed. Here my file is selected, and I’ll enter a commit message, but I’ll include the work item number after a #. This creates a link.

    2023-12-13 18_02_45-Flyway Desktop

    I now click commit and push. In Azure DevOps, in the Repos –> Commit item, I see my commit.

    2023-12-13 18_04_15-Commit 1421f994_ #250 create products table - Repos
    Note the details item under my cursor. If I click that, I see commit details and near the bottom, a link to the work item.

    2023-12-13 18_04_21-Commit 1421f994_ #250 create products table - Repos

    If I click through to the work item, or I access the work item from Boards, I will see my commit linked on the far right of the work item.

    2023-12-13 18_04_32-Westwind Team Features Board - Boards

    This is very handy to have your actual code linked to the work that it relates to. If I have PRs or multiple commits, as long as you use the #nnn, where nnn is the work item, you’ll have everything linked together.

    This is less a Flyway Desktop feature than an Azure DevOps one, but you can access this from Flyway Desktop by writing good commit messages with work item numbers.

    Try Flyway Desktop out today. If you haven’t worked with Flyway Desktop, download it today. There is a free version that organizes migrations and paid versions with many more features.

    Video Walkthrough

    I made a quick video showing this as well. You can watch it below, or check out all the Flyway videos I’ve added: