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. Checkout the integration examples for demonstration.

Migration Crate

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

async-std = { version = "1", features = ["attributes", "tokio1"] }

version = "0.12"
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.
# View the list of supported features at
# e.g.
# "runtime-tokio-rustls", # `ASYNC_RUNTIME` feature
# "sqlz-mssql", # `DATABASE_DRIVER` feature

Entity Crate

Specify SeaORM X dependency.

sea-orm = { version = "0.12", 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 we want to bundle the migration utility as part of your app, you'd also want to import the migration crate.

members = [".", "entity", "migration"]

entity = { path = "entity" }
migration = { path = "migration" } # depends on your needs

sea-orm = { version = "0.12", path = "<SEA_ORM_X_ROOT>/sea-orm-x", features = [..] }