Spaces:
Sleeping
Sleeping
Commit
·
126ae8d
1
Parent(s):
4231eb9
Refactor application imports and migration script: update model import paths in env.py and migrate.py, enhance app initialization in __init__.py, and modify PYTHONPATH in run.sh for improved directory structure.
Browse files- alembic/env.py +1 -1
- app/__init__.py +4 -1
- scripts/migrate.py +3 -2
- scripts/run.sh +1 -1
alembic/env.py
CHANGED
|
@@ -5,7 +5,7 @@ from sqlalchemy import pool
|
|
| 5 |
|
| 6 |
from alembic import context
|
| 7 |
|
| 8 |
-
from app.models import Base
|
| 9 |
from app.config import get_settings
|
| 10 |
|
| 11 |
# this is the Alembic Config object, which provides
|
|
|
|
| 5 |
|
| 6 |
from alembic import context
|
| 7 |
|
| 8 |
+
from app.models.database import Base
|
| 9 |
from app.config import get_settings
|
| 10 |
|
| 11 |
# this is the Alembic Config object, which provides
|
app/__init__.py
CHANGED
|
@@ -1 +1,4 @@
|
|
| 1 |
-
"""App package."""
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""App package initialization."""
|
| 2 |
+
from app.models import Base
|
| 3 |
+
|
| 4 |
+
__all__ = ['Base']
|
scripts/migrate.py
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
|
|
| 1 |
import os
|
| 2 |
-
import sys
|
| 3 |
import logging
|
| 4 |
from alembic.config import Config
|
| 5 |
from alembic import command
|
|
|
|
| 6 |
|
| 7 |
# Configure logging
|
| 8 |
logging.basicConfig(
|
|
@@ -32,7 +33,7 @@ def run_migrations():
|
|
| 32 |
|
| 33 |
except Exception as e:
|
| 34 |
logger.error(f"Error during database migration: {str(e)}")
|
| 35 |
-
|
| 36 |
|
| 37 |
if __name__ == "__main__":
|
| 38 |
run_migrations()
|
|
|
|
| 1 |
+
"""Database migration script."""
|
| 2 |
import os
|
|
|
|
| 3 |
import logging
|
| 4 |
from alembic.config import Config
|
| 5 |
from alembic import command
|
| 6 |
+
from app.models.database import Base
|
| 7 |
|
| 8 |
# Configure logging
|
| 9 |
logging.basicConfig(
|
|
|
|
| 33 |
|
| 34 |
except Exception as e:
|
| 35 |
logger.error(f"Error during database migration: {str(e)}")
|
| 36 |
+
raise
|
| 37 |
|
| 38 |
if __name__ == "__main__":
|
| 39 |
run_migrations()
|
scripts/run.sh
CHANGED
|
@@ -9,7 +9,7 @@ export LOG_LEVEL=${LOG_LEVEL:-"info"}
|
|
| 9 |
export DATABASE_URL=${DATABASE_URL:-"sqlite:///app/storage/audiobooks.db"}
|
| 10 |
|
| 11 |
# Set Python path to include both app directories
|
| 12 |
-
export PYTHONPATH="/app:/app/app:${PYTHONPATH:-}"
|
| 13 |
|
| 14 |
# Create storage directories if they don't exist
|
| 15 |
mkdir -p /app/storage/audio
|
|
|
|
| 9 |
export DATABASE_URL=${DATABASE_URL:-"sqlite:///app/storage/audiobooks.db"}
|
| 10 |
|
| 11 |
# Set Python path to include both app directories
|
| 12 |
+
export PYTHONPATH="/app:/app/app:${PYTHONPATH:-}:$(dirname $(dirname $(realpath $0)))"
|
| 13 |
|
| 14 |
# Create storage directories if they don't exist
|
| 15 |
mkdir -p /app/storage/audio
|