fix(api-server,control-plane): replace remaining AutoMigrate with raw SQL, fix CP_RUNTIME_NAMESPACE#1442
Conversation
✅ Deploy Preview for cheerful-kitten-f556a0 canceled.
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Enterprise Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughThe Changes
🚥 Pre-merge checks | ✅ 5 | ❌ 3❌ Failed checks (1 warning, 2 inconclusive)
✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
✨ Simplify code
Comment |
…ace on vanilla OpenShift CP_RUNTIME_NAMESPACE defaulted to "ambient-code--runtime-int" (MPP-specific) in Go code, causing crashloop on vanilla OpenShift where that namespace doesn't exist. Fix by falling back to NAMESPACE env var (or "ambient-code") and adding downward API to the base manifest. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
87c94ea to
d1280c9
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@components/ambient-api-server/plugins/agents/migration.go`:
- Around line 14-25: The agents table DDL in migration.go creates project_id and
name as nullable, which conflicts with the model's gorm:"not null"; update the
CREATE TABLE statement for agents to add NOT NULL to the project_id and name
column definitions (the SQL string used to create agents) so the schema enforces
the same constraints as the model and prevents schema drift.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: 5a0ccd58-ed74-4ef8-b08d-804bf0ece811
📒 Files selected for processing (5)
components/ambient-api-server/plugins/agents/migration.gocomponents/ambient-api-server/plugins/credentials/migration.gocomponents/ambient-api-server/plugins/inbox/migration.gocomponents/ambient-control-plane/internal/config/config.gocomponents/manifests/base/ambient-control-plane-service.yml
| `CREATE TABLE IF NOT EXISTS agents ( | ||
| id TEXT PRIMARY KEY, | ||
| created_at TIMESTAMPTZ, | ||
| updated_at TIMESTAMPTZ, | ||
| deleted_at TIMESTAMPTZ, | ||
| project_id TEXT, | ||
| name TEXT, | ||
| prompt TEXT, | ||
| current_session_id TEXT, | ||
| labels TEXT, | ||
| annotations TEXT | ||
| )`, |
There was a problem hiding this comment.
Restore required constraints in agents DDL
project_id (Line 19) and name (Line 20) are created nullable, but the runtime model treats them as required (gorm:"not null" in components/ambient-api-server/plugins/agents/model.go). This introduces schema drift for fresh installs and weakens data integrity for project-scoped queries.
Proposed fix
`CREATE TABLE IF NOT EXISTS agents (
id TEXT PRIMARY KEY,
created_at TIMESTAMPTZ,
updated_at TIMESTAMPTZ,
deleted_at TIMESTAMPTZ,
- project_id TEXT,
- name TEXT,
+ project_id TEXT NOT NULL,
+ name TEXT NOT NULL,
prompt TEXT,
current_session_id TEXT,
labels TEXT,
annotations TEXT
)`,📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| `CREATE TABLE IF NOT EXISTS agents ( | |
| id TEXT PRIMARY KEY, | |
| created_at TIMESTAMPTZ, | |
| updated_at TIMESTAMPTZ, | |
| deleted_at TIMESTAMPTZ, | |
| project_id TEXT, | |
| name TEXT, | |
| prompt TEXT, | |
| current_session_id TEXT, | |
| labels TEXT, | |
| annotations TEXT | |
| )`, | |
| `CREATE TABLE IF NOT EXISTS agents ( | |
| id TEXT PRIMARY KEY, | |
| created_at TIMESTAMPTZ, | |
| updated_at TIMESTAMPTZ, | |
| deleted_at TIMESTAMPTZ, | |
| project_id TEXT NOT NULL, | |
| name TEXT NOT NULL, | |
| prompt TEXT, | |
| current_session_id TEXT, | |
| labels TEXT, | |
| annotations TEXT | |
| )`, |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@components/ambient-api-server/plugins/agents/migration.go` around lines 14 -
25, The agents table DDL in migration.go creates project_id and name as
nullable, which conflicts with the model's gorm:"not null"; update the CREATE
TABLE statement for agents to add NOT NULL to the project_id and name column
definitions (the SQL string used to create agents) so the schema enforces the
same constraints as the model and prevents schema drift.
Merge Queue Status
This pull request spent 12 seconds in the queue, including 2 seconds running CI. Required conditions to merge |
Summary
AutoMigratein agents, inbox, and credentials initial migrations with rawCREATE TABLE IF NOT EXISTS+CREATE INDEX IF NOT EXISTS— fixespq: got 2 parameters but the statement requires 1on non-fresh databases where tables already existCP_RUNTIME_NAMESPACEdefaulting to MPP-specificambient-code--runtime-inton vanilla OpenShift by falling back toNAMESPACEenv var and adding downward API to base manifestRoot Cause
GORM's postgres migrator injects
pgx.QueryExecModeSimpleProtocolas a query parameter inGetRows()whenDriverNameis empty. Since rh-trex-ai useslib/pq(not native pgx), this sentinel is counted as an extra bind parameter, causing the mismatch. This only triggers whenAutoMigratefinds an already-existing table (ALTER TABLE path callsColumnTypes→GetRows).Test plan
go vet ./...andgo build ./...pass for both api-server and control-plane🤖 Generated with Claude Code
Summary by CodeRabbit