Available on crate feature
migration only.Expand description
This module contains migrations to help adding the sessions table required for this crate.
§Example - Single migration
If you don’t need to run any other migrations the Migrator struct can be used directly
use async_sea_orm_session::migration::Migrator;
use async_sea_orm_session::DatabaseSessionStore;
use sea_orm::{Database, DatabaseConnection};
use sea_orm_migration::MigratorTrait;
let db: DatabaseConnection =
Database::connect("protocol://username:password@host/database").await?;
// Run the async-sea-orm-session migration, if it hasn't already been run.
Migrator::up(&db, None).await?;
let store = DatabaseSessionStore::new(db);§Example - Multiple migrations
The previous example isn’t super useful because it doesn’t allow you to run other migrations.
To resolve this you should include SessionTableMigration directly in your own
MigratorTrait implementation, as in the example below:
ⓘ
// In migrations/src/lib.rs
pub use sea_orm_migration::prelude::*;
use async_sea_orm_session::migration::SessionTableMigration;
mod m20220101_000001_sample_migration;
mod m20220102_000002_some_other_migration;
pub struct Migrator;
#[async_trait::async_trait]
impl MigratorTrait for Migrator {
fn migrations() -> Vec<Box<dyn MigrationTrait>> {
vec![
Box::new(m20220101_000001_sample_migration::Migration),
Box::new(m20220102_000002_some_other_migration::Migration),
Box::new(SessionTableMigration),
]
}
}