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

Alembic fix #111

Merged
merged 3 commits into from
Sep 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
41 changes: 41 additions & 0 deletions alembic_fix
@@ -0,0 +1,41 @@
#!/bin/bash

CONTAINER=$(docker ps -f name=graphql-postgres --format {{.Names}})
if [ -z $CONTAINER ]; then
echo "Could not find a running container for the database."
exit 1
fi


TABLE_EXISTS=$(docker exec $CONTAINER psql -d postgresql://postgres:onetask@graphql-postgres:5432 -c "SELECT COUNT(*) FROM pg_tables WHERE schemaname = 'public' AND tablename = 'alembic_version';" -qtAX)
if [ $TABLE_EXISTS -eq 0 ]
then
echo "Table alembic_version does not exist. Creating..."
docker exec $CONTAINER psql -d postgresql://postgres:onetask@graphql-postgres:5432 -c "CREATE TABLE alembic_version (version_num VARCHAR(32) NOT NULL, PRIMARY KEY (version_num))" -qtAX
echo "Table created."
else
return 0
fi


echo "Checking revision..."
if [ $(docker exec $CONTAINER psql -d postgresql://postgres:onetask@graphql-postgres:5432 -c "SELECT COUNT(*) FROM information_schema.columns WHERE table_name='attribute' and column_name='source_code';" -qtAX) -ne 0 ]
then
echo "Set revision to 87f463aa5112"
docker exec $CONTAINER psql -d postgresql://postgres:onetask@graphql-postgres:5432 -c "INSERT INTO alembic_version VALUES('87f463aa5112')" -qtAX
elif [ $(docker exec $CONTAINER psql -d postgresql://postgres:onetask@graphql-postgres:5432 -c "SELECT COUNT(*) FROM pg_tables WHERE schemaname = 'public' AND tablename = 'labeling_access_link';" -qtAX) -ne 0 ]
then
echo "Set revision to 9618924f9679"
docker exec $CONTAINER psql -d postgresql://postgres:onetask@graphql-postgres:5432 -c "INSERT INTO alembic_version VALUES('9618924f9679')" -qtAX
elif [ $(docker exec $CONTAINER psql -d postgresql://postgres:onetask@graphql-postgres:5432 -c "SELECT COUNT(*) FROM pg_tables WHERE schemaname = 'public' AND tablename = 'app_version';" -qtAX) -ne 0 ]
then
echo "Set revision to 5b3a4deea1c4"
docker exec $CONTAINER psql -d postgresql://postgres:onetask@graphql-postgres:5432 -c "INSERT INTO alembic_version VALUES('5b3a4deea1c4')" -qtAX
elif [ $(docker exec $CONTAINER psql -d postgresql://postgres:onetask@graphql-postgres:5432 -c "SELECT COUNT(*) FROM pg_tables WHERE schemaname = 'public' AND tablename = 'organization';" -qtAX) -ne 0 ]
then
echo "Set revision to 992352f4c1f9"
docker exec $CONTAINER psql -d postgresql://postgres:onetask@graphql-postgres:5432 -c "INSERT INTO alembic_version VALUES('992352f4c1f9')" -qtAX
else
echo "Nothing found assuming inital db"
docker exec $CONTAINER psql -d postgresql://postgres:onetask@graphql-postgres:5432 -c "DROP TABLE alembic_version" -qtAX
fi
94 changes: 94 additions & 0 deletions alembic_fix.bat
@@ -0,0 +1,94 @@
@echo off

SET name=initial
FOR /F "tokens=*" %%g IN ('"docker ps -f name=graphql-postgres --format {{.Names}}"') do (SET name=%%g)

IF "%name%" == "initial" (
echo cant find name
goto :eof
)

FOR /F "tokens=*" %%g IN ('docker exec %name% psql -d postgresql://postgres:onetask@graphql-postgres:5432 -c "SELECT COUNT(*) FROM pg_tables WHERE schemaname = 'public' AND tablename = 'alembic_version';" -qtAX') do (SET result=%%g)

IF "%result%" == "0" (
echo creating table
docker exec %name% psql -d postgresql://postgres:onetask@graphql-postgres:5432 -c "CREATE TABLE alembic_version (version_num VARCHAR(32) NOT NULL, PRIMARY KEY (version_num))" -qtAX
echo table created
) ELSE (
goto :eof
)

goto VERSION_87f463aa5112



:END

goto :eof

:VERSION_87f463aa5112

echo checking version 87f463aa5112

FOR /F "tokens=*" %%g IN ('docker exec %name% psql -d postgresql://postgres:onetask@graphql-postgres:5432 -c "SELECT COUNT(*) FROM information_schema.columns WHERE table_name='attribute' and column_name='source_code';" -qtAX') do (SET result=%%g)

IF "%result%" == "0" (
goto VERSION_9618924f9679
) ELSE (
Call :setVersion 87f463aa5112
goto END
)

:VERSION_9618924f9679
echo checking version 9618924f9679
FOR /F "tokens=*" %%g IN ('docker exec %name% psql -d postgresql://postgres:onetask@graphql-postgres:5432 -c "SELECT COUNT(*) FROM pg_tables WHERE schemaname = 'public' AND tablename = 'labeling_access_link';" -qtAX') do (SET result=%%g)

IF "%result%" == "0" (
goto VERSION_5b3a4deea1c4
) ELSE (
Call :setVersion 9618924f9679
goto END
)

:VERSION_5b3a4deea1c4
echo checking version 5b3a4deea1c4
FOR /F "tokens=*" %%g IN ('docker exec %name% psql -d postgresql://postgres:onetask@graphql-postgres:5432 -c "SELECT COUNT(*) FROM pg_tables WHERE schemaname = 'public' AND tablename = 'app_version';" -qtAX') do (SET result=%%g)

IF "%result%" == "0" (
goto VERSION_992352f4c1f9
) ELSE (
Call :setVersion 5b3a4deea1c4
goto END
)

:VERSION_992352f4c1f9
echo checking version 992352f4c1f9
FOR /F "tokens=*" %%g IN ('docker exec %name% psql -d postgresql://postgres:onetask@graphql-postgres:5432 -c "SELECT COUNT(*) FROM pg_tables WHERE schemaname = 'public' AND tablename = 'organization';" -qtAX') do (SET result=%%g)

IF "%result%" == "0" (
goto NO_VERSION
) ELSE (
Call :setVersion 992352f4c1f9
goto END
)

:NO_VERSION
echo nothing found assuming inital db
docker exec %name% psql -d postgresql://postgres:onetask@graphql-postgres:5432 -c "DROP TABLE alembic_version" -qtAX
goto END


:setVersion
Set "version=%~1"

FOR /F "tokens=*" %%g IN ('docker exec %name% psql -d postgresql://postgres:onetask@graphql-postgres:5432 -c "SELECT COUNT(*) FROM alembic_version;" -qtAX') do (SET result=%%g)

IF "%result%" == "0" (
echo setting version to %version%
docker exec %name% psql -d postgresql://postgres:onetask@graphql-postgres:5432 -c "INSERT INTO alembic_version VALUES('%version%')" -qtAX
echo version is %version%
)



EXIT /B 0
8 changes: 3 additions & 5 deletions start
@@ -1,10 +1,5 @@
#!/bin/bash

echo "We are currently experiencing some issues with refinery."
echo "We are working on it. Sorry, for the inconvenience."
echo "If you pull the repository and this message is still there, please try to pull it at a later time."
exit 1

LOCAL_VOLUME_POSTGRES=./postgres-data
LOCAL_VOLUME_MINIO=./minio-data
LOCAL_VOLUME_QDRANT=./qdrant-storage
Expand Down Expand Up @@ -49,6 +44,9 @@ if [ ! -f "./refinery/oathkeeper/jwks.json" ]; then
docker run --rm docker.io/oryd/oathkeeper:v0.38 credentials generate --alg RS256 > refinery/oathkeeper/jwks.json
fi

source wait_until_db_ready
source alembic_fix

docker-compose -f refinery/docker-compose.yml up -d

echo "UI: http://localhost:4455/app/"
Expand Down
7 changes: 2 additions & 5 deletions start.bat
@@ -1,11 +1,6 @@
@echo off
setlocal enabledelayedexpansion

echo "We are currently experiencing some issues with refinery."
echo "We are working on it. Sorry, for the inconvenience."
echo "If you pull the repository and this message is still there, please try to pull it at a later time."
exit 1

set LOCAL_VOLUME_POSTGRES=".\postgres-data"
set LOCAL_VOLUME_MINIO=".\minio-data"
set LOCAL_VOLUME_QDRANT=".\qdrant-storage"
Expand Down Expand Up @@ -68,6 +63,8 @@ IF NOT EXIST .\refinery\oathkeeper\jwks.json (
docker run --rm docker.io/oryd/oathkeeper:v0.38 credentials generate --alg RS256 > refinery\oathkeeper\jwks.json
)

call wait_until_db_ready.bat
call alembic_fix.bat

docker-compose -f refinery\docker-compose.yml up -d

Expand Down
5 changes: 0 additions & 5 deletions stop
@@ -1,8 +1,3 @@
#!/bin/bash

echo "We are currently experiencing some issues with refinery."
echo "We are working on it. Sorry, for the inconvenience."
echo "If you pull the repository and this message is still there, please try to pull it at a later time."
exit 1

docker-compose -f refinery/docker-compose.yml down --remove-orphans
4 changes: 0 additions & 4 deletions stop.bat
@@ -1,9 +1,5 @@
@echo off

echo "We are currently experiencing some issues with refinery."
echo "We are working on it. Sorry, for the inconvenience."
echo "If you pull the repository and this message is still there, please try to pull it at a later time."
exit 1

docker-compose -f refinery\docker-compose.yml down --remove-orphans
if "%1" neq "update" pause
5 changes: 0 additions & 5 deletions update
@@ -1,10 +1,5 @@
#!/bin/bash

echo "We are currently experiencing some issues with refinery."
echo "We are working on it. Sorry, for the inconvenience."
echo "If you pull the repository and this message is still there, please try to pull it at a later time."
exit 1

echo "Checking refinery installation..."
if test -f "./refinery/docker-compose.yml"; then
echo "Refinery is installed."
Expand Down
4 changes: 0 additions & 4 deletions update.bat
@@ -1,10 +1,6 @@
@echo off
setlocal enabledelayedexpansion

echo "We are currently experiencing some issues with refinery."
echo "We are working on it. Sorry, for the inconvenience."
echo "If you pull the repository and this message is still there, please try to pull it at a later time."
exit 1

echo Checking refinery installation...
if exist "%~dp0\refinery\docker-compose.yml" (
Expand Down
19 changes: 19 additions & 0 deletions wait_until_db_ready
@@ -0,0 +1,19 @@
#!/bin/bash
echo "Starting db..."

docker-compose -f refinery/docker-compose.yml up -d graphql-postgres

CONTAINER=$(docker ps -f name=graphql-postgres --format {{.Names}})
if [ -z $CONTAINER ]; then
echo "Could not find a running container for the database."
exit 1
fi

echo "Waiting for container to be ready..."
docker exec $CONTAINER pg_isready > /dev/null 2>&1
while [ $? -ne 0 ]
do
docker exec $CONTAINER pg_isready > /dev/null 2>&1
done

echo "db ready"
25 changes: 25 additions & 0 deletions wait_until_db_ready.bat
@@ -0,0 +1,25 @@
@echo off

echo starting db...

docker-compose -f refinery\docker-compose.yml up -d graphql-postgres

SET name=initial
FOR /F "tokens=*" %%g IN ('"docker ps -f name=graphql-postgres --format {{.Names}}"') do (SET name=%%g)

IF "%name%" == "initial" (
echo cant find name
goto :eof
)

echo waiting for pg_isready...

:RECHECK
docker exec %name% pg_isready > nul
IF %ERRORLEVEL% NEQ 0 (
timeout 1 > nul
goto RECHECK
)

echo db ready.