DEV Community

Chikau Kume
Chikau Kume

Posted on

[Laravel] Bidirectional Sync Between Migrations and ER Diagrams for Automated Documentation

Introduction

As many of you working in IT development may know, development documentation often becomes outdated or doesn't exist at all in most projects.

ER diagrams are one type of documentation that, even when created initially, rarely get updated and end up diverging from the actual database structure. As a result, only the current migration files can be trusted, forcing developers to read through migrations and actual tables one by one to understand the DB structure.

Of course, we should "update ER diagrams whenever we update the code."
However, low-priority tasks tend to get postponed, and before we know it, we're left with ER diagrams that are completely out of sync with reality...
Sound familiar?

That's why I've added bidirectional synchronization between Laravel migrations and ER diagrams (PlantUML) to LAC.

For details about LAC and installation instructions, please see my previous article:
https://dev.to/chikau/95-faster-laravel-development-meet-lac-30gp

With this feature, you can generate ER diagrams based on the latest source code with a single command, eliminating management overhead while enabling documentation creation and maintenance. While development documentation includes various elements like screen transitions and basic design documents, I believe having at least an ER diagram helps understand the most crucial aspect of any system - data flow. This motivated me to create this feature.

How to Use

# ER Diagram → Migration
1. Create a .puml file and place it in storage/app/db/diagrams
2. Run the following command:
php artisan lac:gen-migration
3. Migration files will be generated in database/migrations

# Migration → ER Diagram
1. Create migration files
2. Run the following command:
php artisan lac:gen-diagram
3. A .puml file will be generated in storage/app/db/diagrams/generated
Enter fullscreen mode Exit fullscreen mode

For those who want to see it in action, please visit:
https://github.com/ChikauKume/laravel-arsenal-core/blob/main/README.md

Conclusion

Combined with the previously introduced Scaffold feature, this can significantly boost your development efficiency. Please give it a try!

📝 Feedback & Feature Requests

Feel free to share your requests and suggestions via GitHub Issues:
👉 https://github.com/ChikauKume/laravel-arsenal-core/issues

If you found this article helpful, please like, comment, and share!

Top comments (0)