Spaces:
Runtime error
Runtime error
Commit ·
01ffc0c
1
Parent(s): a9da580
feat: handle missing migrations on startup with create_all fallback
Browse files- README_SPACES.md +2 -0
- docker-entrypoint.sh +9 -1
README_SPACES.md
CHANGED
|
@@ -29,3 +29,5 @@ Flask application for sharing and organizing notes.
|
|
| 29 |
|
| 30 |
- The app listens on port `7860`.
|
| 31 |
- DB migrations run at startup by default. Set `RUN_MIGRATIONS=0` to skip.
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
- The app listens on port `7860`.
|
| 31 |
- DB migrations run at startup by default. Set `RUN_MIGRATIONS=0` to skip.
|
| 32 |
+
- If `migrations/` is missing, startup falls back to `db.create_all()` by default.
|
| 33 |
+
- Set `RUN_CREATE_ALL_IF_NO_MIGRATIONS=0` to disable that fallback.
|
docker-entrypoint.sh
CHANGED
|
@@ -4,7 +4,15 @@ set -e
|
|
| 4 |
mkdir -p instance
|
| 5 |
|
| 6 |
if [ "${RUN_MIGRATIONS:-1}" = "1" ]; then
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
fi
|
| 9 |
|
| 10 |
exec gunicorn --workers 2 --threads 4 --timeout 120 --bind 0.0.0.0:${PORT:-7860} "app:create_app()"
|
|
|
|
| 4 |
mkdir -p instance
|
| 5 |
|
| 6 |
if [ "${RUN_MIGRATIONS:-1}" = "1" ]; then
|
| 7 |
+
if [ -d migrations ]; then
|
| 8 |
+
flask db upgrade
|
| 9 |
+
else
|
| 10 |
+
echo "migrations/ not found, skipping flask db upgrade."
|
| 11 |
+
if [ "${RUN_CREATE_ALL_IF_NO_MIGRATIONS:-1}" = "1" ]; then
|
| 12 |
+
echo "Running db.create_all() fallback."
|
| 13 |
+
python -c "from app import create_app; from app.extensions import db; app = create_app(); app.app_context().push(); db.create_all()"
|
| 14 |
+
fi
|
| 15 |
+
fi
|
| 16 |
fi
|
| 17 |
|
| 18 |
exec gunicorn --workers 2 --threads 4 --timeout 120 --bind 0.0.0.0:${PORT:-7860} "app:create_app()"
|