Function Signature
Description
Checks and displays the status of database migrations by comparing migrations that have been applied to the database against migration files in the migration folder. This helps you understand which migrations are pending, applied, or missing.Parameters
The database connection URL:
- PostgreSQL:
postgres://user:password@host:port/database?sslmode=disable - MySQL:
mysql://root:password@localhost:3306/app - MariaDB:
mariadb://root:password@localhost:3307/app - SQLite:
sqlite://./database.sqlite - LibSQL/Turso:
https://your-database.turso.io
Authentication token for LibSQL/Turso databases. Use
None for other database types.Name of the table used to track applied migrations. Should match the table name used in other migration operations.
Path to the directory containing migration files. Example:
"./migrations".Name of the schema dump file. Required for consistency with other operations.
Timeout in seconds to wait for the database to be ready. Use
Some(30) for 30 seconds, or None for default timeout.Whether to display detailed status information. Set to
true for verbose output showing all migrations, false for a summary.Return Value
ReturnsResult<()> which:
- Returns
Ok(())after successfully checking and displaying migration status - Returns
Errif there was a connection error or the migration folder doesn’t exist
Usage Example
Non-Verbose Status Check
LibSQL/Turso Example
Output Information
The function logs migration status information to the console. The exact format depends on theverbose parameter:
Verbose Mode (verbose: true)
Shows detailed information about each migration:
- List of all applied migrations with timestamps
- List of pending migrations that need to be applied
- Any migrations in the database that don’t have corresponding files
Non-Verbose Mode (verbose: false)
Shows a summary:
- Total number of applied migrations
- Total number of pending migrations
- Whether the database is up to date
Behavior
- Connects to the database
- Creates the migration tracking table if it doesn’t exist
- Retrieves all applied migrations from the tracking table
- Reads all
.up.sqlmigration files from the migration folder - Compares the two lists to determine:
- Which migrations have been applied
- Which migrations are pending
- If there are any inconsistencies
- Logs the status information to the console
Migration Status States
Applied Migrations
Migrations that exist in both the database tracking table and the migration folder. These have been successfully applied to the database.Pending Migrations
Migrations that exist in the migration folder but not in the database tracking table. These need to be applied usingmigrate_database.
Missing Migration Files
Migrations that are recorded in the database but don’t have corresponding files in the migration folder. This can happen if:- Migration files were deleted after being applied
- The migration folder path is incorrect
- You’re checking a different migration folder than was used originally
Use Cases
Pre-Deployment Check
CI/CD Pipeline Integration
Development Workflow
Error Handling
The function may return errors in these cases:- Database connection failure
- Migration folder doesn’t exist or is unreadable
- Invalid database URL
- Insufficient permissions to read migration files
- Timeout waiting for database to be ready
Best Practices
- Run before migrations: Always check status before applying migrations to understand what will change
-
Use verbose mode in development: Set
verbose: truewhen developing to see detailed information -
Use non-verbose mode in production: Set
verbose: falsein automated deployments for cleaner logs - Verify after deployment: Check status after deploying to confirm all migrations were applied
- Monitor for missing files: Watch for warnings about migrations in the database without corresponding files
See Also
- migrate_database - Apply pending migrations
- migate_down - Rollback migrations
- new_migration - Create new migration files