Kontext Kontext

Error: Muliple files found matching pattern ./*.sql

event 2023-01-09 visibility 109 comment 0 insights toc
more_vert
insights Stats

Issue context

When using GitHub actions to deploy SQL scripts to Azure SQL database, the following error appears:

      # Deploy database scripts
      - uses: azure/sql-action@v2
        with:
          connection-string: ${{ secrets.DB_CONN_STRING }}
          path: "./*.sql"

The error occurred because there are multiple files matched by the wildcard "./*.sql". Currently this action doesn't support multiple SQL files.

Resolutions

To fix this issue, there are multiple approaches.

Concatenate files into one

Since only one script file is supported, we can concatenate multiple files into one. This can be done via another action task. The following code snippet provides one example:

      - name: Concat sql scripts
        run: |
          pushd ./scripts/sql
          find *.sql | sort -n | xargs cat >> /path/to/destination/script.sql
          popd

The above script change directory to a folder named 'scripts/sql' and then find all the SQL files; at last, it concatenates them into one single file.

Run multiple actions

We can also run the azure/sql-action multiple times:

      - uses: azure/sql-action@v2
        with:
          connection-string: ${{ secrets.DB_CONN_STRING }}
          path: "./script-1.sql"

      - uses: azure/sql-action@v2
        with:
          connection-string: ${{ secrets.DB_CONN_STRING }}
          path: "./script-2.sql"

      - uses: azure/sql-action@v2
        with:
          connection-string: ${{ secrets.DB_CONN_STRING }}
          path: "./script-N.sql"

Use a matrix

If you want to dynamically setup these tasks, you can use matrix feature for your job.  For examples, please refer to the official documentation Using a matrix for your jobs - GitHub Docs. You may want to use max-parallel property to limit the concurrency. If the sequence of execution is important, please use the previous approaches. 

More from Kontext
comment Comments
No comments yet.

Please log in or register to comment.

account_circle Log in person_add Register

Log in with external accounts