agronholm / sqlacodegen

Automatic model code generator for SQLAlchemy
Other
1.85k stars 241 forks source link

Deterministic ordering of the classes #186

Open MatthieuBizien opened 2 years ago

MatthieuBizien commented 2 years ago

I just discovered sqlacodegen, and it looks great! Combined with Alembic, I can do 2-way modifications of the schema, and keep everything synced.

The git diff generated are very large, I use autoflake --remove-all-unused-imports --remove-unused-variables --in-place + black to make them cleaner.

The only remaining noise in the git diff is that the classes order is not always the same, maybe because the dependencies change.

Could it be possible to add an option to sort the classes by names?

agronholm commented 2 years ago

The tables/classes are indeed sorted by dependencies, so any dependent classes come before the ones that require them, except of course when there are cyclic dependencies. Unless you are getting nondeterministic results for the same underlying database schema, then I don't consider this to be a bug. Somebody could add an option for alphabetically sorting the tables, but I don't think I'm going to do it.