Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Add workflow to test migrations backwards compatibility

Grzegorz11acc18f9ac9
diff --git a/.github/workflows/test-migrations-compatibility.yml b/.github/workflows/test-migrations-compatibility.yml
new file mode 100644
index 0000000000..3134ed5ae7
--- /dev/null
+++ b/.github/workflows/test-migrations-compatibility.yml
@@ -0,0 +1,62 @@
+name: Test migrations compatibility
+
+on:
+ pull_request_target:
+ branches:
+ - "3.*"
+ - "main"
+# paths:
+# - "**/migrations/**"
+
+env:
+ DATABASE_URL: "postgres://saleor:saleor@postgres:5432/saleor"
+ SECRET_KEY: ci-test
+
+jobs:
+ build:
+ runs-on: ubuntu-latest
+ services:
+ postgres:
+ image: postgres
+ env:
+ POSTGRES_PASSWORD: saleor
+ POSTGRES_USER: saleor
+ options: >-
+ --health-cmd pg_isready
+ --health-interval 10s
+ --health-timeout 5s
+ --health-retries 5
+
+ steps:
+ - name: Checkout branch
+ uses: actions/checkout@v3
+
+ - name: Install system dependencies
+ run: apt-get install -y libpq-dev
+
+ - name: Cache pip
+ uses: actions/cache@v3
+ with:
+ path: ~/.cache/pip
+ key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements_dev.txt') }}
+ restore-keys: |
+ ${{ runner.os }}-pip-
+
+ - name: Install dependencies
+ run: |
+ python -m pip install wheel
+ python -m pip install -r requirements_dev.txt
+
+ - name: Migrate
+ run: |
+ ./manage.py migrate
+
+ - name: Checkout base
+ uses: actions/checkout@v3
+ with:
+ ref: {{ env.GITHUB_REF }}
+
+ - name: Run tests
+ run: |
+ export PYTEST_DB_URL=$DATABASE_URL
+ pytest -n 0 --reuse-db
diff --git a/conftest.py b/conftest.py
index 235fedaa3a..dffa9e97bd 100644
--- a/conftest.py
+++ b/conftest.py
@@ -1,3 +1,9 @@
+import os
+
+import dj_database_url
+import pytest
+from django.conf import settings
+
pytest_plugins = [
"saleor.tests.fixtures",
"saleor.plugins.tests.fixtures",
@@ -9,3 +15,12 @@ pytest_plugins = [
"saleor.graphql.webhook.tests.benchmark.fixtures",
"saleor.plugins.webhook.tests.subscription_webhooks.fixtures",
]
+
+if os.environ.get("PYTEST_DB_URL"):
+ @pytest.fixture(scope="session")
+ def django_db_setup():
+ settings.DATABASES = {
+ settings.DATABASE_CONNECTION_DEFAULT_NAME: dj_database_url.config(
+ default=os.environ.get("PYTEST_DB_URL"), conn_max_age=600
+ ),
+ }