Skip to content

Commit 21693fb

Browse files
samblesawsbuild
andauthored
Fix/1140 status db indexing (main) (#1144)
* apply index opts * Add status index_DB migration file * Add script to test DB migrations Add basic CI check for DB update miration fetch all commits to parse out last release Fix DB create script adjust permissions limit py env to server requ * Updated Package Requirements: waitress==3.0.1 * Fix CVE-2023-43804 --------- Co-authored-by: awsbuild <[email protected]>
1 parent 5a60810 commit 21693fb

File tree

6 files changed

+123
-3
lines changed

6 files changed

+123
-3
lines changed
+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: DB migration Test
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
workflow_dispatch:
9+
inputs:
10+
prev_release_tag:
11+
description: 'OasisPlatform tag [semvar]'
12+
required: false
13+
14+
workflow_call:
15+
inputs:
16+
prev_release_tag:
17+
description: 'Platform tag to set the DB migration from'
18+
required: false
19+
type: string
20+
platform_branch:
21+
description: "Platform branch to migrate to (remote trigger) [git ref]"
22+
required: True
23+
type: string
24+
25+
jobs:
26+
DB_migrate:
27+
runs-on: ubuntu-22.04
28+
env:
29+
PLAT_BRANCH: ${{ github.ref }}
30+
PREV_RELEASE_TAG: ${{ inputs.prev_release_tag }}
31+
32+
steps:
33+
- name: Branch selection (remote trigger)
34+
if: inputs.platform_branch != ''
35+
run: echo "PLAT_BRANCH=${{ inputs.platform_branch }}" >> $GITHUB_ENV
36+
37+
- name: Checkout
38+
uses: actions/checkout@v3
39+
with:
40+
repository: OasisLMF/OasisPlatform
41+
ref: ${{ env.PLAT_BRANCH }}
42+
fetch-depth: 0
43+
44+
- name: Find 'prev_release_tag'
45+
if: inputs.prev_release_tag == ''
46+
run: |
47+
tag=$( ./scripts/find_release.sh -t 1)
48+
echo "PREV_RELEASE_TAG=$tag" >> $GITHUB_ENV
49+
50+
- name: Create DB to migrate from
51+
run: |
52+
./scripts/create-db-sqlite3.sh ${{ env.PREV_RELEASE_TAG }}
53+
54+
- name: Set up Python 3.12
55+
uses: actions/setup-python@v4
56+
with:
57+
python-version: '3.12'
58+
- run: pip install -r requirements-server.txt
59+
60+
- name: Run Migration
61+
run: |
62+
python ./manage.py migrate

kubernetes/worker-controller/requirements.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ six==1.16.0
3838
# via
3939
# kubernetes-asyncio
4040
# python-dateutil
41-
urllib3==1.26.12
41+
urllib3==2.2.3
4242
# via kubernetes-asyncio
4343
websockets==10.3
4444
# via -r kubernetes/worker-controller/requirements.in

requirements.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,7 @@ vine==5.1.0
610610
# kombu
611611
virtualenv==20.27.0
612612
# via tox
613-
waitress==3.0.0
613+
waitress==3.0.1
614614
# via webtest
615615
wcwidth==0.2.13
616616
# via prompt-toolkit

scripts/create-db-sqlite3.sh

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/bin/bash
2+
3+
set -e
4+
function usage {
5+
echo "Usage: $0 <OasisPlatform Tag>, e.g. 2.3.10, or 1.28.9"
6+
echo
7+
echo " This script initializes an db.sqlite3 DB file, used for testing migration changes added to the platform."
8+
}
9+
10+
if [ -z "$1" ]; then
11+
usage
12+
exit 1
13+
else
14+
SERVER_TAG=$1
15+
fi
16+
17+
SERVER_IMAGE='coreoasis/api_server'
18+
SQL_FILE='src/server/oasisapi/db.sqlite3'
19+
ENTRY='/usr/bin/python3'
20+
CMD='manage.py migrate'
21+
#CMD='/bin/bash'
22+
23+
if [ -f $SQL_FILE ]; then
24+
echo "Found existing file $SQL_FILE - deleting and creating a empty file"
25+
rm -f $SQL_FILE
26+
fi
27+
touch $SQL_FILE
28+
chmod 777 $SQL_FILE
29+
30+
31+
echo "Creating a blank db.sqlite3 file for OasisPlatform $SERVER_TAG"
32+
echo
33+
docker run -e OASIS_SERVER_DB_ENGINE=django.db.backends.sqlite3 --entrypoint $ENTRY -v ./$SQL_FILE:/var/www/oasis/$SQL_FILE $SERVER_IMAGE:$SERVER_TAG $CMD
34+
echo "-- Done --"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Generated by Django 3.2.25 on 2024-11-25 14:07
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('analyses', '0014_merge_20240202_1452'),
10+
]
11+
12+
operations = [
13+
migrations.AlterField(
14+
model_name='analysis',
15+
name='status',
16+
field=models.CharField(choices=[('NEW', 'New'), ('INPUTS_GENERATION_ERROR', 'Inputs generation error'), ('INPUTS_GENERATION_CANCELLED', 'Inputs generation cancelled'), ('INPUTS_GENERATION_STARTED', 'Inputs generation started'), ('INPUTS_GENERATION_QUEUED', 'Inputs generation added to queue'), ('READY', 'Ready'), ('RUN_QUEUED', 'Run added to queue'), ('RUN_STARTED', 'Run started'), ('RUN_COMPLETED', 'Run completed'), ('RUN_CANCELLED', 'Run cancelled'), ('RUN_ERROR', 'Run error')], db_index=True, default='NEW', editable=False, max_length=27),
17+
),
18+
migrations.AlterField(
19+
model_name='analysistaskstatus',
20+
name='status',
21+
field=models.CharField(choices=[('PENDING', 'Task waiting to be added to the queue'), ('QUEUED', 'Task added to queue'), ('STARTED', 'Task started'), ('COMPLETED', 'Task completed'), ('CANCELLED', 'Task cancelled'), ('ERROR', 'Task error')], db_index=True, default='PENDING', editable=False, max_length=9),
22+
),
23+
]

src/server/oasisapi/analyses/models.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ class AnalysisTaskStatus(models.Model):
9494
choices=status_choices,
9595
default=status_choices.PENDING,
9696
editable=False,
97+
db_index=True,
9798
)
9899
pending_time = models.DateTimeField(null=True, auto_now_add=True, editable=False)
99100
queue_time = models.DateTimeField(null=True, default=None, editable=False)
@@ -166,7 +167,7 @@ class Analysis(TimeStampedModel):
166167
model = models.ForeignKey(AnalysisModel, on_delete=models.CASCADE, related_name='analyses', help_text=_('The model to link the analysis to'))
167168
name = models.CharField(help_text='The name of the analysis', max_length=255)
168169
status = models.CharField(max_length=max(len(c) for c in status_choices._db_values),
169-
choices=status_choices, default=status_choices.NEW, editable=False)
170+
choices=status_choices, default=status_choices.NEW, editable=False, db_index=True)
170171
run_mode = models.CharField(max_length=max(len(c) for c in run_mode_choices._db_values),
171172
choices=run_mode_choices, default=None, editable=False, null=True)
172173
task_started = models.DateTimeField(editable=False, null=True, default=None)

0 commit comments

Comments
 (0)