Skip to content

Commit

Permalink
simplify running
Browse files Browse the repository at this point in the history
  • Loading branch information
dragos-dobre committed May 16, 2024
1 parent 25dd72f commit 6ad4856
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 29 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/openmis-module-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down
1 change: 0 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ ENV SA_PASSWORD=IMISuserP@s
ENV DB_USER_PASSWORD=IMISuserP@s
ENV DB_NAME=IMIS
ENV DB_USER=IMISUser
ENV INIT_MODE=empty
RUN mkdir -p /app
COPY script/* /app/
COPY sql /app/sql
Expand Down
24 changes: 12 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand All @@ -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
Expand All @@ -79,15 +79,15 @@ docker build \
-t openimis-db
```

optinnaly
optional
```
--build-arg SQL_SCRIPT_URL=<url to the sql script to create the database> \
--build-arg DB_USER_PASSWORD=StrongPassword
--build-arg DB_USER=IMISUser
--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


Expand All @@ -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.
* <host directory>/data:/var/opt/mssql/data : database files
* <host directory>/log:/var/opt/mssql/log : logs files
* <host directory>/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 <CONTAINER ID>` / `docker start <CONTAINER ID>` (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 <CONTAINER ID>` / `docker start <CONTAINER ID>` (using `docker run ... ` recreates a new container from the image, thus without any data)



Expand Down
8 changes: 0 additions & 8 deletions concatenate_files.sh

This file was deleted.

5 changes: 3 additions & 2 deletions script/concatenate_files.sh
Original file line number Diff line number Diff line change
@@ -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
8 changes: 4 additions & 4 deletions script/run-initialization.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
sleep 60s


# 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=$(/opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P $SA_PASSWORD -Q "SELECT COUNT(*) FROM master.dbo.sysdatabases WHERE name = N'$DB_NAME'" | tr -dc '0-9'| cut -c1 )
Expand All @@ -22,7 +22,7 @@ if [ ${data} -eq "0" ]; then
#/opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P $SA_PASSWORD -Q "DROP DATABASE IF EXISTS $DB_NAME"
/opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P $SA_PASSWORD -Q "CREATE DATABASE $DB_NAME"

if [ "$INIT_MODE" = "demo" ]; then
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
/opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P $SA_PASSWORD -i output/fullEmptyDatabase.sql -d $DB_NAME | grep . | uniq -c
Expand Down

0 comments on commit 6ad4856

Please sign in to comment.