-
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #830 from openzim/missing_schedule_name
Fix missing schedule name
- Loading branch information
Showing
21 changed files
with
381 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
FROM node:14-alpine as builder | ||
|
||
RUN apk --no-cache add yarn python3 | ||
WORKDIR /app | ||
COPY entrypoint.sh /usr/local/bin/entrypoint.sh | ||
COPY package.json yarn.lock /app/ | ||
RUN yarn install && yarn cache clean | ||
COPY *.js /app/ | ||
COPY public /app/public | ||
COPY src /app/src | ||
ENV ENVIRON_PATH /app/public/environ.json | ||
ENTRYPOINT [ "entrypoint.sh" ] | ||
CMD ["yarn", "serve", "--host", "0.0.0.0", "--port", "80"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"Just some test instructions, useful for instance to dry run SQLAlchemy code" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import os\n", | ||
"from pathlib import Path\n", | ||
"if os.getcwd().endswith(\"/dev\"):\n", | ||
" os.chdir(Path(os.getcwd()) / Path(\"../dispatcher/backend/src\"))" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 2, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"env: POSTGRES_URI=postgresql+psycopg://zimfarm:zimpass@localhost:5432/zimfarm\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"%env POSTGRES_URI=postgresql+psycopg://zimfarm:zimpass@localhost:5432/zimfarm\n", | ||
"\n", | ||
"import json\n", | ||
"import pathlib\n", | ||
"import sqlalchemy as sa\n", | ||
"import sqlalchemy.orm as so\n", | ||
"\n", | ||
"from db import Session\n", | ||
"from db.models import Schedule, RequestedTask" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 3, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"UPDATE requested_task SET original_schedule_name=(SELECT schedule.name \n", | ||
"FROM schedule \n", | ||
"WHERE schedule.id = requested_task.schedule_id) WHERE requested_task.schedule_id IS NOT NULL\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"stmt = (\n", | ||
" sa.update(RequestedTask)\n", | ||
" .where(\n", | ||
" RequestedTask.schedule_id != None\n", | ||
" )\n", | ||
" .values(original_schedule_name=sa.select(Schedule.name).where(Schedule.id == RequestedTask.schedule_id).scalar_subquery())\n", | ||
")\n", | ||
"print(stmt)" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "venv", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.8.17" | ||
}, | ||
"orig_nbformat": 4 | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
dispatcher/backend/src/migrations/versions/43f385b318d4_add_original_schedule_name.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
"""add_original_schedule_name | ||
Revision ID: 43f385b318d4 | ||
Revises: 15354d56545a | ||
Create Date: 2023-09-26 07:56:45.008277 | ||
""" | ||
import sqlalchemy as sa | ||
from alembic import op | ||
|
||
from db.models import RequestedTask, Schedule, Task | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = "43f385b318d4" | ||
down_revision = "15354d56545a" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade() -> None: | ||
bind = op.get_bind() | ||
session = sa.orm.Session(bind=bind) | ||
|
||
# add original_schedule_name as nullable | ||
op.add_column( | ||
"requested_task", | ||
sa.Column("original_schedule_name", sa.String(), nullable=True), | ||
) | ||
|
||
# set original_schedule_name for requested tasks with existing schedule | ||
session.execute( | ||
sa.update(RequestedTask) | ||
.where(RequestedTask.schedule_id is not None) | ||
.values( | ||
original_schedule_name=sa.select(Schedule.name) | ||
.where(Schedule.id == RequestedTask.schedule_id) | ||
.scalar_subquery() | ||
) | ||
) | ||
|
||
# set original_schedule_name for requested tasks without existing schedule | ||
session.execute( | ||
sa.update(RequestedTask) | ||
.where(RequestedTask.schedule_id is None) | ||
.values(original_schedule_name="<unknown>") | ||
) | ||
|
||
# set original_schedule_name as not nullable | ||
op.alter_column("requested_task", "original_schedule_name", nullable=False) | ||
|
||
# add original_schedule_name as nullable | ||
op.add_column( | ||
"task", sa.Column("original_schedule_name", sa.String(), nullable=True) | ||
) | ||
|
||
# set original_schedule_name for requested tasks with existing schedule | ||
session.execute( | ||
sa.update(Task) | ||
.where(Task.schedule_id is not None) | ||
.values( | ||
original_schedule_name=sa.select(Schedule.name) | ||
.where(Schedule.id == Task.schedule_id) | ||
.scalar_subquery() | ||
) | ||
) | ||
|
||
# set original_schedule_name for requested tasks without existing schedule | ||
session.execute( | ||
sa.update(Task) | ||
.where(Task.schedule_id is None) | ||
.values(original_schedule_name="<unknown>") | ||
) | ||
|
||
# set original_schedule_name as not nullable | ||
op.alter_column("task", "original_schedule_name", nullable=False) | ||
|
||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.drop_column("task", "original_schedule_name") | ||
op.drop_column("requested_task", "original_schedule_name") | ||
# ### end Alembic commands ### |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.