Overview
Thegeni up command applies all pending migrations to your database, bringing it to the latest version. It automatically tracks which migrations have been applied and only runs new ones.
Usage
Required Environment Variables
The database connection string. Format varies by database type.Examples:
- PostgreSQL:
postgres://user:password@localhost:5432/dbname?sslmode=disable - MySQL:
mysql://root:password@localhost:3306/app - MariaDB:
mariadb://root:password@localhost:3307/app - SQLite:
sqlite://./database.sqlite - LibSQL:
https://localhost:6000
Optional Environment Variables
Authentication token for LibSQL/Turso databases. Only required when connecting to Turso or LibSQL instances that require authentication.
Path to the directory containing migration files.
Name of the table used to track applied migrations.
Filename for the dumped database schema.
Number of seconds to wait for the database to be ready before timing out. Useful when the database needs time to boot.
Set to
true to disable automatic schema dumping after migrations.How It Works
- Connect to the database using the provided URL
- Create the migrations tracking table if it doesn’t exist
- Scan the migrations folder for
.up.sqlfiles - Compare with applied migrations in the database
- Execute pending migrations in timestamp order
- Record each successful migration in the tracking table
- Dump the database schema to a file (unless disabled)
Examples
PostgreSQL
MySQL
SQLite
For SQLite, Geni will automatically create the database file if it doesn’t exist.
LibSQL/Turso
Custom Configuration
In CI/CD
Transaction Behavior
By default, each migration runs inside a database transaction. If a migration fails:- The transaction is rolled back
- The migration is not recorded as applied
- Geni exits with an error
- No subsequent migrations are run
Disabling Transactions
Some operations cannot run in transactions. Add this comment to the top of your migration file:Schema Dumping
After successfully applying migrations, Geni automatically dumps your database schema to a file. This provides:- Version control: Track schema changes alongside code
- Documentation: See the current database structure at a glance
- Disaster recovery: Reconstruct schema from a known good state
Generated Schema File
By default, createsschema.sql in your migrations folder:
Disable Schema Dumping
Migration Tracking Table
Geni creates a table (default:schema_migrations) to track applied migrations:
Error Handling
No Migrations Found
DATABASE_MIGRATIONS_FOLDER correctly.
Connection Failed
DATABASE_URL environment variable.
Migration Failed
geni up again.
Docker Usage
CI/CD Integration
GitHub Actions
GitLab CI
Best Practices
- Test locally first: Run
geni uplocally before deploying - Use transactions: Keep the default transaction behavior unless necessary
- Check status first: Run
geni statusto see what will be applied - Backup production: Always backup production databases before running migrations
- Monitor execution: Watch for errors during migration application
- Version control schema: Commit the generated
schema.sqlfile
Next Steps
Rollback Migrations
Undo migrations with
geni downCheck Status
View migration status with
geni statusDump Schema
Export schema with
geni dumpCreate Database
Initialize database with
geni create