Skip to content

MigratorTrait with self#2806

Merged
tyt2y3 merged 2 commits intomasterfrom
migrator-self
Feb 10, 2026
Merged

MigratorTrait with self#2806
tyt2y3 merged 2 commits intomasterfrom
migrator-self

Conversation

@tyt2y3
Copy link
Copy Markdown
Member

@tyt2y3 tyt2y3 commented Nov 11, 2025

@tyt2y3
Copy link
Copy Markdown
Member Author

tyt2y3 commented Nov 11, 2025

@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" }

@ctron
Copy link
Copy Markdown

ctron commented Nov 12, 2025

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!

@tyt2y3
Copy link
Copy Markdown
Member Author

tyt2y3 commented Nov 12, 2025

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

@tyt2y3
Copy link
Copy Markdown
Member Author

tyt2y3 commented Jan 9, 2026

@ctron got any fun?

@ctron
Copy link
Copy Markdown

ctron commented Jan 12, 2026

@ctron got any fun?

I'm so sorry. Especially as you came up with a quick fix like that. But I wasn't able to test it yet. It's still on my todo list, as this problem still persists and we do need a fix. So it still is relevant.

@tyt2y3
Copy link
Copy Markdown
Member Author

tyt2y3 commented Jan 12, 2026

no problem, I've rebased the branch

@ctron
Copy link
Copy Markdown

ctron commented Feb 10, 2026

Finally had some time to check this out. Yes, having this would be awesome!

@tyt2y3
Copy link
Copy Markdown
Member Author

tyt2y3 commented Feb 10, 2026

I hope there's no conflict!

@tyt2y3 tyt2y3 merged commit 5b9193d into master Feb 10, 2026
36 of 38 checks passed
@tyt2y3 tyt2y3 deleted the migrator-self branch February 10, 2026 21:54
@github-actions
Copy link
Copy Markdown

🎉 Released In 2.0.0-rc.32 🎉

Huge thanks for the contribution!
This feature has now been released, so it's a great time to upgrade.
Show some love with a ⭐ on our repo, every star counts!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants