All Downloads are FREE. Search and download functionalities are using the official Maven repository.

liquibase.examples.json.liquibase.create-checks-packages.flow.yaml Maven / Gradle / Ivy

The newest version!
##########           LIQUIBASE FLOWFILE                ##########
##########  learn more http://docs.liquibase.com/flow  ##########

#### About this file liquibase-create-checks-packages.flow.yaml
#    This flow file generates the checks-packages artifacts shipped with Liquibase:
#      liquibase.checks-settings.conf (IF IT DOESNT EXIST)
#      liquibase.checks-package.yaml
#      checks-packages (directory)
#        >liquibase.checks.access-control.yaml
#        >liquibase.checks.data-protection.yaml
#        >liquibase.checks.schema-protection.yaml     
#        >liquibase.checks.changeset-standards.yaml
#        >liquibase.checks.coding-standards.yaml
# 
#    But the real value is to serve as a template for generating your own checks packages
#    if you already have a base checks-settings file which you would like to split into 
#    themed checks settings file in a sub-dir, controlled by a checks-package file.
#
#
#    To run this file: liquibase flow --flow-file=liquibase.create-checks-packages.flow.yaml
#



#### Start the flow file  
  
## Set up some global variables for property substitution in ANY stage
globalVariables:
  CHKSPKGSDIR: "./checks-packages"
  BASECHECKSFILE: "liquibase.checks-settings.conf"
  
  ACCESSCONTROL_FILE: "liquibase.checks.access-control.yaml"
  ACCESSCONTROL_CHECKS: "SqlGrantWarn,SqlGrantOptionWarn,SqlGrantAdminWarn,SqlRevokeWarn"
  ACCESSCONTROL_PKGNAME: "access-control.pkg"
  
  DATAPROTECTION_FILE: "liquibase.checks.data-protection.yaml"
  DATAPROTECTION_CHECKS: "ModifyDataTypeWarn,SqlSelectStarWarn,ChangeTruncateTableWarn"
  DATAPROTECTION_PKGNAME: "data-protection.pkg"
  
  SCHEMAPROTECTION_FILE: "liquibase.checks.schema-protection.yaml"    
  SCHEMAPROTECTION_CHECKS: "WarnOnUseDatabase,TableColumnLimit,ChangeDropTableWarn,ChangeDropColumnWarn,DetectChangeType"
  SCHEMAPROTECTION_PKGNAME: "schema-protection.pkg"
  
  CHANGESETSTANDARDS_FILE: "liquibase.checks.changeset-standards.yaml"
  CHANGESETSTANDARDS_CHECKS: "RollbackRequired,ChangesetLabelCheck,ChangesetContextCheck,ChangesetCommentCheck,OneChangePerChangeset,RequireChangesetIDisUUID"
  CHANGESETSTANDARDS_PKGNAME: "changeset-standards.pkg"  
  
  CODINGSTANDARDS_FILE: "liquibase.checks.coding-standards.yaml"  
  CODINGSTANDARDS_CHECKS: "CheckTablesForIndex,TableCommentCheck"
  CODINGSTANDARDS_PKGNAME: "coding-standards.pkg"
  
  CHECKSPACKAGE_MASTERFILE: "liquibase.checks-package.yaml" 
  CHECKSPACKAGE_MASTERFILE_HEADER: "liquibase.checks-package-header.yaml"
  
  


## Note: Any command which fails in any stage below result in the command stopping, and endStage being run.
## A flow file can have one or more stages, each with multiple "actions", 
## or your flow file can have multiple stages with fewer actions in each stage.
stages:


  ## create a default checks-settings file
  stage-create-default-conf-file:

    actions:
      # create dir for checks package yaml files to be created in later
      - type: shell
        if: exists("${BASECHECKSFILE}")==empty
        command: bash -c "1 | liquibase checks show";echo 'default checks setting config file created'





  ## A prep stage. There can be more than one stage if desired.
  stage-mkdir:

    actions:
      # create dir for checks package yaml files to be created in later
      - type: shell
        command: bash -c "mkdir -p ${CHKSPKGSDIR}"
      - type: shell
        command: bash -c "echo 'Made dir ${CHKSPKGSDIR}'"




  ## turn off all checks
  stage-checks-disable:
        
    actions:
      #
      # turn off checks, this will auto perform checks show as well
      #
      - type: liquibase
        command: checks bulkset
        cmdArgs: {disable: true, force: true}

          

  ###### now this is procedural for now, but could be decomposed into flowfiles since there is a ton of repeat, just with different names
  ###### but that is an exercise for later!


  ## CREATE checks settings files to be used in package
  stage-access-control-yaml:
  
    stageVariables:
      THISFILE: "${ACCESSCONTROL_FILE}" 
      THESECHECKS: "${ACCESSCONTROL_CHECKS}"

    actions:      
      #
      # turn on some checks
      #
      - type: liquibase
        command: checks enable
        cmdArgs: {check-name: "${THESECHECKS}"}
      #
      # show all checks just enabled
      #
      - type: liquibase
        command: checks show
        cmdArgs: {check-status: enabled}

      # create yaml file
      - type: shell
        command: bash -c "touch ${CHKSPKGSDIR}/${THISFILE};echo 'created file ${CHKSPKGSDIR}/${THISFILE}'"
      - type: shell
        command: bash -c "cp ${BASECHECKSFILE} ${CHKSPKGSDIR}/${THISFILE};echo 'copied enabled checks to ${CHKSPKGSDIR}/${THISFILE}'"

      #
      # turn off checks, this will auto perform checks show as well
      #
      - type: liquibase
        command: checks bulkset
        cmdArgs: {disable: true, force: true}




  ## CREATE checks settings files to be used in package
  stage-data-protection-yaml:
  
    stageVariables:
      THISFILE: "${DATAPROTECTION_FILE}" 
      THESECHECKS: "${DATAPROTECTION_CHECKS}"

    actions:      
      #
      # turn on some checks
      #
      - type: liquibase
        command: checks enable
        cmdArgs: {check-name: "${THESECHECKS}"}
      #
      # show all checks just enabled
      #
      - type: liquibase
        command: checks show
        cmdArgs: {check-status: enabled}

      # create yaml file
      - type: shell
        command: bash -c "touch ${CHKSPKGSDIR}/${THISFILE};echo 'created file ${CHKSPKGSDIR}/${THISFILE}'"
      - type: shell
        command: bash -c "cp ${BASECHECKSFILE} ${CHKSPKGSDIR}/${THISFILE};echo 'copied enabled checks to ${CHKSPKGSDIR}/${THISFILE}'"

      #
      # turn off checks, this will auto perform checks show as well
      #
      - type: liquibase
        command: checks bulkset
        cmdArgs: {disable: true, force: true}



  ## CREATE checks settings files to be used in package
  stage-schema-protection-yaml:
  
    stageVariables:
      THISFILE: "${SCHEMAPROTECTION_FILE}" 
      THESECHECKS: "${SCHEMAPROTECTION_CHECKS}"

    actions:      
      #
      # turn on some checks
      #
      - type: liquibase
        command: checks enable
        cmdArgs: {check-name: "${THESECHECKS}"}
      #
      # show all checks just enabled
      #
      - type: liquibase
        command: checks show
        cmdArgs: {check-status: enabled}

      # create yaml file
      - type: shell
        command: bash -c "touch ${CHKSPKGSDIR}/${THISFILE};echo 'created file ${CHKSPKGSDIR}/${THISFILE}'"
      - type: shell
        command: bash -c "cp ${BASECHECKSFILE} ${CHKSPKGSDIR}/${THISFILE};echo 'copied enabled checks to ${CHKSPKGSDIR}/${THISFILE}'"

      #
      # turn off checks, this will auto perform checks show as well
      #
      - type: liquibase
        command: checks bulkset
        cmdArgs: {disable: true, force: true}
        

  ## CREATE checks settings files to be used in package
  stage-changeset-standards-yaml:
  
    stageVariables:
      THISFILE: "${CHANGESETSTANDARDS_FILE}" 
      THESECHECKS: "${CHANGESETSTANDARDS_CHECKS}"

    actions:      
      #
      # turn on some checks
      #
      - type: liquibase
        command: checks enable
        cmdArgs: {check-name: "${THESECHECKS}"}
      #
      # show all checks just enabled
      #
      - type: liquibase
        command: checks show
        cmdArgs: {check-status: enabled}

      # create yaml file
      - type: shell
        command: bash -c "touch ${CHKSPKGSDIR}/${THISFILE};echo 'created file ${CHKSPKGSDIR}/${THISFILE}'"
      - type: shell
        command: bash -c "cp ${BASECHECKSFILE} ${CHKSPKGSDIR}/${THISFILE};echo 'copied enabled checks to ${CHKSPKGSDIR}/${THISFILE}'"

      #
      # turn off checks, this will auto perform checks show as well
      #
      - type: liquibase
        command: checks bulkset
        cmdArgs: {disable: true, force: true}        


  ## CREATE checks settings files to be used in package
  stage-coding-standards-yaml:
  
    stageVariables:
      THISFILE: "${CODINGSTANDARDS_FILE}" 
      THESECHECKS: "${CODINGSTANDARDS_CHECKS}"

    actions:      
      #
      # turn on some checks
      #
      - type: liquibase
        command: checks enable
        cmdArgs: {check-name: "${THESECHECKS}"}
      #
      # show all checks just enabled
      #
      - type: liquibase
        command: checks show
        cmdArgs: {check-status: enabled}

      # create yaml file
      - type: shell
        command: bash -c "touch ${CHKSPKGSDIR}/${THISFILE};echo 'created file ${CHKSPKGSDIR}/${THISFILE}'"
      - type: shell
        command: bash -c "cp ${BASECHECKSFILE} ${CHKSPKGSDIR}/${THISFILE};echo 'copied enabled checks to ${CHKSPKGSDIR}/${THISFILE}'"

      #
      # turn off checks, this will auto perform checks show as well
      #
      - type: liquibase
        command: checks bulkset
        cmdArgs: {disable: true, force: true}
        
        
       
        
  ## CREATE the checks package file using the just created themed checks-settings config yaml files
  stage-add-access-control-pkg-to-chkspkg-file:
  
    stageVariables:
      THISPKG_FILE: "${CHECKSPACKAGE_MASTERFILE}"
      THISPKG_NAME: "${ACCESSCONTROL_PKGNAME}"
      THISPKG_CONTENTS: "${ACCESSCONTROL_FILE}"
      
    actions:
      #
      # create package file with package names and checks - ACCESSCONTROL
      #
      - type: liquibase
        command: checks create
        cmdArgs: {package-file: "${THISPKG_FILE}", package-name: "${THISPKG_NAME}", package-contents: "${CHKSPKGSDIR}/${THISPKG_CONTENTS}"}   
        
        
        
        
        
  ## CREATE the checks package file using the just created themed checks-settings config yaml files
  stage-add-data-protection-pkg-to-chkspkg-file:
  
    stageVariables:
      THISPKG_FILE: "${CHECKSPACKAGE_MASTERFILE}"
      THISPKG_NAME: "${DATAPROTECTION_PKGNAME}"
      THISPKG_CONTENTS: "${DATAPROTECTION_FILE}"
      
    actions:
      #
      # create package file with package names and checks - DATA PROTECTION
      #
      - type: liquibase
        command: checks create
        cmdArgs: {package-file: "${THISPKG_FILE}", package-name: "${THISPKG_NAME}", package-contents: "${CHKSPKGSDIR}/${THISPKG_CONTENTS}"}          


  ## CREATE the checks package file using the just created themed checks-settings config yaml files
  stage-add-schema-protection-pkg-to-chkspkg-file:
  
    stageVariables:
      THISPKG_FILE: "${CHECKSPACKAGE_MASTERFILE}"
      THISPKG_NAME: "${SCHEMAPROTECTION_PKGNAME}"
      THISPKG_CONTENTS: "${SCHEMAPROTECTION_FILE}"
      
    actions:
      #
      # create package file with package names and checks - SCHEMA PROTECTION
      #
      - type: liquibase
        command: checks create
        cmdArgs: {package-file: "${THISPKG_FILE}", package-name: "${THISPKG_NAME}", package-contents: "${CHKSPKGSDIR}/${THISPKG_CONTENTS}"}          


  ## CREATE the checks package file using the just created themed checks-settings config yaml files
  stage-add-changeset-standards-pkg-to-chkspkg-file:
  
    stageVariables:
      THISPKG_FILE: "${CHECKSPACKAGE_MASTERFILE}"
      THISPKG_NAME: "${CHANGESETSTANDARDS_PKGNAME}"
      THISPKG_CONTENTS: "${CHANGESETSTANDARDS_FILE}"
      
    actions:
      #
      # create package file with package names and checks - CHANGESET STANDARDS
      #
      - type: liquibase
        command: checks create
        cmdArgs: {package-file: "${THISPKG_FILE}", package-name: "${THISPKG_NAME}", package-contents: "${CHKSPKGSDIR}/${THISPKG_CONTENTS}"}          



  ## CREATE the checks package file using the just created themed checks-settings config yaml files
  stage-add-coding-standards-pkg-to-chkspkg-file:
  
    stageVariables:
      THISPKG_FILE: "${CHECKSPACKAGE_MASTERFILE}"
      THISPKG_NAME: "${CODINGSTANDARDS_PKGNAME}"
      THISPKG_CONTENTS: "${CODINGSTANDARDS_FILE}"
      
    actions:
      #
      # create package file with package names and checks - CODING STANDARDS
      #
      - type: liquibase
        command: checks create
        cmdArgs: {package-file: "${THISPKG_FILE}", package-name: "${THISPKG_NAME}", package-contents: "${CHKSPKGSDIR}/${THISPKG_CONTENTS}"}          


  ## add both STANDARDS to one pkg
  stage-allstandards:
  
    stageVariables:
      THISPKG_FILE: "${CHECKSPACKAGE_MASTERFILE}"
      THISPKG_NAME: "all-standards.pkg"
      THISPKG_CONTENTS: "${CHKSPKGSDIR}/${CODINGSTANDARDS_FILE},${CHKSPKGSDIR}/${CHANGESETSTANDARDS_FILE}"
      
    actions:
      #
      # create package file with package names and checks - ALL STANDARDS
      #
      - type: liquibase
        command: checks create
        cmdArgs: {package-file: "${THISPKG_FILE}", package-name: "${THISPKG_NAME}", package-contents: "${THISPKG_CONTENTS}"}     

  ## add both PROTECTIONS to one pkg
  stage-allprotections:
  
    stageVariables:
      THISPKG_FILE: "${CHECKSPACKAGE_MASTERFILE}"
      THISPKG_NAME: "all-protections.pkg"
      THISPKG_CONTENTS: "${CHKSPKGSDIR}/${SCHEMAPROTECTION_FILE},${CHKSPKGSDIR}/${DATAPROTECTION_FILE}"
      
    actions:
      #
      # create package file with package names and checks - ALL PROTECTIONS
      #
      - type: liquibase
        command: checks create
        cmdArgs: {package-file: "${THISPKG_FILE}", package-name: "${THISPKG_NAME}", package-contents: "${THISPKG_CONTENTS}"}     






  ################# Enhance the just created checks package file with information
  stage-add-INFO-HEADER-chkspkg-file:

      
    actions:
      #
      # prepend header file using cat to checks package file
      #
      - type: shell
        command: bash -c "cat ${CHECKSPACKAGE_MASTERFILE_HEADER} ${CHECKSPACKAGE_MASTERFILE} > tmmmp.tmp && mv tmmmp.tmp ${CHECKSPACKAGE_MASTERFILE}"

      - type: shell
        command: bash -c "echo 'added informational header to ${CHECKSPACKAGE_MASTERFILE}'"



## The endStage ALWAYS RUNS. 
## So put actions here which you desire to perform whether previous stages' actions succeed or fail.
## If you do not want any actions to ALWAYS RUN, simply delete the endStage from your flow file.

endStage:
  actions:
    - type: shell
      command: bash -c "echo 'New Checks Package file ${CHECKSPACKAGE_MASTERFILE}'"
      
      
      
      
      
      
      




© 2015 - 2024 Weber Informatics LLC | Privacy Policy