diff --git a/.github/workflows/openmis-module-test.yml b/.github/workflows/openmis-module-test.yml index f6187aa..258e38e 100644 --- a/.github/workflows/openmis-module-test.yml +++ b/.github/workflows/openmis-module-test.yml @@ -54,7 +54,7 @@ jobs: /opt/mssql-tools/bin/sqlcmd -S localhost,1433 -U SA -P $SA_PASSWORD -Q 'DROP DATABASE IF EXISTS imis_1_4_2' /opt/mssql-tools/bin/sqlcmd -S localhost,1433 -U SA -P $SA_PASSWORD -Q 'CREATE DATABASE imis_1_4_2' /opt/mssql-tools/bin/sqlcmd -S localhost,1433 -U SA -P $SA_PASSWORD -d imis_1_4_2 -i 1.42/openIMIS_ONLINE.sql | grep . | uniq -c - /opt/mssql-tools/bin/sqlcmd -S localhost,1433 -U SA -P $SA_PASSWORD -d imis_1_4_2 -i "new/output/fullMigrationScipt.sql" | grep . | uniq -c + /opt/mssql-tools/bin/sqlcmd -S localhost,1433 -U SA -P $SA_PASSWORD -d imis_1_4_2 -i "new/output/fullMigrationScript.sql" | grep . | uniq -c env: SA_PASSWORD: GitHub999 ACCEPT_EULA: Y @@ -73,7 +73,7 @@ jobs: /opt/mssql-tools/bin/sqlcmd -S localhost,1433 -U SA -P $SA_PASSWORD -Q 'DROP DATABASE IF EXISTS imis_main' /opt/mssql-tools/bin/sqlcmd -S localhost,1433 -U SA -P $SA_PASSWORD -Q 'CREATE DATABASE imis_main' /opt/mssql-tools/bin/sqlcmd -S localhost,1433 -U SA -P $SA_PASSWORD -d imis_main -i "oldMain/output/fullDemoDatabase.sql" | grep . | uniq -cc - /opt/mssql-tools/bin/sqlcmd -S localhost,1433 -U SA -P $SA_PASSWORD -d imis_main -i "new/output/fullMigrationScipt.sql" | grep . | uniq -c + /opt/mssql-tools/bin/sqlcmd -S localhost,1433 -U SA -P $SA_PASSWORD -d imis_main -i "new/output/fullMigrationScript.sql" | grep . | uniq -c env: @@ -88,7 +88,8 @@ jobs: run: | python -m pip install --upgrade pip pip install -r requirements.txt - python modules-requirements.py openimis.json > modules-requirements.txt + cd script + python modules-requirements.py ../openimis.json > modules-requirements.txt cat modules-requirements.txt pip install -r modules-requirements.txt - name: Django tests latest diff --git a/Dockerfile b/Dockerfile index a60d663..14096f3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,6 @@ FROM mcr.microsoft.com/mssql/server:2022-latest +RUN START_USER=$(whoami) +USER root ARG ACCEPT_EULA=Y ENV ACCEPT_EULA=N ARG SA_PASSWORD=IMISuserP@s @@ -6,11 +8,7 @@ ENV SA_PASSWORD=IMISuserP@s ENV DB_USER_PASSWORD=IMISuserP@s ENV DB_NAME=IMIS ENV DB_USER=IMISUser -ENV INIT_MODE=empty -USER root -RUN mkdir -p /app -COPY script/* /app/ -COPY sql /app/sql -WORKDIR /app -RUN chmod a+x /app/*.sh +COPY script/* ./ +COPY sql ./sql +RUN chmod a+x ./*.sh CMD /bin/bash ./entrypoint.sh diff --git a/README.md b/README.md index 0dc190e..f67f5fd 100644 --- a/README.md +++ b/README.md @@ -26,11 +26,11 @@ git clone https://github.com/openimis/database_ms_sqlserver * create a new database (i.e. openIMIS.X.Y.Z where X.Y.Z is the openIMIS database version) -* Execute the initial database creation script fullEmpytDatabase.sql or fullDemoDatabase.sql (see "creating SQL script" section on how to get them) +* Execute the initial database creation script fullEmptyDatabase.sql or fullDemoDatabase.sql (see "creating SQL script" section on how to get them) ### Upgrading -In order to upgrade from the previous version of openIMIS database (see [Versioning](#versioning) section), execute the migration script (fullMigrationSript), see "creating SQL script" to get it +In order to upgrade from the previous version of openIMIS database (see [Versioning](#versioning) section), execute the migration script (fullMigrationScript), see "creating SQL script" to get it ## Deployment @@ -43,7 +43,7 @@ Please read [CONTRIBUTING.md](https://gist.github.com/PurpleBooth/b24679402957c6 ### Creating SQL script - SQL files for initialisaiton or update are created using bash script concatenate_files.sh or by downloading the sql-file zip from the latest release https://github.com/openimis/database_ms_sqlserver/releases/latest + SQL files for initialisation or update are created using bash script concatenate_files.sh or by downloading the sql-file zip from the latest release https://github.com/openimis/database_ms_sqlserver/releases/latest ## openIMIS dockerized database @@ -56,13 +56,13 @@ Please read [CONTRIBUTING.md](https://gist.github.com/PurpleBooth/b24679402957c6 ### ENV -- INIT_MODE if set to demo will init the database to demo (works only if not yet init) +- DEMO_DATASET if set to true will init the database to demo (works only if not yet init) otherwise comment it out - SQL_SCRIPT_URL url to init scripts - **ACCEPT_EULA** must be set to Y to accept MS SQL EULA - SA_PASSWORD default: IMISuserP@s -- DB_USER_PASSWORD defautl: IMISuserP@s -- DB_NAMEdefautl: IMIS -- DB_USER defautl: IMISUser +- DB_USER_PASSWORD default: IMISuserP@s +- DB_NAME default: IMIS +- DB_USER default: IMISUser ### gettingstarted @@ -79,7 +79,7 @@ docker build \ -t openimis-db ``` -optinnaly +optional ``` --build-arg SQL_SCRIPT_URL= \ --build-arg DB_USER_PASSWORD=StrongPassword @@ -87,7 +87,7 @@ optinnaly --build-arg DB_NAME=IMIS ``` ***Notes***: -* by setting the ACCEPT_EULA=Y, you explicitely accept [Microsoft EULA](https://go.microsoft.com/fwlink/?linkid=857698) for the dockerized SQL Server 2017. Please ensure you read it and use the provided software according to the terms of that license. +* by setting the ACCEPT_EULA=Y, you explicitly accept [Microsoft EULA](https://go.microsoft.com/fwlink/?linkid=857698) for the dockerized SQL Server 2017. Please ensure you read it and use the provided software according to the terms of that license. * choose a strong password (at least 8 chars,...)... or SQL Server will complain @@ -97,13 +97,13 @@ To restore the backup inside the container: ***Note:*** -the container will check if the database exist, if it doesnot it will take the latest demo release version and deploy it , SQL_SCRIPT_URL is per defautl set to "https://github.com/openimis/database_ms_sqlserver/releases/latest/download/sql-files.zip" -to have data retention when container are recreated volums need to be configured as microsoft docs suggest +The container will check if the database exist. If it does not, it will take the latest demo release version and deploy it, SQL_SCRIPT_URL is by default set to "https://github.com/openimis/database_ms_sqlserver/releases/latest/download/sql-files.zip" +To ensure data retention when containers are recreated, volumes need to be configured as suggested in the Microsoft documentation. * /data:/var/opt/mssql/data : database files * /log:/var/opt/mssql/log : logs files * /secrets:/var/opt/mssql/secrets : secrets -The database is writen within the container. If you want to keep your data between container execution, stop/start the container via `docker stop ` / `docker start ` (using `docker run ... ` recreates a new container from the image... thus without any data) +The database is written within the container. If you want to keep your data between container execution, stop/start the container via `docker stop ` / `docker start ` (using `docker run ... ` recreates a new container from the image, thus without any data) diff --git a/concatenate_files.sh b/concatenate_files.sh deleted file mode 100644 index 1cc154b..0000000 --- a/concatenate_files.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/bash - -mkdir output -cat sql/migrations/1_migration_latest.sql sql/stored_procedures/*.sql > output/fullMigrationScipt.sql -cat sql/base/*.sql sql/stored_procedures/*.sql > output/fullEmptyDatabase.sql -cat sql/base/*.sql sql/stored_procedures/*.sql sql/demo/*.sql> output/fullDemoDatabase.sql -cat sql/base/*.sql sql/stored_procedures/*.sql sql/offline/central.sql > output/fullOfflineCentralDatabase.sql -cat sql/base/*.sql sql/stored_procedures/*.sql sql/offline/hf.sql > output/fullOfflineHFDatabase.sql diff --git a/script/concatenate_files.sh b/script/concatenate_files.sh index 1cc154b..6add062 100644 --- a/script/concatenate_files.sh +++ b/script/concatenate_files.sh @@ -1,8 +1,9 @@ #!/bin/bash mkdir output -cat sql/migrations/1_migration_latest.sql sql/stored_procedures/*.sql > output/fullMigrationScipt.sql +cat sql/migrations/1_migration_latest.sql sql/stored_procedures/*.sql > output/fullMigrationScript.sql cat sql/base/*.sql sql/stored_procedures/*.sql > output/fullEmptyDatabase.sql -cat sql/base/*.sql sql/stored_procedures/*.sql sql/demo/*.sql> output/fullDemoDatabase.sql +cat sql/base/*.sql sql/stored_procedures/*.sql sql/demo/*.sql > output/fullDemoDatabase.sql +cat sql/demo/*.sql > output/DemoDataset.sql cat sql/base/*.sql sql/stored_procedures/*.sql sql/offline/central.sql > output/fullOfflineCentralDatabase.sql cat sql/base/*.sql sql/stored_procedures/*.sql sql/offline/hf.sql > output/fullOfflineHFDatabase.sql diff --git a/script/run-initialization.sh b/script/run-initialization.sh index a506634..cdbf840 100644 --- a/script/run-initialization.sh +++ b/script/run-initialization.sh @@ -9,10 +9,10 @@ MSSQL_TOOLS_VERSION=$(ls -d ${MSSQL_TOOLS_BASE}* 2>/dev/null | sort -V | tail -n SQLCMD_PATH="${MSSQL_TOOLS_BASE}${MSSQL_TOOLS_VERSION}/bin/sqlcmd" -# DATABSE initialisation +# DATABASE initialisation -echo "Database initialisaton" -# if the table does not exsit it will create the table +echo "Database initialisation" +# if the table does not exist it will create the table # get "1" if the database exist : tr get only the integer, cut only the first integer (the second is the number of row affected) data=$($SQLCMD_PATH -S localhost -U SA -P $SA_PASSWORD -C -Q "SELECT COUNT(*) FROM master.dbo.sysdatabases WHERE name = N'$DB_NAME'" | tr -dc '0-9'| cut -c1 ) @@ -26,8 +26,8 @@ if [[ ${data} -eq "0" ]]; then #/opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P $SA_PASSWORD -Q "DROP DATABASE IF EXISTS $DB_NAME" $SQLCMD_PATH -S localhost -U SA -P $SA_PASSWORD -C -Q "CREATE DATABASE $DB_NAME" - if [[ "$INIT_MODE" = "demo" ]]; then - $SQLCMD_PATH -S localhost -U SA -P $SA_PASSWORD -C -i output/fullDemoDatabase.sql -d $DB_NAME | grep . | uniq -c + if [ "$DEMO_DATASET" ]; then + /opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P $SA_PASSWORD -i output/fullDemoDatabase.sql -d $DB_NAME | grep . | uniq -c else $SQLCMD_PATH -S localhost -U SA -P $SA_PASSWORD -C -i output/fullEmptyDatabase.sql -d $DB_NAME | grep . | uniq -c fi