Skip to content
Back to skills

New Migration

ASecurity

Create a new Fleet database migration with timestamp naming, Up function, init registration, and test file.

  • 7,278 stars
  • 0 votes
  • 0 copies
  • 3 views
  • Added November 13, 2026
businessgobashsqltestinggitdatabase

Works with

  • cli

Security analysis

A100/100

Scanned November 13, 2026

npx -y skills add fleetdm/fleet --skill new-migration --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of New Migration?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for New Migration
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/fleetdm-new-migration/badge)](https://www.skillsdirectory.com/skills/fleetdm-new-migration)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: new-migration
description: Create a new Fleet database migration with timestamp naming, Up function, init registration, and test file.
allowed-tools: Bash(date *), Bash(make migration *), Bash(go build *), Bash(go test *), Bash(MYSQL_TEST*), Read, Write, Grep, Glob
model: sonnet
effort: medium
---

# Create a New Database Migration

Create a migration for: $ARGUMENTS

## Process

### 1. Generate Timestamp and Name
Use `make migration name=CamelCaseName` if available, or generate manually:
```bash
date +%Y%m%d%H%M%S
```
The migration name should be descriptive CamelCase (e.g., `AddRecoveryLockAutoRotateAt`, `CreateTableSoftwareInstallers`).

### 2. Create Migration File
Location: `server/datastore/mysql/migrations/tables/{TIMESTAMP}_{Name}.go`

```go
package tables

import "database/sql"

func init() {
	MigrationClient.AddMigration(Up_{TIMESTAMP}, Down_{TIMESTAMP})
}

func Up_{TIMESTAMP}(tx *sql.Tx) error {
	_, err := tx.Exec(`
		-- SQL statement here
	`)
	return err
}

func Down_{TIMESTAMP}(tx *sql.Tx) error {
	return nil
}
```

### 3. Create Test File (data migrations only)
Only needed when the migration modifies data: changing existing data, adding new data, or populating a table. A migration that only adds a
table, column, or index does not need a test file.

Location: `server/datastore/mysql/migrations/tables/{TIMESTAMP}_{Name}_test.go`

```go
package tables

import (
	"testing"

	"github.com/stretchr/testify/require"
)

func TestUp_{TIMESTAMP}(t *testing.T) {
	db := applyUpToPrev(t)

	// Set up test data before migration if needed

	applyNext(t, db)

	// Verify migration applied correctly
	// e.g., check table exists, columns added, data migrated
}
```

### 4. Verify
- Run `go build ./server/datastore/mysql/migrations/...` to check compilation
- Run `MYSQL_TEST=1 go test -run TestUp_{TIMESTAMP} ./server/datastore/mysql/migrations/tables/` to test the migration

## Rules
- Every migration MUST have a test file
- Down migrations are always no-ops (`return nil`) — Fleet doesn't use rollback migrations
- Never modify existing migration files — create new ones
- Data migrations go in the `data/` subdirectory

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in business →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.