Skip to content

Commit 4b32110

Browse files
authored
Merge pull request #28 from Sheldenburg/feature/user-registration
fix the initial data load in prod
2 parents 6b6fec2 + e75ddc9 commit 4b32110

File tree

5 files changed

+31
-14
lines changed

5 files changed

+31
-14
lines changed

.github/workflows/db-migration.yml

+26-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Alembic DB Migration
1+
name: Alembic DB Migration and Load Initial Data
22

33
on:
44
push:
@@ -16,13 +16,24 @@ jobs:
1616
- name: Set up Python
1717
uses: actions/setup-python@v3
1818
with:
19-
python-version: '3.11'
19+
python-version: "3.11"
2020

2121
- name: Install dependencies
2222
run: |
2323
python -m pip install --upgrade pip
2424
pip install -r requirements.txt
2525
26+
- name: Start the DB
27+
working-directory: backend/src
28+
env:
29+
POSTGRES_DB: ${{ secrets.POSTGRES_DB }}
30+
POSTGRES_USER: ${{ secrets.POSTGRES_USER }}
31+
POSTGRES_PASSWORD: ${{ secrets.POSTGRES_PASSWORD }}
32+
POSTGRES_SERVER: ${{ secrets.POSTGRES_SERVER }}
33+
POSTGRES_PORT: ${{ secrets.POSTGRES_PORT }}
34+
run: |
35+
python backend_pre_start.py
36+
2637
- name: Run Alembic migrations
2738
working-directory: backend/src/app
2839
env:
@@ -33,3 +44,16 @@ jobs:
3344
POSTGRES_PORT: ${{ secrets.POSTGRES_PORT }}
3445
run: |
3546
alembic upgrade head
47+
48+
- name: Create initial data in the DB
49+
working-directory: backend/src
50+
env:
51+
POSTGRES_DB: ${{ secrets.POSTGRES_DB }}
52+
POSTGRES_USER: ${{ secrets.POSTGRES_USER }}
53+
POSTGRES_PASSWORD: ${{ secrets.POSTGRES_PASSWORD }}
54+
POSTGRES_SERVER: ${{ secrets.POSTGRES_SERVER }}
55+
POSTGRES_PORT: ${{ secrets.POSTGRES_PORT }}
56+
FIRST_SUPERUSER: ${{ secrets.FIRST_SUPERUSER }}
57+
FIRST_SUPERUSER_PASSWORD: ${{ secrets.FIRST_SUPERUSER_PASSWORD }}
58+
run: |
59+
python initial_data.py
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,16 @@
11
#! /usr/bin/env bash
22

3-
cd lambda/app
3+
cd src
44
# Load environment variables
55
export $(grep -v '^#' .env | xargs)
66

7-
87
# Let the DB start
9-
# python /app/app/backend_pre_start.py
10-
# python backend_pre_start.py
8+
python backend_pre_start.py
119

10+
cd app
1211
# Run migrations
1312
alembic upgrade head
1413

1514
cd ..
16-
1715
# Create initial data in DB
18-
# python /app/app/initial_data.py
1916
python initial_data.py
20-
21-
cd ..
File renamed without changes.

backend/src/app/backend_pre_start.py backend/src/backend_pre_start.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import logging
22

3+
from app.core.db import engine
34
from sqlalchemy import Engine
45
from sqlmodel import Session, select
56
from tenacity import after_log, before_log, retry, stop_after_attempt, wait_fixed
67

7-
from app.core.db import engine
8-
98
logging.basicConfig(level=logging.INFO)
109
logger = logging.getLogger(__name__)
1110

backend/src/app/tests_pre_start.py backend/src/tests_pre_start.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import logging
22

3+
from app.core.db import engine
34
from sqlalchemy import Engine
45
from sqlmodel import Session, select
56
from tenacity import after_log, before_log, retry, stop_after_attempt, wait_fixed
67

7-
from app.core.db import engine
8-
98
logging.basicConfig(level=logging.INFO)
109
logger = logging.getLogger(__name__)
1110

0 commit comments

Comments
 (0)