Skip to content

Make sea-orm-cli & sea-orm-migration dependencies optional#2367

Merged
tyt2y3 merged 5 commits into
SeaQL:masterfrom
xamgore:master
May 20, 2025
Merged

Make sea-orm-cli & sea-orm-migration dependencies optional#2367
tyt2y3 merged 5 commits into
SeaQL:masterfrom
xamgore:master

Conversation

@xamgore

@xamgore xamgore commented Sep 26, 2024

Copy link
Copy Markdown
Contributor

Addresses #2320.

My team is working on a workspace project. To make sure generated models are always the same, we decided to make sea-orm-cli a member crate. You may find details at the discussion 1889.

The problem is, sea-orm-cli/codegen feature imports all the database drivers, even though sqlite and mysql represent zero interest for me.

codegen = ["sea-schema/sqlx-all", "sea-orm-codegen"]

libsqlite-sys + sqlx-mysql + sqlx-sqlite take quite a few seconds in total compilation time, and I believe this could be improved.

image

I've gone through dependency-hell feature-shenanigans, but could easily make a mistake. So testing and merging this PR won't be easy. I tested the code on my local environment: tweaked all the possible combinations of features to see, whether the compiler would grumble. Also, I have patched my team project with local sea-orm codebase and tested it against it.

@xamgore

xamgore commented Sep 30, 2024

Copy link
Copy Markdown
Contributor Author

@billy1624 could you allow CI checks, please?

@xamgore

xamgore commented Apr 2, 2025

Copy link
Copy Markdown
Contributor Author

I've rebased the branch, probably some issues should be gone now.

Comment on lines -445 to -447
DbBackend::MySql => MySql.query_tables(),
DbBackend::Postgres => Postgres.query_tables(),
DbBackend::Sqlite => Sqlite.query_tables(),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would something like this work?

        #[cfg(feature = "sqlx-mysql")]
        DbBackend::MySql => MySql.query_tables(),
        #[cfg(feature = "sqlx-postgres")]
        DbBackend::Postgres => Postgres.query_tables(),
        #[cfg(feature = "sqlx-sqlite")]
        DbBackend::Sqlite => Sqlite.query_tables(),

if the feature is not enabled, the variant shouldn't exist

@xamgore xamgore Apr 13, 2025

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately not, as Rust needs the arms to be present. But the direction of thought is right, thank you

@xamgore

xamgore commented Apr 13, 2025

Copy link
Copy Markdown
Contributor Author

Ok, I've started testing against these two checks from the action scripts:

cargo clippy --manifest-path sea-orm-migration/Cargo.toml -- -D warnings
cargo clippy --manifest-path sea-orm-migration/Cargo.toml --features sqlx-postgres -- -D warnings

+on my personal project which uses the patched version

[patch.crates-io]
sea-orm = { git = "https://github.com/xamgore/sea-orm.git", branch = "master" }
sea-orm-cli = { git = "https://github.com/xamgore/sea-orm.git", branch = "master" }
sea-orm-migration = { git = "https://github.com/xamgore/sea-orm.git", branch = "master" }

It works.

Comment thread sea-orm-migration/src/migrator.rs Outdated

@tyt2y3 tyt2y3 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

works now!

@xamgore

xamgore commented May 8, 2025

Copy link
Copy Markdown
Contributor Author

@tyt2y3 thanks for all your work on this crate, truly amazing! 😌 ❤️

@tyt2y3 tyt2y3 merged commit 88f4bf1 into SeaQL:master May 20, 2025
36 checks passed
@github-actions

Copy link
Copy Markdown

🎉 Released In 1.1.12 🎉

Thank you everyone for the contribution!
This feature is now available in the latest release. Now is a good time to upgrade!
Your participation is what makes us unique; your adoption is what drives us forward.
You can support SeaQL 🌊 by starring our repos, sharing our libraries and becoming a sponsor ⭐.

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