Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check if it's possible to pipe output directly to sqlcmd (checked -i -, however... #29

Open
github-actions bot opened this issue Oct 25, 2022 · 0 comments
Assignees

Comments

@github-actions
Copy link

github-actions bot commented Oct 25, 2022

https://github.com/nanlabs/infra-reference/blob/f129254bb893310107de4529419c8e57e85b2b66/examples/docker/mssql/entrypoint.sh#L27

set -e

INITDB_FOLDER="/opt/mssql-scripts"
TMP_DIR="/tmp"

function sqlcmd() {
  file=${1?"Sql file must be provided as a parameter"}
  /opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P "${SA_PASSWORD}" -i "${file}"
  echo "$file imported successfully"
}

function initialize_app_database() {
    # Restore the application database using .sql files
    shopt -s globstar nullglob
    for file in "$INITDB_FOLDER"/*.sql; do
        sqlcmd "$file"
    done

    # Restore the application database using .sql.gz files
    shopt -s globstar nullglob
    for file in "$INITDB_FOLDER"/*.sql.gz; do
        echo "Uncompressing $file to $TMP_DIR"
        filename=$(basename "$file")
        uncompressed_file="$TMP_DIR/${filename//.gz/}"
        # TODO Check if it's possible to pipe output directly to sqlcmd (checked  -i -, however it didn´t seem to be supported ). as an alternative mkfifo can be reviewed as well
        gunzip --keep --stdout "$file" > "$uncompressed_file"
        sqlcmd "$uncompressed_file"
    done

    # Restore the application database using .sh files
    shopt -s globstar nullglob
    for file in "$INITDB_FOLDER"/*.sh; do
        echo "Importing $file"
        if [ -x "$file" ]; then
            "$file"

┆Issue is synchronized with this Clickup task by Unito

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: 🔖 Ready
Development

No branches or pull requests

2 participants