sea-orm icon indicating copy to clipboard operation
sea-orm copied to clipboard

MigratorTrait with self

Open tyt2y3 opened this issue 1 month ago • 3 comments

#2803

tyt2y3 avatar Nov 11 '25 21:11 tyt2y3

@ctron can you try this and see if it works for you?

use crate::common::migration::*;
use sea_orm_migration::{MigratorTraitSelf, prelude::*};

pub struct Migrator {
    pub i: i32,
}

#[async_trait::async_trait]
impl MigratorTraitSelf for Migrator {
    fn migrations(&self) -> Vec<Box<dyn MigrationTrait>> {
        vec![
            Box::new(m20220118_000001_create_cake_table::Migration),
            Box::new(m20220118_000002_create_fruit_table::Migration),
        ]
    }
}

[patch.crates-io]
sea-orm-migration = { git = "https://github.com/SeaQL/sea-orm", branch = "migrator-self" }

tyt2y3 avatar Nov 11 '25 21:11 tyt2y3

I won't be able to actually try it out this week. But taking a quick look, that looks very promising. As the MigrationTrait already uses self, I should be able to pass in arguments to the actual migration. And so that should work!

ctron avatar Nov 12 '25 08:11 ctron

thanks, please give it a try and let me know. want to have some user feedback before merging this in.

tyt2y3 avatar Nov 12 '25 12:11 tyt2y3