Skip to content

Commit c1d2334

Browse files
committed
-added missing migration after changing field length
-upgraded isort and configured pyproject to support proper python version -added postgresql DB and config -added Makefile to prepare-venv, create-migrations and migrate
1 parent 4ff871a commit c1d2334

File tree

10 files changed

+116
-10
lines changed

10 files changed

+116
-10
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
venv
22
__pycache__
3+
.idea
34
web/**/*.sqlite3
45
**/.env

Makefile

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
VENV_DIR := venv
2+
3+
prepare-venv:
4+
@command -v pyenv >/dev/null 2>&1 || { echo "pyenv not installed"; exit 1; }
5+
pyenv install -s
6+
python -m venv $(VENV_DIR)
7+
$(VENV_DIR)/bin/pip install --upgrade pip
8+
@echo "In order to use venv python, please run 'source venv/bin/activate', then install dependencies by running \
9+
'make install-dev'."
10+
111
prepare-web:
212
pip install -r web/requirements.txt
313
cp web/.env.example web/.env
@@ -30,3 +40,9 @@ fix-files:
3040
python3 -m black .
3141
python3 -m isort .
3242
python3 -m flake8 .
43+
44+
create-migrations:
45+
python ./web/manage.py makemigrations
46+
47+
migrate:
48+
python ./web/manage.py migrate

README.md

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,18 @@ For a demonstration of a page with at least one link, see for example `{baseurl}
66

77
## Notes on installation and usage
88

9+
To prepare pyenv (`venv`) make sure to have `pyenv` installed, then run
10+
```bash
11+
make prepare-env
12+
source venv/bin/activate
13+
```
14+
15+
By default, the Mathswitch uses sqlite3 database, in order to use postgresql there is
16+
a provided `.env.example` config and Docker compose to run the database:
17+
```bash
18+
docker compose up -d
19+
```
20+
921
To install all the necessary Python packages, run:
1022

1123
```bash
@@ -22,19 +34,19 @@ cp web/.env.example web/.env
2234
Next, to create a database, run:
2335

2436
```bash
25-
python manage.py migrate
37+
python web/manage.py migrate
2638
```
2739

2840
In order to use the administrative interface, you need to create an admin user:
2941

3042
```bash
31-
python manage.py createsuperuser
43+
python web/manage.py createsuperuser
3244
```
3345

3446
Finally, to populate the database, run
3547

3648
```bash
37-
python manage.py import_wikidata
49+
python web/manage.py import_wikidata
3850
# OR
3951
make populate-db
4052
```
@@ -52,7 +64,7 @@ make populate-db
5264
If you ever want to repopulate the database, you can clear it using
5365

5466
```bash
55-
python manage.py clear_wikidata
67+
python web/manage.py clear_wikidata
5668
```
5769

5870
### To run the categorizer
@@ -100,12 +112,16 @@ black . && isort . && flake8
100112

101113
Each time after you change a model, make sure to create the appropriate migrations:
102114
```bash
103-
python manage.py makemigrations
115+
python web/manage.py makemigrations
116+
# OR
117+
make create-migrations
104118
```
105119

106120
To update the database with the new model, run:
107121
```bash
108-
python manage.py migrate
122+
python web/manage.py migrate
123+
# OR
124+
make migrate
109125
```
110126

111127
## Instructions for Katja to update the live version

docker-compose.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
volumes:
2+
postgres_data:
3+
4+
services:
5+
db:
6+
image: postgres:17-alpine
7+
restart: unless-stopped
8+
env_file:
9+
- ./web/.env
10+
ports:
11+
- '${POSTGRES_PORT:-5432}:5432'
12+
volumes:
13+
- postgres_data:/var/lib/postgresql/data
14+
profiles:
15+
- ''
16+
- db

pyproject.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
[tool.black]
22
extend-exclude = 'migrations'
3-
target-version = ['py310']
3+
target-version = ['py312']
4+
45
[tool.isort]
56
extend_skip_glob = ["*/migrations/*"]
67
profile = "black"
7-
py_version = 310
8+
py_version = 312

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
black~=25.9.0
2-
isort~=5.12.0
2+
isort~=7.0.0
33
flake8~=7.3.0
44

55
-r ./web/requirements.txt

web/.env.example

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,10 @@
11
SECRET_KEY="django-insecure-9wy9w#vf^tde0262doyy_j19=64c()_qub!1)f+fh-b^=7ndw*"
2-
WIKIPEDIA_CONTACT_EMAIL=my@email.com
2+
WIKIPEDIA_CONTACT_EMAIL=my@email.com
3+
4+
# DB
5+
USE_POSTGRES=True
6+
POSTGRES_DB=mathsdb
7+
POSTGRES_USER=mathsuser
8+
POSTGRES_PASSWORD=mathspass
9+
POSTGRES_HOST=localhost
10+
POSTGRES_PORT=5432
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Generated by Django 4.2.27 on 2025-12-16 23:19
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
("concepts", "0014_categorizerresult"),
10+
]
11+
12+
operations = [
13+
migrations.AlterField(
14+
model_name="categorizerresult",
15+
name="llm_type",
16+
field=models.CharField(max_length=100),
17+
),
18+
]

web/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
Django~=4.2.6
2+
psycopg2-binary~=2.9.11
23
requests~=2.32.5
34
spacy~=3.7.0 --prefer-binary
45
scispacy~=0.6.2

web/web/settings.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,23 @@
3131
# SECURITY WARNING: don't run with debug turned on in production!
3232
DEBUG = True
3333

34+
USE_POSTGRES = config("USE_POSTGRES", default=False, cast=bool)
35+
36+
POSTGRES_DB = config("POSTGRES_DB", default=None)
37+
POSTGRES_USER = config("POSTGRES_USER", default=None)
38+
POSTGRES_PASSWORD = config("POSTGRES_PASSWORD", default=None)
39+
POSTGRES_HOST = config("POSTGRES_HOST", default=None)
40+
POSTGRES_PORT = config("POSTGRES_PORT", default="5432")
41+
42+
IS_POSTGRES_CONFIGURED = all(
43+
[
44+
POSTGRES_DB,
45+
POSTGRES_USER,
46+
POSTGRES_PASSWORD,
47+
POSTGRES_HOST,
48+
]
49+
)
50+
3451
ALLOWED_HOSTS = ["*"]
3552

3653

@@ -90,6 +107,18 @@
90107
}
91108
}
92109

110+
if USE_POSTGRES and IS_POSTGRES_CONFIGURED:
111+
DATABASES = {
112+
"default": {
113+
"ENGINE": "django.db.backends.postgresql",
114+
"NAME": POSTGRES_DB,
115+
"USER": POSTGRES_USER,
116+
"PASSWORD": POSTGRES_PASSWORD,
117+
"HOST": POSTGRES_HOST,
118+
"PORT": POSTGRES_PORT,
119+
}
120+
}
121+
93122

94123
# Password validation
95124
# https://docs.djangoproject.com/en/4.2/ref/settings/#auth-password-validators

0 commit comments

Comments
 (0)