akron db makemigrations

Generate migration files automatically from schema changes in your akron.json configuration.

NEW COMMAND

akron db makemigrations

Automatically generate migration files by comparing your current schema with the last snapshot.

Syntax

1akron db makemigrations [OPTIONS]

Options

OptionDescriptionDefault
--nameCustom name for the migration fileAuto-generated

How It Works

Schema Change Detection

  1. Reads your current akron.json schema definition
  2. Compares it with the last saved schema snapshot
  3. Identifies changes (new tables, modified columns, etc.)
  4. Generates migration steps to transform the database
  5. Creates a migration file in .akron/ directory
  6. Updates the schema snapshot for future comparisons

Examples

Auto-generated Migration Name

Generate migration with automatic naming:

1akron db makemigrations
Expected Output
āœ… Generated migration: migration_0001
   File: .akron/migration_0001.json
   Steps: 3

šŸ“‹ Migration preview:
   1. Create table 'users'
   2. Create table 'posts'
   3. Create table 'comments'

Custom Migration Name

Generate migration with descriptive name:

1akron db makemigrations --name "add_user_authentication"
Expected Output
āœ… Generated migration: add_user_authentication
   File: .akron/add_user_authentication.json
   Steps: 2

šŸ“‹ Migration preview:
   1. Add column 'password_hash' to 'users'
   2. Add column 'last_login' to 'users'

No Changes Detected

When schema hasn't changed:

1akron db makemigrations
Expected Output
āœ… No changes detected in schema.

Migration File Structure

Generated Migration File

Example migration file structure:

1{
2 "name": "add_user_posts",
3 "timestamp": "2023-12-01T10:30:00.000000",
4 "steps": [
5 {
6 "action": "create_table",
7 "table": "users",
8 "schema": {
9 "id": "int",
10 "email": "str",
11 "username": "str",
12 "created_at": "datetime"
13 }
14 },
15 {
16 "action": "create_table",
17 "table": "posts",
18 "schema": {
19 "id": "int",
20 "title": "str",
21 "content": "text",
22 "author_id": "int"
23 }
24 }
25 ],
26 "checksum": "sha256_hash_of_current_schema"
27}

Supported Migration Actions

Table Operations

  • create_table - Create new tables
  • drop_table - Remove existing tables

Column Operations

  • add_column - Add new columns
  • drop_column - Remove columns
  • modify_column - Change column types

Best Practices

āœ… Do

  • • Use descriptive migration names for complex changes
  • • Generate migrations frequently for small, incremental changes
  • • Review the migration preview before applying
  • • Keep your akron.json file in version control

āŒ Don't

  • • Make manual changes to migration files
  • • Delete migration files after they've been applied
  • • Skip generating migrations for schema changes
  • • Make breaking changes without considering data migration

Next Steps

After generating migrations:

  1. Review the generated migration file for accuracy
  2. Run akron db migrate --dry-run to preview changes
  3. Apply migrations with akron db migrate
  4. Check status with akron db status