fix(migration): exa env var into db#6366
Conversation
Greptile OverviewGreptile SummaryAdds database migration to seed Exa search provider from Critical Issue:
Confidence Score: 1/5
Important Files ChangedFile Analysis
Sequence DiagramsequenceDiagram
participant Migration as Migration Script
participant Env as Environment
participant DB as Database
participant Encrypt as Encryption Util
Migration->>Env: Get EXA_API_KEY
alt No API key found
Env-->>Migration: None
Migration->>Migration: Return early
else API key exists
Env-->>Migration: API key value
Migration->>DB: Get bind connection
Migration->>DB: Check for existing provider
alt Provider already exists
DB-->>Migration: Existing record
Migration->>Migration: Return early
else No existing provider
DB-->>Migration: None
Migration->>Encrypt: encrypt_string_to_bytes(api_key)
Encrypt-->>Migration: Encrypted key bytes
Migration->>DB: Check for active providers
alt Active provider exists
DB-->>Migration: Active record found
Migration->>DB: Insert (is_active=False)
else No active provider
DB-->>Migration: No active records
Migration->>DB: Insert (is_active=True)
end
DB-->>Migration: Insert complete
end
end
|
| def _get_internet_search_table(metadata: sa.MetaData) -> sa.Table: | ||
| return sa.Table( | ||
| "internet_search_provider", | ||
| metadata, | ||
| sa.Column("id", sa.Integer, primary_key=True), | ||
| sa.Column("name", sa.String), | ||
| sa.Column("provider_type", sa.String), | ||
| sa.Column("api_key", sa.LargeBinary), | ||
| sa.Column("config", postgresql.JSONB), | ||
| sa.Column("is_active", sa.Boolean), | ||
| ) |
There was a problem hiding this comment.
logic: table definition missing time_created and time_updated columns that exist in actual schema (line 33-42 in migration 1f2a3b4c5d6e). These columns have NOT NULL constraints with server defaults. When manually defining sa.Table for data manipulation, include all NOT NULL columns to ensure insert succeeds.
Prompt To Fix With AI
This is a comment left during a code review.
Path: backend/alembic/versions/3c9a65f1207f_seed_exa_provider_from_env.py
Line: 28:38
Comment:
**logic:** table definition missing `time_created` and `time_updated` columns that exist in actual schema (line 33-42 in migration `1f2a3b4c5d6e`). These columns have NOT NULL constraints with server defaults. When manually defining sa.Table for data manipulation, include all NOT NULL columns to ensure insert succeeds.
How can I resolve this? If you propose a fix, please make it concise.There was a problem hiding this comment.
We need to fix this one.
justin-tahara
left a comment
There was a problem hiding this comment.
Make sure to test this and ensure that it works.
backend/alembic/versions/3c9a65f1207f_seed_exa_provider_from_env.py
Outdated
Show resolved
Hide resolved
| def _get_internet_search_table(metadata: sa.MetaData) -> sa.Table: | ||
| return sa.Table( | ||
| "internet_search_provider", | ||
| metadata, | ||
| sa.Column("id", sa.Integer, primary_key=True), | ||
| sa.Column("name", sa.String), | ||
| sa.Column("provider_type", sa.String), | ||
| sa.Column("api_key", sa.LargeBinary), | ||
| sa.Column("config", postgresql.JSONB), | ||
| sa.Column("is_active", sa.Boolean), | ||
| ) |
There was a problem hiding this comment.
We need to fix this one.
| if existing: | ||
| return | ||
|
|
||
| encrypted_key = encrypt_string_to_bytes(exa_api_key) |
There was a problem hiding this comment.
Is this how you store the key in the DB?
Description
[Provide a brief description of the changes in this PR]
How Has This Been Tested?
[Describe the tests you ran to verify your changes]
Additional Options
Summary by cubic
Seeds the Exa internet search provider from the EXA_API_KEY environment variable during migration and encrypts the API key. Activates it only if no provider is active; no-op if the env var is missing or the provider already exists.
Written for commit 4e29a17. Summary will update automatically on new commits.