Flyway - Schema "public" is up to date. No migration necessary.

Greetings.

I am exploring Flyway Community to deploy PostgreSQL scripts from Azure DevOps pipeline using docker.

I have followed the steps given in the https://documentation.red-gate.com/flyway/deploying-database-changes-via-a-pipeline/example-ci-cd-pipelines/azure-devops/azure-devops-docker-yml-microsoft-hosted-agent, however the scripts are not getting deployed in the database.

Script files are renamed as V1__xxxx.sql, V2__xxxx.sql etc. I see the migration history table got created in the database in the first run, but the scripts are not getting executed.


Here is my YAML file, appreciate your help on it.

 

name: docker-ADO-hosted-pipeline

 

trigger:

  branches:

    include:

      - main

  paths:

    include:

      - /src/script/

 

pool:

  vmImage: $(AGENT_POOL)

 

variables:

  RELEASE_PREVIEW: 'Release-Preview.sql'

  BUILD_NAME: 'Build'

  REPORTS: 'Reports.html'

  REPORTS_DISPLAY_NAME: 'Reports'

 

  FLYWAY_MIGRATIONS_PATH: $(Build.Repository.LocalPath)/Flyway/src/script/

  FLYWAY_CONFIG_FILES: $(Build.Repository.LocalPath)/Flyway/config/

  FLYWAY: 'docker run --rm -v "$(FLYWAY_MIGRATIONS_PATH)":/flyway/migrations -v "$(FLYWAY_CONFIG_FILES)":/flyway/conf -v "$(System.ArtifactsDirectory)":/flyway/reports $(FLYWAY_DOCKER_IMAGE) flyway -user="$(userName)" -password="$(password)" -licenseKey=$(FLYWAY_LICENSE_KEY)'

 

  # Contains FLYWAY_LICENSE_KEY, BASELINE_VERSION, FIRST_UNDO_SCRIPT, FLYWAY_DOCKER_IMAGE, AGENT_POOL

  # Make BASELINE_VERSION match the baseline version in your project

  # Make FIRST_UNDO_SCRIPT match the first undo version in your project

  # FLYWAY_DOCKER_IMAGE is currently at: redgate/flyway:latest-azure

  # AGENT_POOL here is ubuntu-latest

  # Look for images at https://hub.docker.com/r/redgate/flyway

  group: flyway_vars

 

parameters:

  # IMPORTANT: DO NOT ADD DEPLOYMENT STEPS TO THE BUILD STAGE - THE BUILD IS A DESTRUCTIVE ACTION

  - name: buildStage

    type: object

    default:

      

      stage: 'Build'

      displayName: 'Build'

      variableGroupName: 'build_credentials_variable_group' #contains userName, password, JDBC, databaseName

 

  # This is the extensible definition of your target environments.

  # Every parameter in deploymentStages corresponds to an environment - here it's Test and Prod.

  # Pay attention to the 'dependsOn' field - this determines order of operations.

  - name: deploymentStages

    type: object

    default:

 

    - stage: 'Test'

      dependsOn: 'Build'

      displayName: 'Deploy Test'

      pauseForCodeReview: false

      variableGroupName: 'test_credentials_variable_group' #contains userName, password, JDBC, databaseName, check_JDBC

        # IMPORTANT: check_JDBC will get destroyed

 

    - stage: 'Prod'

      dependsOn: 'Test'

      displayName: 'Deploy Prod'

      pauseForCodeReview: true

      variableGroupName: 'prod_credentials_variable_group' #contains userName, password, JDBC, databaseName, check_JDBC

        # IMPORTANT: check_JDBC will get destroyed

 

stages:

       

  - stage: ${{parameters.buildStage.stage}}

    displayName: ${{parameters.buildStage.displayName}}

    jobs:

    - job: ${{parameters.buildStage.stage}}

      variables:

      - group: ${{ parameters.buildStage.variableGroupName }}

      - group: flyway_vars

      steps:


        - script: |

          displayName: 'List Files in Migration Path'

         

        - script: |

          displayName: 'List Files in config Path'         

          

        - script: |

            $(FLYWAY) baseline -url='$(JDBC)'

          displayName: 'Run Flyway Baseline'

          env:

            FLYWAY_LOG_LEVEL: DEBUG  # Set the log level to DEBUG

           

        - script: |

            $(FLYWAY) info migrate info -url='$(JDBC)' -cleanDisabled='true'

          failOnStderr: false

          displayName: 'Migrate Build DB'

          env:

            FLYWAY_LOG_LEVEL: DEBUG  # Set the log level to DEBUG

       

        - task: CopyFiles@2

          inputs:

            targetFolder: '$(System.ArtifactsDirectory)'

 

        - task: PublishBuildArtifacts@1

          displayName: 'Publish Build Artifact'

          inputs:

            ArtifactName: '$(BUILD_NAME)'

            PathtoPublish: '$(System.ArtifactsDirectory)'

         

  

  - ${{each stage in parameters.deploymentStages}}:

   

    - stage: ${{stage.stage}}

      displayName: ${{stage.displayName}}

      dependsOn: ${{stage.dependsOn}}

      jobs:

      - job: PreRelease

        displayName: Configure Release

        variables:

        - group: ${{stage.variableGroupName}}

        - group: flyway_vars

        steps:

          - task: DownloadBuildArtifacts@0

            inputs:

              buildType: 'current'

              downloadType: 'single'

              artifactName: '$(BUILD_NAME)'

              downloadPath: '$(System.ArtifactsDirectory)'

           

   

      - job: Deploy

        displayName: Deployment

      #  dependsOn: 'CodeReview'

        variables:

        - group: ${{stage.variableGroupName}}

        - group: flyway_vars

        steps:

 

          - script: |

              $(FLYWAY) info migrate info -url='$(JDBC)' -outOfOrder='false' -cleanDisabled='true' -baselineOnMigrate=true -baselineVersion='$(BASELINE_VERSION)'

            displayName: ${{stage.displayName}}

            failOnStderr: false

            env:

              FLYWAY_LOG_LEVEL: DEBUG  # Set the log level to DEBUG

 

 

 

Config file

 

flyway.url=jdbc:postgresql://dev-cccccccc.postgres.database.azure.com:5432/xxxx_flyway_db

flyway.user=xxxxxxx

flyway.password=xxxxxx

flyway.locations=filesystem:$(Build.Repository.LocalPath)/Flyway/src/script/

flyway.validateMigrationNaming=true

flyway.mixed=true

flyway.schemas=public

flyway.table=flyway_schema_history

flyway.baselineOnMigrate=true

flyway.baselineVersion=0


Tagged:

Answers

  • Hello, could you run "info -X" to check the debug log. 

    We would like to verify if the `location` parameter `flyway.locations=filesystem:$(Build.Repository.LocalPath)/Flyway/src/script/` is populated as expected, which is where your scripts V1 and V2 should reside.

Leave a Comment

BoldItalicStrikethroughOrdered listUnordered list
Emoji
Image
Align leftAlign centerAlign rightToggle HTML viewToggle full pageToggle lights
Drop image/file