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

Develop doc #991

Open
wants to merge 10 commits into
base: develop
Choose a base branch
from
4 changes: 2 additions & 2 deletions documentation/3.1.0/dockerized/MentorEd-Setup-README.md
Original file line number Diff line number Diff line change
Expand Up @@ -287,13 +287,13 @@ There ar few forms required for mentoting application to run, to add those fallo

- **Ubuntu/Linux/Mac**
```
./insert_sample_forms.sh mentoring postgres://postgres:postgres@citus_master:5432/mentoring
./sample-data/mentoring/insert_sample_forms.sh mentoring postgres://postgres:postgres@citus_master:5432/mentoring
```

- **Windows**

```
insert_sample_forms.bat mentoring postgres://postgres:postgres@citus_master:5432/mentoring
sample-data\mentoring\insert_sample_forms.bat mentoring postgres://postgres:postgres@citus_master:5432/mentoring
```

After successfully running the script, forms will be added to database.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,64 +1,60 @@
@echo off
setlocal

:: Exit on error
setlocal EnableDelayedExpansion

:: Define the GitHub raw URL for the JSON file
set "GITHUB_REPO=https://raw.githubusercontent.com/ELEVATE-Project/mentoring-mobile-app/refs/heads/release-3.1.1/forms.json"
set "JSON_FILE=forms.json"

:: set organization_id
:: Set organization_id
set "organization_id=1"


:: Check if the output directory is passed as an argument, otherwise use the current directory
:: Check if output directory is provided as an argument
if "%~2"=="" (
set "OUTPUT_DIR=."
) else (
set "OUTPUT_DIR=%~2"
)

:: Ensure the directory exists
if not exist "!OUTPUT_DIR!" (
echo Error: Directory '!OUTPUT_DIR!' does not exist.
:: Ensure the output directory exists
if not exist "%OUTPUT_DIR%" (
echo Error: Directory '%OUTPUT_DIR%' does not exist.
exit /b 1
)

:: Define the output file path in the specified directory
set "SQL_OUTPUT_FILE=!OUTPUT_DIR!\forms.sql"
:: Define output file path for the SQL file
set "SQL_OUTPUT_FILE=%OUTPUT_DIR%\forms.sql"

:: Fetch the JSON file from the GitHub repository
:: Fetch JSON file from GitHub repository
echo Fetching JSON file from GitHub...
curl -o "!JSON_FILE!" "!GITHUB_REPO!"
curl -o "%JSON_FILE%" "%GITHUB_REPO%"

:: Check if the download was successful
:: Check if download was successful
if errorlevel 1 (
echo Failed to download JSON file from GitHub.
exit /b 1
)

:: Append 'SELECT NULL;' to the end of the SQL file
echo delete from forms; > "!SQL_OUTPUT_FILE!"

:: Create or overwrite the SQL output file
:: Write initial SQL delete statement to clear existing data in 'forms' table
echo delete from forms; > "%SQL_OUTPUT_FILE%"
echo Generating SQL insert statements...
>> "!SQL_OUTPUT_FILE!" (
echo.

:: Initialize ID counter starting from 1
set /a id_counter=1

:: Use PowerShell to parse JSON and generate SQL
for /f "usebackq delims=" %%i in (`powershell -command "Get-Content '!JSON_FILE!' | ConvertFrom-Json | ForEach-Object { 'INSERT INTO forms (id, type, sub_type, data, version, organization_id) VALUES (' + [int]$env:id_counter + ', ''$($_.type)'', ''$($_.sub_type)'', ''$($_.data | ConvertTo-Json -Compress -Depth 100)'', 1, ''!organization_id!'');' }"`) do (
echo %%i
set /a id_counter+=1
)
)

:: Append 'SELECT NULL;' to the end of the SQL file
echo SELECT NULL; >> "!SQL_OUTPUT_FILE!"

echo SQL file generated: "!SQL_OUTPUT_FILE!"

:: Initialize ID counter
set /a id_counter=1

:: Use PowerShell to parse JSON and generate a separate SQL insert statement for each object
powershell -Command ^
"$jsonData = Get-Content '%JSON_FILE%' | ConvertFrom-Json; " ^
"$id_counter = 1; " ^
"$jsonData | ForEach-Object { " ^
"$current_timestamp = (Get-Date -Format 'yyyy-MM-dd HH:mm:ss'); " ^
"$sql = 'INSERT INTO forms (id, type, sub_type, data, version, organization_id, created_at, updated_at) VALUES (' + $id_counter.ToString() + ', ''' + $_.type + ''', ''' + $_.sub_type + ''', ''';" ^
"$sql += ($_.data | ConvertTo-Json -Compress -Depth 100).Replace(\"'\", \"''\") + ''', 1, %organization_id%, ''' + $current_timestamp + ''', ''' + $current_timestamp + ''');'; " ^
"Add-Content -Path '%SQL_OUTPUT_FILE%' -Value $sql; " ^
"$id_counter += 1; " ^
"}"

:: Append a final statement to the SQL file
echo SELECT NULL; >> "%SQL_OUTPUT_FILE%"

echo SQL file generated: "%SQL_OUTPUT_FILE%"
endlocal
166 changes: 99 additions & 67 deletions documentation/3.1.0/dockerized/scripts/windows/insert_sample_forms.bat
Original file line number Diff line number Diff line change
@@ -1,107 +1,139 @@
@echo off
setlocal enabledelayedexpansion

REM Exit on error
set "ERRORLEVEL=0"

REM Ensure correct number of arguments are provided
:: Ensure the correct number of arguments are provided
if "%~2"=="" (
echo Error: Folder name and database URL not provided. Usage: %0 <folder_name> <database_url>
echo Error: Folder name and database URL not provided. Usage: %0 &lt;folder_name&gt; &lt;database_url&gt;
exit /b 1
)

REM Use the provided folder name
:: Use the provided folder name
set "FOLDER_NAME=sample-data\%~1"

REM Check if folder exists
if not exist "!FOLDER_NAME!" (
echo Error: Folder '!FOLDER_NAME!' not found.
:: Check if folder exists
if not exist "%FOLDER_NAME%" (
echo Error: Folder '%FOLDER_NAME%' not found.
exit /b 1
)

REM Use the provided database URL
:: Use the provided database URL
set "DEV_DATABASE_URL=%~2"

REM Extract database credentials and connection details using for
for /f "tokens=4,5,6,7 delims=:@/" %%a in ("%DEV_DATABASE_URL%") do (
set "DB_USER=%%a"
set "DB_PASSWORD=%%b"
set "DB_HOST=%%c"
set "DB_PORT=%%d"
)
set "conn=%DEV_DATABASE_URL%"

REM Extract DB_NAME
for /f "tokens=*" %%a in ("%DEV_DATABASE_URL%") do (
for /f "delims=/ tokens=2" %%b in ("%%a") do set "DB_NAME=%%b"
)
set "conn=!conn:postgres://=!"

for /f "tokens=1 delims=:" %%a in ("!conn!") do set "DB_USER=%%a"

set "conn=!conn:%DB_USER%:=!"

for /f "tokens=1 delims=@" %%a in ("!conn!") do set "DB_PASSWORD=%%a"

set "conn=!conn:%DB_PASSWORD%@=!"

set "hostport=!conn:*@=!"
for /f "tokens=1 delims=:" %%a in ("!hostport!") do set "DB_HOST=%%a"

REM Log database variables
echo Extracted Database Variables:
echo DB_USER: !DB_USER!
echo DB_PASSWORD: !DB_PASSWORD!
echo DB_HOST: !DB_HOST!
echo DB_PORT: !DB_PORT!
echo DB_NAME: !DB_NAME!

REM Define the container name (same as DB_HOST)
set "CONTAINER_NAME=!DB_HOST!"

REM Wait for Docker container to be up
echo Waiting for Docker container '!CONTAINER_NAME!' to be up...
:waitForContainer
docker inspect "!CONTAINER_NAME!" >nul 2>&1
set "conn=!conn:%DB_HOST%:=!"

for /f "tokens=1 delims=/" %%a in ("!conn!") do set "DB_PORT=%%a"

set "conn=!conn:*%DB_PORT%/=!"

set "DB_NAME=!conn!"

echo DB_USER: %DB_USER%
echo DB_PASSWORD: %DB_PASSWORD%
echo DB_HOST: %DB_HOST%
echo DB_PORT: %DB_PORT%
echo DB_NAME: %DB_NAME%

:: Define the container name (same as DB_HOST)
set "CONTAINER_NAME=%DB_HOST%"

:: Wait for Docker container to be up
echo Waiting for Docker container '%CONTAINER_NAME%' to be up...
:WAIT_CONTAINER
docker inspect "%CONTAINER_NAME%" >nul 2>&1
if errorlevel 1 (
echo Waiting for container...
timeout /t 1 >nul
goto waitForContainer
timeout /t 1 /nobreak
goto WAIT_CONTAINER
)
echo Container is now up.

REM Wait for PostgreSQL to be ready to accept connections
echo Waiting for PostgreSQL on '!DB_HOST!:!DB_PORT!' to accept connections...
:waitForDB
docker exec "!CONTAINER_NAME!" pg_isready -h localhost -p !DB_PORT! -U !DB_USER! >nul 2>&1
:: Wait for PostgreSQL to be ready to accept connections
echo Waiting for PostgreSQL on '%DB_HOST%:%DB_PORT%' to accept connections...
:WAIT_DB
docker exec "%CONTAINER_NAME%" bash -c "pg_isready -h localhost -p %DB_PORT% -U %DB_USER%" >nul 2>&1
if errorlevel 1 (
echo Waiting for database to be ready...
timeout /t 1 >nul
goto waitForDB
timeout /t 1 /nobreak
goto WAIT_DB
)
echo Database is ready.

REM Function to check if the database exists
:checkDatabase
docker exec "!CONTAINER_NAME!" psql -h localhost -U !DB_USER! -p !DB_PORT! -lqt | findstr /i /c:"!DB_NAME!" >nul
exit /b %errorlevel%

echo Checking existence of database '!DB_NAME!'...
:waitForDBExistence
call :checkDatabase
:: Check if the database exists
:CHECK_DB
docker exec "%CONTAINER_NAME%" bash -c "PGPASSWORD='%DB_PASSWORD%' psql -h localhost -U %DB_USER% -p %DB_PORT% -lqt | cut -d \| -f 1 | grep -qw '%DB_NAME%'" >nul 2>&1
if errorlevel 1 (
echo Database '!DB_NAME!' does not exist, waiting...
timeout /t 5 >nul
goto waitForDBExistence
echo Database '%DB_NAME%' does not exist, waiting...
timeout /t 5 /nobreak
goto CHECK_DB
)
echo Database '!DB_NAME!' exists, proceeding with script.
echo Database '%DB_NAME%' exists, proceeding with script.

REM ------------------------------------------------------------
REM New code to push `forms.sql` data into the database
REM ------------------------------------------------------------
:: Retrieve and prepare SQL file operations
set "SAMPLE_COLUMNS_FILE=%FOLDER_NAME%\sampleData.sql"
if not exist "%SAMPLE_COLUMNS_FILE%" (
echo Error: sampleData.sql not found in folder '%FOLDER_NAME%'.
exit /b 1
)

set "DEFAULT_FORM_FOLDER_LOCATION=!FOLDER_NAME!"
:: Copy the SQL file into the Docker container
echo Copying sampleData.sql to container '%CONTAINER_NAME%'...
docker cp "%SAMPLE_COLUMNS_FILE%" "%CONTAINER_NAME%:/sampleData.sql"

REM Ensure create_default_form_sql.bat is executable
call create_default_form_sql.bat "!FOLDER_NAME!"
:: Execute the SQL file inside the container
echo Executing sampleData.sql in the database...
docker exec "%CONTAINER_NAME%" bash -c "PGPASSWORD='%DB_PASSWORD%' psql -h localhost -U %DB_USER% -d %DB_NAME% -p %DB_PORT% -f /sampleData.sql"
if errorlevel 1 (
echo Error executing SQL script.
exit /b 1
) else (
echo SQL script executed successfully.
)

echo Sample Data Insertion Completed

:: New code to push `forms.sql` data into the database
set "DEFAULT_ORG_ID=%~1"
set "FORMS_SQL_FILE=forms.sql"
if not exist "!FORMS_SQL_FILE!" (
echo Error: forms.sql not found.


:: Check if the create_default_form_sql.sh script exists
if not exist "create_default_form_sql.bat" (
echo Error: create_default_form_sql.bat not found.
exit /b 1
)

echo Copying forms.sql to container '!CONTAINER_NAME!'...
docker cp "!FORMS_SQL_FILE!" "!CONTAINER_NAME!:/forms.sql"
:: Run the create_default_form_sql.sh script with the provided arguments
echo Running create_default_form_sql.bat...
bash create_default_form_sql.bat "%ORGANIZATION_ID%" "%FOLDER_NAME%"

if errorlevel 1 (
echo Error running create_default_form_sql.bat.
exit /b 1
) else (
echo create_default_form_sql.bat executed successfully.
)

echo Copying forms.sql to container '%CONTAINER_NAME%'...
docker cp "%FORMS_SQL_FILE%" "%CONTAINER_NAME%:/forms.sql"

echo Inserting Forms Data from forms.sql...
docker exec --user "!DB_USER!" "!CONTAINER_NAME!" psql -h localhost -U !DB_USER! -d !DB_NAME! -p !DB_PORT! -f /forms.sql
docker exec --user "%DB_USER%" "%CONTAINER_NAME%" bash -c "PGPASSWORD='%DB_PASSWORD%' psql -h localhost -U %DB_USER% -d %DB_NAME% -p %DB_PORT% -f /forms.sql"

echo Forms Data Insertion Completed

endlocal
4 changes: 2 additions & 2 deletions documentation/3.1.0/native/MentorEd-Setup-README.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ Before setting up the application, the dependencies should be installed and veri
git clone -b release-3.1.0 https://github.com/ELEVATE-Project/mentoring.git && \
git clone -b release-3.1.0 https://github.com/ELEVATE-Project/user.git && \
git clone -b release-3.1.0 https://github.com/ELEVATE-Project/notification.git && \
git clone -b release-3.1.1 https://github.com/ELEVATE-Project/interface-service.git && \
git clone -b release-3.1.0 https://github.com/ELEVATE-Project/interface-service.git && \
git clone -b release-3.1.0 https://github.com/ELEVATE-Project/scheduler.git && \
git clone -b release-3.1.1 https://github.com/ELEVATE-Project/mentoring-mobile-app.git
```
Expand All @@ -199,7 +199,7 @@ Before setting up the application, the dependencies should be installed and veri
git clone -b release-3.1.0 https://github.com/ELEVATE-Project/mentoring.git & ^
git clone -b release-3.1.0 https://github.com/ELEVATE-Project/user.git & ^
git clone -b release-3.1.0 https://github.com/ELEVATE-Project/notification.git & ^
git clone -b release-3.1.1 https://github.com/ELEVATE-Project/interface-service.git & ^
git clone -b release-3.1.0 https://github.com/ELEVATE-Project/interface-service.git & ^
git clone -b release-3.1.0 https://github.com/ELEVATE-Project/scheduler.git & ^
git clone -b release-3.1.1 https://github.com/ELEVATE-Project/mentoring-mobile-app.git
```
Expand Down
7 changes: 3 additions & 4 deletions documentation/3.1.0/native/envs/interface_env
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
API_DOC_URL=/elevate-interface/api-doc
APPLICATION_ENV=development
APPLICATION_PORT=3569
INSTALLED_PACKAGES=elevate-user elevate-mentoring elevate-scheduler
INSTALLED_PACKAGES=elevate-user elevate-mentoring elevate-scheduler elevate-project elevate-entity-management elevate-self-creation-portal elevate-survey
MENTORING_SERVICE_BASE_URL=http://localhost:3000
NOTIFICATION_SERVICE_BASE_URL=http://localhost:3002
RATE_LIMITER_ENABLED=true
RATE_LIMITER_NUMBER_OF_PROXIES=0
REQUIRED_BASE_PACKAGES=elevate-user elevate-mentoring elevate-scheduler
REQUIRED_PACKAGES=elevate-user@1.1.71 elevate-mentoring@1.1.56 elevate-scheduler@1.0.4
ROUTE_CONFIG_JSON_URLS_PATHS=https://raw.githubusercontent.com/ELEVATE-Project/user/develop/src/constants/interface-routes/configs.json,https://raw.githubusercontent.com/ELEVATE-Project/mentoring/release-3.2.0/src/constants/interface-routes/configs.json,https://raw.githubusercontent.com/ELEVATE-Project/scheduler/develop/src/constants/interface-routes/configs.json
REQUIRED_PACKAGES=elevate-user@1.1.71 elevate-mentoring@1.1.56 elevate-scheduler@1.0.4 elevate-project@1.1.16 elevate-entity-management@1.0.7 elevate-self-creation-portal@1.0.30 elevate-survey@1.0.27
SCHEDULER_SERVICE_BASE_URL=http://localhost:4000
SUPPORTED_HTTP_TYPES="GET POST PUT PATCH DELETE"
USER_SERVICE_BASE_URL=http://localhost:3001
SELF_CREATION_PORTAL_SERVICE_BASE_URL=http://localhost:3006
ALLOWED_HOST="*"
INTERNAL_ACCESS_TOKEN=internal_access_token
14 changes: 9 additions & 5 deletions documentation/3.1.0/native/envs/non-citus/user_env
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
ACCESS_TOKEN_EXPIRY=30m
ACCESS_TOKEN_SECRET=xG7V87nfj2394fJD394jfgh08dfDfh98DKJlndfj9d # Replace with your secure secret
# Replace with your secure secret
ACCESS_TOKEN_SECRET=xG7V87nfj2394fJD394jfgh08dfDfh98DKJlndfj9d
ADMIN_INVITEE_UPLOAD_EMAIL_TEMPLATE_CODE=invitee_upload_status
ADMIN_SECRET_CODE=N0DM5NAwwCN5KNXKJwlwu6c0nQQt6Rcl # Replace with secure admin secret code
# Replace with secure admin secret code
ALLOWED_HOST="*"
ADMIN_SECRET_CODE=N0DM5NAwwCN5KNXKJwlwu6c0nQQt6Rcl
API_DOC_URL=/user/api-doc
APPLICATION_BASE_URL=/user
APPLICATION_ENV=development
Expand All @@ -25,7 +27,7 @@ DEFAULT_ORGANISATION_CODE=default_code
DEFAULT_ORG_ID=1
DEFAULT_QUEUE=queue
DEFAULT_ROLE=mentee
DEV_DATABASE_URL=postgres://postgres:postgres@localhost:5432/users
DEV_DATABASE_URL=postgres://postgres:postgres@localhost:9700/users
DISABLE_LOG=false
EMAIL_ID_ENCRYPTION_ALGORITHM="aes-256-cbc"
EMAIL_ID_ENCRYPTION_IV=c9c7bd480494409071847264652f5c95
Expand Down Expand Up @@ -57,10 +59,12 @@ OTP_EMAIL_TEMPLATE_CODE=emailotp
OTP_EXP_TIME=86400
PORTAL_URL=https://mentored.some.org/auth/login
PUBLIC_ASSET_BUCKETNAME="public-bucket"
RECAPTCHA_SECRET_KEY=6LfWEKYpAAAAAJS0eukS2Su # Replace with secure Recaptcha secret key
REDIS_HOST=redis://localhost:6379
# Replace with secure Recaptcha secret key
RECAPTCHA_SECRET_KEY=6LfWEKYpAAAAAJS0eukS2Su
REFRESH_TOKEN_EXPIRY=7
REFRESH_TOKEN_SECRET=371hkjkjady2y3ihdkajshdkiq23iuekw71 # Replace with secure refresh token secret
# Replace with secure refresh token secret
REFRESH_TOKEN_SECRET=371hkjkjady2y3ihdkajshdkiq23iuekw71
REFRESH_VIEW_INTERVAL=540000
REGISTRATION_EMAIL_TEMPLATE_CODE=registration
REGISTRATION_OTP_EMAIL_TEMPLATE_CODE=registrationotp
Expand Down
Loading