Compare commits

...

2 Commits

Author SHA1 Message Date
fb32bb12c5 fix: check column existence before creating indexes
Fixes startup error 'no such column: session_id' that occurs when
_create_indexes() tries to create indexes on columns that don't exist yet.

The issue occurred when initializing a database from scratch:
1. _migrate_schema() adds session_id column to positions table
2. _create_indexes() tries to create index on session_id
3. But on fresh databases, positions table was created without session_id
4. Migration runs after table creation, before index creation
5. Index creation fails because column doesn't exist yet

Solution: Check if columns exist before creating indexes on them.

This ensures the database can be initialized both:
- Fresh (CREATE TABLE without session_id, then ALTER TABLE, then CREATE INDEX)
- Migrated (ALTER TABLE adds column, then CREATE INDEX)

Tested: All 21 database tests passing
2025-11-02 19:24:19 -05:00
29af5ddb4c fix: remove non-existent data scripts from Dockerfile
The get_daily_price.py, get_interdaily_price.py, and merge_jsonl.py
scripts don't exist in the repository. Removed the RUN command that
tries to copy these files to /app/scripts/.

This fixes the Docker build failure:
ERROR: process did not complete successfully: exit code: 1

The API server doesn't need these data preparation scripts as it
operates on existing database records.
2025-11-02 19:18:12 -05:00
2 changed files with 13 additions and 12 deletions

View File

@@ -26,12 +26,6 @@ WORKDIR /app
# Copy application code
COPY . .
# Copy data scripts to separate directory (volume mount won't overlay these)
RUN mkdir -p /app/scripts && \
cp data/get_daily_price.py /app/scripts/ && \
cp data/get_interdaily_price.py /app/scripts/ && \
cp data/merge_jsonl.py /app/scripts/
# Create necessary directories
RUN mkdir -p data logs data/agent_data

View File

@@ -438,12 +438,19 @@ def _create_indexes(cursor: sqlite3.Cursor) -> None:
""")
# Positions table - add index for simulation_run_id and session_id
cursor.execute("""
CREATE INDEX IF NOT EXISTS idx_positions_run_id ON positions(simulation_run_id)
""")
cursor.execute("""
CREATE INDEX IF NOT EXISTS idx_positions_session_id ON positions(session_id)
""")
# Check if columns exist before creating indexes
cursor.execute("PRAGMA table_info(positions)")
position_columns = [row[1] for row in cursor.fetchall()]
if 'simulation_run_id' in position_columns:
cursor.execute("""
CREATE INDEX IF NOT EXISTS idx_positions_run_id ON positions(simulation_run_id)
""")
if 'session_id' in position_columns:
cursor.execute("""
CREATE INDEX IF NOT EXISTS idx_positions_session_id ON positions(session_id)
""")
def drop_all_tables(db_path: str = "data/jobs.db") -> None: