What are the challenges you face when working across database platforms? Take the survey

PowerShell to genereate script comparing two revisions of the same DB

blackraven86blackraven86 Posts: 1 New member
edited July 30, 2021 8:08AM in SQL Compare
Hi. Really new in Redgate.
My command wants to automate generating redgate scripts.
Basically when a developer makes a commit that requires DB changes he/she runs SQL Compare Pro (from SSMS) that generates scripts
 SQL source control, revision some_revision_needed
 SQL source control, revision HEAD

We use TFS as a version control system.

Now I'm trying to figure out how to make the same happens from PowerShell.
Reading this article, got the scripts from Github
but can't understand what is this (in the script code):

    $Source = '1'; $Target = '2' #never alter these, they are constants.
    if ($SourceType -eq 'Database')
    { $Dbs = $Source }
    else { $Dbs = $Target } #the database (Dbs) is either $source or $Target.

As far as I can see it in my case both source and target will be DBs but different revisions.
smth like
sqlcompare /db1:DB_DATA /revision1:bc1e57e /db2:DB_DATA /revision2:fd4e53a /scripts -please_put_the_scripts_here_and_don't_run_them_yet
Am I wrong? Do I misunderstand the logic of Redgate work?

Probably it's not even comparing two DBs but two SQL source controls...
There is a piece of the internal manual for developers to do it manually. That's how it works now.

So what my line to run the script should look like?



  • Options
    Sergio RSergio R Posts: 610 Rose Gold 5

    I would recommend that you use SQL Change Automation for SSMS, this will create a migration script with every commit, and you have the option of using SQL Source Control as a source.

    Please note that this will not incur any extra cost for you as these tools are included both in the SQL Toolbelt and Redgate Deploy suite.

    Kind Regards,
    Product Support Engineer
    Redgate Software Ltd
    Please see our Help Center for detailed guides on how to use our tools
Sign In or Register to comment.