Overview
Thegeni new command generates a pair of timestamped migration files for your database changes. Each migration consists of an “up” file for applying changes and a “down” file for rolling them back.
Usage
Arguments
The name of the migration. Spaces will be converted to underscores and the name will be lowercased.Examples:
create_users_tableadd email columnCreateIndexOnPosts
How It Works
- Generates a Unix timestamp for versioning
- Creates two files in your migrations folder:
{timestamp}_{name}.up.sql- For applying the migration{timestamp}_{name}.down.sql- For rolling back the migration
- Each file contains a starter comment template
Environment Variables
Specifies the directory where migration files will be created. The folder will be created automatically if it doesn’t exist.
Examples
Basic Usage
Create a migration to add a users table:Using Custom Migration Folder
Migration with Spaces
Generated File Contents
Each generated file contains a template comment: _create_users_table.up.sql:Writing Migrations
After creating migration files, you need to add your SQL:Up Migration Example
Down Migration Example
The down migration should reverse all changes made in the up migration to ensure clean rollbacks.
Transaction Control
By default, Geni runs migrations in transactions. To disable transactions for a specific migration, add a comment at the top of the file:Best Practices
- Use descriptive names: Choose names that clearly describe what the migration does
- Keep migrations small: Focus on one logical change per migration
- Test rollbacks: Always ensure your down migration properly reverses the up migration
- Avoid manual timestamps: Let Geni generate timestamps to prevent conflicts
- Version control: Commit migration files to your repository
Common Patterns
Creating a Table
Altering a Table
Adding an Index
Data Migration
Next Steps
Apply Migrations
Run pending migrations with
geni upCheck Status
View pending migrations with
geni status