drawdb icon indicating copy to clipboard operation
drawdb copied to clipboard

Can ER diagram of already created database be created automagically?

Open dineshdharme opened this issue 1 year ago • 7 comments

Let's say I point to a database or create table as queries exported out of current database, can it automatically create a ER diagram.

Fuctionality similar to this : https://gitlab.com/Screwtapello/sqlite-schema-diagram/-/tree/main

dineshdharme avatar Apr 07 '24 18:04 dineshdharme

That was my very first question when I say this project 😉

michabbb avatar Apr 07 '24 21:04 michabbb

You can import a .sql file and the tables will be imported. Right now only tables in MySQL scripts get parsed and imported

1ilit avatar Apr 09 '24 04:04 1ilit

You mean a structure dump? Do foreign keys, indexes and triggers get recognized as well?

michabbb avatar Apr 09 '24 09:04 michabbb

Indexes yes, but it's a bit broken for relationships(so for FKs and triggers) now. The way things are now the program expects somewhat of a specific structure for the ast which I can imaging is not inclusive of all the different ways things can get defined. I hope to fix it this week.

1ilit avatar Apr 09 '24 10:04 1ilit

sounds interesting. this app would be extremely useful if you not just create a new DB from scratch, but also can modify and extend an existing database. the ultimate goal would be:

  • import an existing SQL structure
  • modify everything to your needs
  • export SQL queries based on your actions that represent the diff I can run on the live server

So whenever I change/add/delete something, a query should be written in some kind of transaction log. at the end, running the transaction log on my live server should modify everything to the same state I left in drawdb. i know this is very difficult because of foreign keys, adding and removing fields that are part of an index, and all that stuff that can block an alter-statement. so this is only loud thinking 😏

michabbb avatar Apr 09 '24 10:04 michabbb

Yes, this can be naively implemented with what we already have. I keep track of all changes or "deltas" for undo and redo which can be used to generate atomic queries. This can result in a lot of redundant queries though. I'll try to think of a smarter way to go about it. Let me know if you have any suggestions

1ilit avatar Apr 09 '24 11:04 1ilit

it´s just an idea 😏 i am thinking about some kind of transaction log where something gets deleted when you undo your last action. so when you add a column and delete it again. there is no need for "add column followed by delete column" , i just would delete the initial "add column" from the logs. but of course that only works if nothing is related to that column, like indexes, FK or triggers ;) with that (maybe) it is possible to reduce the noise. but at the end, i am pretty sure, nobody will care if the generated SQL queries look pretty or not, as long as they work and take care of every little relationship and run in the correct order so the script won´t fail in the middle of the run.... nobody will complain 😏

michabbb avatar Apr 09 '24 11:04 michabbb