* feat(cli): add 'migration generate' subcommand This subcommend will create a new, empty migration. * feat(deps): add chrono crate This crate will allow me to fetch the current date and time required for generating the migration filename. * feat(cli): generate migration filename * feat(cli): read template, replace migration name * feat(cli): write modified content to file * feat(deps): add regex crate Allows me to parse the lib.rs file containing the migrator logic. * fix(cli): add missing chrono import * feat(cli): mod declaration for new migration This modifies the existing migator file, adding a module declaration for the newly generated migration. * feat(cli): regenerate migration vector * feat(cli): write updated migrator file to disk This completes updating the migrator file with the new migration information. * docs(cli): additional docstring * refactor(cli): move logic into functions * test(cli): create new migration happy path * test(cli): update migrator happy path * fix(cli): dedicated tmp dir for test This avoids conflicts with the other tests. * style(cli): align generated code with cargofmt As suggested by @billy1624 in the review of #656. * feat(cli): harden regex against extra spaces As suggested by @billy1624 in the review of #656. Co-authored-by: Billy Chan <ccw.billy.123@gmail.com>
SeaORM CLI
Install and Usage:
> cargo install sea-orm-cli
> sea-orm-cli help
Or:
> cargo install --bin sea
> sea help
Getting Help:
cargo run -- -h
Running Entity Generator:
# MySQL (`--database-schema` option is ignored)
cargo run -- generate entity -u mysql://sea:sea@localhost/bakery -o out
# SQLite (`--database-schema` option is ignored)
cargo run -- generate entity -u sqlite://bakery.db -o out
# PostgreSQL
cargo run -- generate entity -u postgres://sea:sea@localhost/bakery -s public -o out
Running Migration:
- Initialize migration directory
cargo run -- migrate init
- Apply all pending migrations
cargo run -- migrate
cargo run -- migrate up
- Apply first 10 pending migrations
cargo run -- migrate up -n 10
- Rollback last applied migrations
cargo run -- migrate down
- Rollback last 10 applied migrations
cargo run -- migrate down -n 10
- Drop all tables from the database, then reapply all migrations
cargo run -- migrate fresh
- Rollback all applied migrations, then reapply all migrations
cargo run -- migrate refresh
- Rollback all applied migrations
cargo run -- migrate reset
- Check the status of all migrations
cargo run -- migrate status