drawdb-io / drawdb

Free, simple, and intuitive online database diagram editor and SQL generator.
https://drawdb.app
GNU Affero General Public License v3.0
20.03k stars 1.42k forks source link

Can ER diagram of already created database be created automagically? #17

Open dineshdharme opened 5 months ago

dineshdharme commented 5 months ago

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

michabbb commented 5 months ago

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

1ilit commented 5 months ago

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

michabbb commented 5 months ago

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

1ilit commented 5 months ago

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.

michabbb commented 5 months ago

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:

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 😏

1ilit commented 5 months ago

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

michabbb commented 5 months ago

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 😏