fix: resolve database and session initialization issues
- Switch from SQLAlchemy sessions to filesystem sessions to avoid race conditions with multiple gunicorn workers trying to create the sessions table simultaneously - Update Alembic env.py to use a minimal Flask app without Flask-Session to prevent session table creation during migrations - Add data directory creation to entrypoint.sh for clean container starts - Configure test environment to use filesystem sessions with temp directory 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -51,8 +51,10 @@ def create_app(config_name: str | None = None) -> Flask:
|
||||
bcrypt.init_app(app)
|
||||
csrf.init_app(app)
|
||||
|
||||
# Initialize session with SQLAlchemy backend
|
||||
app.config["SESSION_SQLALCHEMY"] = db
|
||||
# Initialize session with filesystem backend
|
||||
# Ensure session directory exists
|
||||
session_dir = Path(app.config.get("SESSION_FILE_DIR", data_dir / "sessions"))
|
||||
session_dir.mkdir(parents=True, exist_ok=True)
|
||||
session.init_app(app)
|
||||
|
||||
# Register blueprints
|
||||
|
||||
@@ -25,8 +25,9 @@ class Config:
|
||||
)
|
||||
SQLALCHEMY_TRACK_MODIFICATIONS = False
|
||||
|
||||
# Session management
|
||||
SESSION_TYPE = "sqlalchemy"
|
||||
# Session management (filesystem-based to avoid race conditions with SQLAlchemy)
|
||||
SESSION_TYPE = "filesystem"
|
||||
SESSION_FILE_DIR = DATA_DIR / "sessions"
|
||||
SESSION_PERMANENT = True
|
||||
SESSION_USE_SIGNER = True
|
||||
SESSION_KEY_PREFIX = "sk:"
|
||||
@@ -90,6 +91,10 @@ class TestConfig(Config):
|
||||
# Use in-memory database for tests
|
||||
SQLALCHEMY_DATABASE_URI = "sqlite:///:memory:"
|
||||
|
||||
# Use filesystem session with temp directory for tests
|
||||
SESSION_TYPE = "filesystem"
|
||||
SESSION_FILE_DIR = Path("/tmp/sneaky-klaus-test-sessions")
|
||||
|
||||
# Disable CSRF for easier testing
|
||||
WTF_CSRF_ENABLED = False
|
||||
|
||||
|
||||
Reference in New Issue
Block a user