Skip to content

Conversation

dhartunian
Copy link
Collaborator

This command can be invoked in Claude Code using
/schema-migration <prompt> in order to generate code for a new schema migration.

The instructions were generated by Claude Code with some minor tweaks.

Epic: None
Release note: None

@cockroach-teamcity
Copy link
Member

This change is Reviewable

Copy link
Collaborator

@rafiss rafiss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name "schema migration" threw me off here. From what i understand from the md file, this is more about the upgrade steps defined in pkg/upgrade (formerly known as pkg/migration). "Schema migration" may be a bit misleading, since not all upgrades involve schema migrations -- only the ones that are about modifying the system database schema do that.

@@ -0,0 +1,447 @@
# CockroachDB Schema Migration Construction
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd call these "upgrade migration" throughout

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.


**Important:** Always use the next available even Internal number. Check existing versions to see what's already used.

### 2. Create the Migration File
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I personally prefer to reverse the order here: I only add the upgrade after I've modified the bootstrap catalog and tested my feature against the updated schema, since I often need to iterate on the schema a little as I do. Once I've arrived at a schema that works for my feature, I add the upgrade for existing clusters once, rather than doing that first and needing to keep updating it as I tweak my new schema.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

CREATE INDEX IF NOT EXISTS your_index ON table (column)
```

2. **Use explicit column families** for new columns:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

huh? why?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this was picked up from some existing old migrations that used them. I removed references to column families.


### 2. Create the Migration File

**File:** `pkg/upgrade/upgrades/v25_4_your_feature_name.go`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should mention the rule about the version in the filename (and test).
maybe ask Claude to read https://cockroachlabs.atlassian.net/wiki/spaces/ENG/pages/2775876082/Guidelines+for+writing+cluster+version-specific+code+and+using+version+gates and ensure these instruction reflect its content?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

This command can be invoked in Claude Code using
`/upgrade-migration <prompt>` in order to generate code for a new
upgrade migration.

The instructions were generated by Claude Code with some minor tweaks.

Epic: None
Release note: None
@dhartunian dhartunian force-pushed the davidh/push-uvmxvmpkxsou branch from 05efc0b to 1a2db42 Compare September 2, 2025 15:15
@dhartunian dhartunian requested a review from dt September 2, 2025 15:16
@dhartunian
Copy link
Collaborator Author

This command was used to generate the work in #152861

@dhartunian dhartunian changed the title CLAUDE: add schema-migration command CLAUDE: add upgrade-migration command Sep 2, 2025
@dhartunian
Copy link
Collaborator Author

Closing this. It's not as useful as I imagined. After trying it out on a real use case I linked above, it saved me almost no time in the end because I had to do so much tweaking anyway. I think a future iteration should:

  1. Carefully write out steps by hand instead of generating them with the LLM. There's a lot of detail and nuance that wasn't captured
  2. Consider building a sub-agent that's purely focused on the datadriven test rewrites and can help with that in the background instead of writing the schema change and migration, which needs more attention to detail.

@dhartunian dhartunian closed this Sep 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants