Skip to main content

Setting Up Migration

Installing SeaORM X CLI

Install sea-orm-cli with cargo locally.

cargo install --path "<SEA_ORM_X_ROOT>/sea-orm-x/sea-orm-cli"

Workspace Structure

It is recommended to structure your cargo workspace as follows to share SeaORM entities between the app crate and the migration crate. Check out the integration examples for demonstration.

Migration Crate

Import the sea-orm-migration and async-std crate.

migration/Cargo.toml
[dependencies]
async-std = { version = "1", features = ["attributes", "tokio1"] }

[dependencies.sea-orm-migration]
version = "2.0.0-rc"
path = "<SEA_ORM_X_ROOT>/sea-orm-x/sea-orm-migration"
features = [
# Enable at least one `ASYNC_RUNTIME` and `DATABASE_DRIVER` feature if you want to run migration via CLI.
# e.g.
# "runtime-tokio-rustls", # `ASYNC_RUNTIME` feature
# "sqlz-mssql", # `DATABASE_DRIVER` feature
]

Entity Crate

Specify SeaORM X dependency.

entity/Cargo.toml
[dependencies]
sea-orm = { version = "2.0.0-rc", path = "<SEA_ORM_X_ROOT>/sea-orm-x" }

App Crate

This is where the application logic goes.

Create a workspace that contains app, entity and migration crates and import the entity crate into the app crate.

If you want to bundle the migration utility as part of your app, also import the migration crate.

./Cargo.toml
[workspace]
members = [".", "entity", "migration"]

[dependencies]
entity = { path = "entity" }
migration = { path = "migration" }

[dependencies.sea-orm]
version = "2.0.0-rc"
path = "<SEA_ORM_X_ROOT>/sea-orm-x"
features = ["sqlz-mssql", "runtime-tokio-rustls", "macros"]