You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
1.3 KiB
37 lines
1.3 KiB
#!/bin/bash
|
|
|
|
# Define variables
|
|
CREATE_TBLS="./CREATE_TABLES.sql"
|
|
INSERT_DATA="./BASE_DATA.sql"
|
|
CONTAINER_NAME="pptl-mssql"
|
|
DB_NAME="PortfolioPortalTest"
|
|
DB_USER="SA"
|
|
DB_PASS="LEAF-portal-test-enviroment1"
|
|
|
|
# Create Docker container
|
|
echo "Creating docker container: $CONTAINER_NAME"
|
|
docker run --name $CONTAINER_NAME -e "ACCEPT_EULA=Y" -e "MSSQL_SA_PASSWORD=$DB_PASS" -p 3341:1433 -d mcr.microsoft.com/mssql/server:2019-latest
|
|
|
|
#Wait for container to start
|
|
echo "Sleeping for 30 seconds to allow container to start..."
|
|
sleep 20
|
|
echo "10 seconds remaining..."
|
|
sleep 10
|
|
|
|
# Create database
|
|
echo "Creating $DB_NAME database..."
|
|
docker exec -it $CONTAINER_NAME /opt/mssql-tools/bin/sqlcmd -S localhost -U $DB_USER -P $DB_PASS -Q "CREATE DATABASE $DB_NAME;"
|
|
|
|
# Copy SQL script file into container
|
|
echo "Copying SQL scripts into container..."
|
|
docker cp $CREATE_TBLS $CONTAINER_NAME:/tmp/
|
|
docker cp $INSERT_DATA $CONTAINER_NAME:/tmp/
|
|
|
|
# Create tables using SQL script file
|
|
echo "Creating tables in $DB_NAME database..."
|
|
docker exec -it $CONTAINER_NAME /opt/mssql-tools/bin/sqlcmd -S localhost -d $DB_NAME -U $DB_USER -P $DB_PASS -i /tmp/$(basename $CREATE_TBLS)
|
|
|
|
echo "Adding base data..."
|
|
docker exec -it $CONTAINER_NAME /opt/mssql-tools/bin/sqlcmd -S localhost -d $DB_NAME -U $DB_USER -P $DB_PASS -i /tmp/$(basename $INSERT_DATA)
|
|
|
|
echo "Database & table setup complete!" |