Skip to content

Commit 1ac8701

Browse files
db change
1 parent fa3f088 commit 1ac8701

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

app.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,39 @@
2424

2525
app = Flask(__name__)
2626
app.config['SECRET_KEY'] = os.environ.get('SECRET_KEY', 'dev-secret-key-change-in-production')
27-
app.config['SQLALCHEMY_DATABASE_URI'] = os.environ.get('DATABASE_URL', 'sqlite:///data/github_backup.db')
27+
app.config['SQLALCHEMY_DATABASE_URI'] = os.environ.get('DATABASE_URL', 'sqlite:////app/data/github_backup.db')
2828
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
2929

30+
# Diagnostic logging for DB path
31+
db_uri = app.config['SQLALCHEMY_DATABASE_URI']
32+
logger.info(f"Configured DB URI: {db_uri}")
33+
if db_uri.startswith('sqlite:///') or db_uri.startswith('sqlite:////'):
34+
# Normalize both relative and absolute sqlite URIs
35+
normalized = db_uri.replace('sqlite:////', '/').replace('sqlite:///', '')
36+
# If we replaced absolute variant, ensure leading slash retained
37+
if db_uri.startswith('sqlite:////'):
38+
sqlite_file = '/' + normalized.lstrip('/')
39+
else:
40+
sqlite_file = os.path.abspath(normalized)
41+
parent = os.path.dirname(sqlite_file)
42+
try:
43+
os.makedirs(parent, exist_ok=True)
44+
stat_parent = os.stat(parent)
45+
logger.info(f"SQLite file target: {sqlite_file} (parent exists, perms {oct(stat_parent.st_mode)[-3:]})")
46+
except Exception as e:
47+
logger.error(f"Failed ensuring SQLite directory {parent}: {e}")
48+
3049
# Initialize extensions
3150
db.init_app(app)
51+
52+
# Immediate connectivity test (runs once at startup)
53+
from sqlalchemy import text
54+
with app.app_context():
55+
try:
56+
db.session.execute(text('SELECT 1'))
57+
logger.info('Initial DB connectivity test succeeded.')
58+
except Exception as e:
59+
logger.error(f'Initial DB connectivity test failed: {e}')
3260
login_manager = LoginManager()
3361
login_manager.init_app(app)
3462
login_manager.login_view = 'login'

docker-compose.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ services:
1212
- ./logs:/app/logs
1313
environment:
1414
- SECRET_KEY=your-secret-key-change-this
15-
- DATABASE_URL=sqlite:///data/github_backup.db
15+
# Use absolute path (4 leading slashes after sqlite:) to avoid relative path ambiguity
16+
- DATABASE_URL=sqlite:////app/data/github_backup.db
1617
- PUID=1000 # Change to your user ID (run 'id -u' to get yours)
1718
- PGID=1000 # Change to your group ID (run 'id -g' to get yours)
1819
restart: unless-stopped

0 commit comments

Comments
 (0)