tedivm / paracelsus

Visualize SQLAlchemy Databases using Mermaid or Dot Diagrams.
https://pypi.org/project/paracelsus/
MIT License
94 stars 10 forks source link

Option to Preserve Column Order #14

Closed selfdanielj closed 5 months ago

selfdanielj commented 5 months ago

Thanks for the great tool!

Right now the table fields are sorted with PK fields first, then FK fields, then the rest of the fields. In my case I'd like to preserve the order columns are defined in the class in the ouput diagrams. I made a few mods and built the project locally to implement this for my immediate needs.

Would you be open to a PR that leaves the current sorting behavior as the default and adds an option to preserve the field order in the tables?

For instance:

paracelsus graph example_app.models.base:Base \
  --import-module "example_app.models.users" \
  --import-module "example_app.models.posts" \
  --import-module "example_app.models.comments" \
  --preserve-order

or

[tool.paracelsus]
base = "example.base:Base"
imports = [
  "example.models"
]
preserve-order = true

I have this working for graph and mermaid output but would need to verify and add some tests for inject and dot output. I don't really have a time frame for this but thought it might be useful to others and would allow me to incorporate paracelsus into an automated build process.

tedivm commented 5 months ago

I would absolutely be open to a PR allowing custom sort options. Rather than a --preserve-order flag I'd prefer a sort flag that takes options though: --sort=default, --sort=preserve. That way we can add other options in the future.

tedivm commented 5 months ago

Actually can you make it --column-sort instead? I'm thinking we'll have table sorts as well in the future (the difference being mermaids TB, BT, RL, and LR). I've already run into a few cases where changing the table sorting would have been helpful.