A database migration is a versioned SQL change that moves a database to a new schema state. In a Rust service, migrations run during database-pool initialization before routes start. section 9.5 section 9.5.3
Implement migrations with a deliberate workflow:
- Write the migration yourself, then let SQLx apply it with sqlx::migrate!().run(&dbpool). section 9.5.3
- Keep migrations correct and idempotent; provide both up and down directions when backward migrations are required. section 9.5.3
- Treat database creation and migration as stateful, destructive operations: verify the target database before running them. section 9.5.3
- Choose a database driver deliberately because SQL statements and database behavior vary despite shared SQL syntax. section 9.5.3
Creating a todos schema
Run sqlx migrate add todos, then populate the generated migrations/20230701202642_todos.sql file with a CREATE TABLE statement. The migration creates a todos table with a non-null integer primary key, body, completion flag, and creation and update timestamps. section 9.6.1


















