|
| 1 | +@echo off |
| 2 | + |
| 3 | +SET name=initial |
| 4 | +FOR /F "tokens=*" %%g IN ('"docker ps -f name=graphql-postgres --format {{.Names}}"') do (SET name=%%g) |
| 5 | + |
| 6 | +IF "%name%" == "initial" ( |
| 7 | + echo cant find name |
| 8 | + goto :eof |
| 9 | +) |
| 10 | + |
| 11 | +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) |
| 12 | + |
| 13 | +IF "%result%" == "0" ( |
| 14 | + echo creating table |
| 15 | + 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 |
| 16 | + echo table created |
| 17 | +) ELSE ( |
| 18 | + goto :eof |
| 19 | +) |
| 20 | + |
| 21 | +goto VERSION_87f463aa5112 |
| 22 | + |
| 23 | + |
| 24 | + |
| 25 | +:END |
| 26 | + |
| 27 | +goto :eof |
| 28 | + |
| 29 | +:VERSION_87f463aa5112 |
| 30 | + |
| 31 | +echo checking version 87f463aa5112 |
| 32 | + |
| 33 | +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) |
| 34 | + |
| 35 | +IF "%result%" == "0" ( |
| 36 | + goto VERSION_9618924f9679 |
| 37 | +) ELSE ( |
| 38 | + Call :setVersion 87f463aa5112 |
| 39 | + goto END |
| 40 | +) |
| 41 | + |
| 42 | +:VERSION_9618924f9679 |
| 43 | +echo checking version 9618924f9679 |
| 44 | +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) |
| 45 | + |
| 46 | +IF "%result%" == "0" ( |
| 47 | + goto VERSION_5b3a4deea1c4 |
| 48 | +) ELSE ( |
| 49 | + Call :setVersion 9618924f9679 |
| 50 | + goto END |
| 51 | +) |
| 52 | + |
| 53 | +:VERSION_5b3a4deea1c4 |
| 54 | +echo checking version 5b3a4deea1c4 |
| 55 | +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) |
| 56 | + |
| 57 | +IF "%result%" == "0" ( |
| 58 | + goto VERSION_992352f4c1f9 |
| 59 | +) ELSE ( |
| 60 | + Call :setVersion 5b3a4deea1c4 |
| 61 | + goto END |
| 62 | +) |
| 63 | + |
| 64 | +:VERSION_992352f4c1f9 |
| 65 | +echo checking version 992352f4c1f9 |
| 66 | +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) |
| 67 | + |
| 68 | +IF "%result%" == "0" ( |
| 69 | + goto NO_VERSION |
| 70 | +) ELSE ( |
| 71 | + Call :setVersion 992352f4c1f9 |
| 72 | + goto END |
| 73 | +) |
| 74 | + |
| 75 | +:NO_VERSION |
| 76 | +echo nothing found assuming inital db |
| 77 | +docker exec %name% psql -d postgresql://postgres:onetask@graphql-postgres:5432 -c "DROP TABLE alembic_version" -qtAX |
| 78 | +goto END |
| 79 | + |
| 80 | + |
| 81 | +:setVersion |
| 82 | +Set "version=%~1" |
| 83 | + |
| 84 | +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) |
| 85 | + |
| 86 | +IF "%result%" == "0" ( |
| 87 | + echo setting version to %version% |
| 88 | + docker exec %name% psql -d postgresql://postgres:onetask@graphql-postgres:5432 -c "INSERT INTO alembic_version VALUES('%version%')" -qtAX |
| 89 | + echo version is %version% |
| 90 | +) |
| 91 | + |
| 92 | + |
| 93 | + |
| 94 | +EXIT /B 0 |
0 commit comments