Schema recommendations agent loop
Purpose
Use PlanetScale schema recommendations as high-quality input to agents. Convert recommendations into safe implementation plans, issues, branches, migrations, or pull requests. Do not apply recommendations directly.
Inputs
Collect:
- Open schema recommendations.
- Recommendation type.
- Affected table, keyspace, schema, and query pattern.
- Suggested DDL.
- Supporting Insights evidence.
- Application repository and migration system.
- Engine: Vitess or Postgres.
- Target branch.
Recommendation types to recognize
- Add index for inefficient query.
- Remove redundant index.
- Prevent primary key ID exhaustion.
- Drop unused table.
- Upgrade legacy charset or collation.
- Other DDL recommendation.
Triage questions
For each recommendation, answer:
- Is this still open and relevant?
- Which query patterns triggered it?
- Which application code paths generate those queries?
- Is the recommendation safely expressible in the application’s migration framework?
- Does the ORM/schema source of truth need to change?
- Can it be tested on a non-production branch?
- What is the expected impact on reads, writes, storage, and deploy time?
- Is there a rollback or revert path?
- Is there a competing recommendation or migration?
Engine-specific implementation path
Vitess
Recommended path:
- Create or use a development branch.
- Apply the schema change to that branch only after approval.
- Open a deploy request only after approval.
- Use deploy request review to inspect schema, shard impact, data-loss warnings, lint errors, and conflicts.
- Use normal safe migration path unless instant deployment is explicitly justified.
- Deploy only after approval.
- Monitor Insights and anomaly state after deployment.
Default output before approval: issue or PR with migration proposal, not a live deploy request.
Postgres
Recommended path:
- Convert DDL into the application’s migration framework where possible.
- Test against a non-production branch.
- Run application tests and relevant query checks.
- Open PR.
- Apply production migration only after approval.
- Use backups/PITR runbook as recovery plan, not as a substitute for migration review.
Default output before approval: migration PR or issue, not production DDL.
Codebase correlation
When a repository is available:
- Search for the table and column names.
- Search for ORM model definitions.
- Search for migrations.
- Search for query fingerprints, route tags, job names, and controller/action names from Insights.
- Identify whether the recommendation should be implemented in database DDL, ORM schema, raw migration, or application query code.
Safety checks before proposing implementation
Block direct application when:
- The recommendation is stale or already addressed.
- The affected table is small enough that the benefit is unclear.
- The index would be redundant with an existing index.
- The index would hurt write-heavy workloads without enough read benefit.
- The table appears unused but repository references are ambiguous.
- Dropping a table or index lacks owner confirmation.
- The migration framework has a different schema source of truth.
- The recommendation targets production and no branch/test plan exists.
Output
For each recommendation, produce:
- Recommendation ID/number.
- Type.
- Severity and expected benefit.
- Evidence from Insights.
- Affected schema.
- Suggested DDL.
- Application code owner or likely location.
- Safe implementation path.
- Validation plan.
- Rollback/revert plan.
- Approval requirement.
End with:
“No schema recommendations have been applied.”
1---2name: planetscale-schema-recommendations-agent-loop3description: Safely triage PlanetScale schema recommendations and turn them into reviewed branches, migrations, issues, or pull requests without applying production changes.4---5
6# Schema recommendations agent loop
7
8## Purpose
9
10Use PlanetScale schema recommendations as high-quality input to agents. Convert recommendations into safe implementation plans, issues, branches, migrations, or pull requests. Do not apply recommendations directly.
11
12## Inputs
13
14Collect:
15
16- Open schema recommendations.
17- Recommendation type.
18- Affected table, keyspace, schema, and query pattern.
19- Suggested DDL.
20- Supporting Insights evidence.
21- Application repository and migration system.
22- Engine: Vitess or Postgres.
23- Target branch.
24
25## Recommendation types to recognize
26
27- Add index for inefficient query.
28- Remove redundant index.
29- Prevent primary key ID exhaustion.
30- Drop unused table.
31- Upgrade legacy charset or collation.
32- Other DDL recommendation.
33
34## Triage questions
35
36For each recommendation, answer:
37
38- Is this still open and relevant?
39- Which query patterns triggered it?
40- Which application code paths generate those queries?
41- Is the recommendation safely expressible in the application’s migration framework?
42- Does the ORM/schema source of truth need to change?
43- Can it be tested on a non-production branch?
44- What is the expected impact on reads, writes, storage, and deploy time?
45- Is there a rollback or revert path?
46- Is there a competing recommendation or migration?
47
48## Engine-specific implementation path
49
50### Vitess
51
52Recommended path:
53
541. Create or use a development branch.
552. Apply the schema change to that branch only after approval.
563. Open a deploy request only after approval.
574. Use deploy request review to inspect schema, shard impact, data-loss warnings, lint errors, and conflicts.
585. Use normal safe migration path unless instant deployment is explicitly justified.
596. Deploy only after approval.
607. Monitor Insights and anomaly state after deployment.
61
62Default output before approval: issue or PR with migration proposal, not a live deploy request.
63
64### Postgres
65
66Recommended path:
67
681. Convert DDL into the application’s migration framework where possible.
692. Test against a non-production branch.
703. Run application tests and relevant query checks.
714. Open PR.
725. Apply production migration only after approval.
736. Use backups/PITR runbook as recovery plan, not as a substitute for migration review.
74
75Default output before approval: migration PR or issue, not production DDL.
76
77## Codebase correlation
78
79When a repository is available:
80
81- Search for the table and column names.
82- Search for ORM model definitions.
83- Search for migrations.
84- Search for query fingerprints, route tags, job names, and controller/action names from Insights.
85- Identify whether the recommendation should be implemented in database DDL, ORM schema, raw migration, or application query code.
86
87## Safety checks before proposing implementation
88
89Block direct application when:
90
91- The recommendation is stale or already addressed.
92- The affected table is small enough that the benefit is unclear.
93- The index would be redundant with an existing index.
94- The index would hurt write-heavy workloads without enough read benefit.
95- The table appears unused but repository references are ambiguous.
96- Dropping a table or index lacks owner confirmation.
97- The migration framework has a different schema source of truth.
98- The recommendation targets production and no branch/test plan exists.
99
100## Output
101
102For each recommendation, produce:
103
104- Recommendation ID/number.
105- Type.
106- Severity and expected benefit.
107- Evidence from Insights.
108- Affected schema.
109- Suggested DDL.
110- Application code owner or likely location.
111- Safe implementation path.
112- Validation plan.
113- Rollback/revert plan.
114- Approval requirement.
115
116End with:
117
118“No schema recommendations have been applied.”