npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

laravel-db-summary

v1.1.2

Published

A tool to summarize Laravel database structure from migration files

Downloads

7

Readme

Laravel SummDB - DB Summarizer

This tool analyzes Laravel migration files and generates a summary of the database structure, including an Entity-Relationship Diagram (ERD) using Mermaid.js syntax.

npm version License GitHub stars GitHub tag NPM Downloads


Package Name

The name of the package on the github repo is a portmanteau of 'Summed Up' to denote a summing up of the DB of the app.

The npm package name however is a clear and understandable 'laravel-db-summary'.

Installation

You can install Laravel DB Summarizer globally using npm:

npm install -g laravel-db-summary

Or use it directly with npx:

npx laravel-db-summary

Usage

There are two ways to use Laravel DB Summarizer:

  1. Interactive Mode: Run the tool without any arguments, and it will prompt you for the Laravel project path:
laravel-db-summary
  1. Command Line Mode: Provide the path to your Laravel project as an argument:
laravel-db-summary /path/to/your/laravel/project

Output

The script generates three files in a 'db-summary' directory:

  1. text-summary.txt: A text summary of each table, its columns, and foreign key relationships.
  2. erd.mmd: Mermaid.js ERD code that can be visualized using tools like the Mermaid Live Editor.
  3. erd.png: A PNG image of the Entity-Relationship Diagram (requires Mermaid CLI to be installed).

If you don't have Mermaid CLI installed, you can still use the erd.mmd file to generate the diagram online.

Requirements

  • Node.js (version 12.0.0 or higher)
  • A Laravel project with migration files

Integrating with CI/CD Pipeline

To include Laravel DB Summarizer as part of your CI/CD pipeline, follow these steps:

  1. Install Laravel DB Summarizer in your CI environment: Add this to your CI configuration file (e.g., .gitlab-ci.yml, .github/workflows/main.yml):

    - npm install -g laravel-db-summary
  2. Run Laravel DB Summarizer: Add a step in your CI pipeline to run the tool:

    - laravel-db-summary /path/to/your/laravel/project
  3. Archive the generated files: Configure your CI to archive the db-summary directory as an artifact. For example, in GitLab CI:

    artifacts:
      paths:
        - db-summary/
  4. Optional: Generate PNG in CI: If you want to generate the PNG in your CI pipeline, ensure Mermaid CLI is installed:

    - npm install -g @mermaid-js/mermaid-cli
  5. Example GitLab CI configuration:

    stages:
      - build
      - test
      - document
    
    document_db:
      stage: document
      script:
        - npm install -g laravel-db-summary @mermaid-js/mermaid-cli
        - laravel-db-summary .
      artifacts:
        paths:
          - db-summary/
  6. Example GitHub Actions workflow:

    name: Document Database
    on: [push]
    jobs:
      document:
        runs-on: ubuntu-latest
        steps:
        - uses: actions/checkout@v2
        - name: Use Node.js
          uses: actions/setup-node@v2
          with:
            node-version: '14'
        - run: npm install -g laravel-db-summary @mermaid-js/mermaid-cli
        - run: laravel-db-summary .
        - uses: actions/upload-artifact@v2
          with:
            name: db-summary
            path: db-summary/

By following these steps, you'll ensure that every build of your Laravel application includes an up-to-date database summary and ERD.

Development

If you want to contribute or modify the tool:

  1. Clone the repository:
git clone https://github.com/the-provost/laravel-summdb.git
  1. Install dependencies:
cd laravel-summdb
npm install
  1. Make your changes and test them:
npm start

Note

This script parses migration files statically and may not capture all complex scenarios or dynamic schema modifications. It's designed as a quick summary tool and may not reflect the exact state of a database that has undergone manual modifications or complex migrations.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Issues

If you find a bug or have a suggestion, please file an issue on the GitHub repository.

Credits

Laravel SummDB makes use of the following open-source packages: