-
Notifications
You must be signed in to change notification settings - Fork 3
134 lines (111 loc) · 4.14 KB
/
migrations.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
name: migrations
# Based on a dump of a existing postgresql database, valid for a given
# fractal-server version, apply current migrations and verify that they go
# through. The main goal is to identify cases where current data make a table
# definition invalid in a way that wouldn't be detected when starting from an
# empty database; typical example: a coulmn has a null value, and we later
# alter it to make it non-nullable.
on:
push:
branches: ["main"]
pull_request:
branches: ["main"]
env:
# The DB `${ROOTDIR}/clean_db_fractal_${SOURCE_VERSION}.sql` is compatible
# with the SOURCE_VERSION of fractal-server.
# Here we test the script that upgrades the DB from SOURCE_VERSION to the
#current version.
SOURCE_VERSION: 2.9.0
ROOTDIR: tests/data/testing_databases
jobs:
migrations:
name: "Python ${{ matrix.python-version }} - ${{ matrix.db }}"
runs-on: ubuntu-22.04
timeout-minutes: 20
strategy:
matrix:
python-version: ["3.10", "3.11", "3.12"]
services:
postgres:
image: postgres
env:
POSTGRES_PASSWORD: postgres
POSTGRES_DB: fractal_test
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
steps:
- uses: actions/checkout@v4
- name: Load database dump into postgres database
env:
PGPASSWORD: postgres
run: psql -U postgres -h localhost -d fractal_test -f ${ROOTDIR}/clean_db_fractal_${SOURCE_VERSION}.sql
- name: Install poetry
run: pipx install poetry==1.8.2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: "poetry"
- name: Install fractal-server
run: |
poetry install --without dev --without docs --no-interaction
poetry add setuptools # required for py3.12
- name: Convert postgres database into sqlite
run: pipx run db-to-sqlite[postgresql]==1.5 "postgresql://postgres:postgres@localhost/fractal_test" $ROOTDIR/clean_db_fractal_${SOURCE_VERSION}.sql.sqlite3 --all
- name: Apply migration and fix-db script (postgres)
env:
FRACTAL_V27_DEFAULT_USER_EMAIL: [email protected]
run: |
cp $ROOTDIR/.fractal_server_postgres.env .fractal_server.env
poetry run fractalctl set-db
echo -e "yes\nyes\nyes\nyes\nyes"| poetry run fractalctl update-db-data
poetry run python scripts/validate_db_data_with_read_schemas.py
- name: Apply migration and fix-db script (sqlite)
env:
FRACTAL_V27_DEFAULT_USER_EMAIL: [email protected]
run: |
echo -e "DB_ENGINE=sqlite\nSQLITE_PATH=${ROOTDIR}/clean_db_fractal_${SOURCE_VERSION}.sql.sqlite3" > .fractal_server.env
poetry run fractalctl set-db
echo -e "yes\nyes\nyes\nyes\nyes" | poetry run fractalctl update-db-data
poetry run python scripts/validate_db_data_with_read_schemas.py
downgrade:
name: "Alembic downgrade"
runs-on: ubuntu-22.04
timeout-minutes: 5
services:
postgres:
image: postgres
env:
POSTGRES_PASSWORD: postgres
POSTGRES_DB: fractal_test
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
steps:
- uses: actions/checkout@v4
- name: Install poetry
run: pipx install poetry==1.8.2
- name: Set up Python 3.11
uses: actions/setup-python@v5
with:
python-version: 3.11
cache: "poetry"
- name: Install fractal-server
run: |
poetry install --without dev --without docs --no-interaction
- name: Apply upgrade and downgrade
run: |
cp $ROOTDIR/.fractal_server_postgres.env fractal_server/.fractal_server.env
cd fractal_server
poetry run alembic history
poetry run alembic upgrade head
poetry run alembic downgrade base