Fix database migration and path issues
- Fix Python path in migrations/env.py for proper imports - Update database path to use relative project paths instead of /app - Update alembic.ini to use relative database path - Update README with correct database location and migration instructions generated with BackendIM... (backend.im)
This commit is contained in:
parent
0976677a4c
commit
bd33c253b2
14
README.md
14
README.md
@ -36,7 +36,19 @@ pip install -r requirements.txt
|
|||||||
|
|
||||||
## Database Setup
|
## Database Setup
|
||||||
|
|
||||||
The application uses SQLite, and the database will be created automatically at `/app/storage/db/db.sqlite` when the application starts.
|
The application uses SQLite, and the database will be created automatically at `./storage/db/db.sqlite` relative to the project root when the application starts.
|
||||||
|
|
||||||
|
### Migrations
|
||||||
|
|
||||||
|
To run database migrations:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Set the Python path to include the project root
|
||||||
|
export PYTHONPATH=/path/to/project
|
||||||
|
|
||||||
|
# Run migrations
|
||||||
|
alembic upgrade head
|
||||||
|
```
|
||||||
|
|
||||||
## Running the Application
|
## Running the Application
|
||||||
|
|
||||||
|
@ -35,7 +35,7 @@ script_location = migrations
|
|||||||
# are written from script.py.mako
|
# are written from script.py.mako
|
||||||
# output_encoding = utf-8
|
# output_encoding = utf-8
|
||||||
|
|
||||||
sqlalchemy.url = sqlite:////app/storage/db/db.sqlite
|
sqlalchemy.url = sqlite:///%(here)s/storage/db/db.sqlite
|
||||||
|
|
||||||
|
|
||||||
[post_write_hooks]
|
[post_write_hooks]
|
||||||
|
@ -2,8 +2,10 @@ from sqlalchemy import create_engine
|
|||||||
from sqlalchemy.ext.declarative import declarative_base
|
from sqlalchemy.ext.declarative import declarative_base
|
||||||
from sqlalchemy.orm import sessionmaker
|
from sqlalchemy.orm import sessionmaker
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
import os
|
||||||
|
|
||||||
DB_DIR = Path("/app") / "storage" / "db"
|
# Use a local path that's accessible in the current environment
|
||||||
|
DB_DIR = Path(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) / "storage" / "db"
|
||||||
DB_DIR.mkdir(parents=True, exist_ok=True)
|
DB_DIR.mkdir(parents=True, exist_ok=True)
|
||||||
|
|
||||||
SQLALCHEMY_DATABASE_URL = f"sqlite:///{DB_DIR}/db.sqlite"
|
SQLALCHEMY_DATABASE_URL = f"sqlite:///{DB_DIR}/db.sqlite"
|
||||||
|
@ -1,10 +1,15 @@
|
|||||||
from logging.config import fileConfig
|
from logging.config import fileConfig
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
from sqlalchemy import engine_from_config
|
from sqlalchemy import engine_from_config
|
||||||
from sqlalchemy import pool
|
from sqlalchemy import pool
|
||||||
|
|
||||||
from alembic import context
|
from alembic import context
|
||||||
|
|
||||||
|
# Add the parent directory to the Python path so that 'app' can be imported
|
||||||
|
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||||
|
|
||||||
# this is the Alembic Config object, which provides
|
# this is the Alembic Config object, which provides
|
||||||
# access to the values within the .ini file in use.
|
# access to the values within the .ini file in use.
|
||||||
config = context.config
|
config = context.config
|
||||||
|
Loading…
x
Reference in New Issue
Block a user