trogers1884/laravel-dbdepends

A Laravel package that creates a view for PostgreSQL database dependencies

v1.0.0 2024-12-15 17:18 UTC

This package is auto-updated.

Last update: 2025-06-15 18:36:37 UTC


README

A Laravel package that creates a view for PostgreSQL database dependencies. This package helps you visualize and understand the relationships between tables, views, and materialized views in your PostgreSQL database by creating a comprehensive dependency map view.

Overview

The package creates a view named tr1884_dbdepends_vw_dependency_map that shows:

  • Direct and indirect dependencies between database objects
  • Object ownership information
  • Dependency counts and details
  • Requirements for each database object

Requirements

  • PHP 8.1 or higher
  • Laravel 10.x or 11.x
  • PostgreSQL database

Installation

  1. Install the package via composer:
composer require trogers1884/laravel-dbdepends
  1. The package will automatically register its service provider.

  2. Run the migrations to create the dependency map view:

php artisan migrate

Usage

Once installed, you can query the dependency map view like any other database view:

use Illuminate\Support\Facades\DB;

// Get all view dependencies
$views = DB::table('tr1884_dbdepends_vw_dependency_map')
    ->where('object_type', 'VIEW')
    ->get();

// Find objects with the most dependencies
$mostDependencies = DB::table('tr1884_dbdepends_vw_dependency_map')
    ->orderByDesc('deps')
    ->limit(10)
    ->get();

View Columns

The dependency map view includes the following columns:

Column Type Description
relation text Fully qualified name (schema.object_name)
object_type text TABLE, VIEW, or MATV (materialized view)
owner name Object owner's username
deps bigint Number of direct dependencies
add_deps integer Number of indirect dependencies
reqs bigint Number of direct requirements
add_reqs integer Number of indirect requirements
dependents text List of direct dependent objects
add_dependents text List of indirect dependent objects
requirements text List of direct required objects
add_requirements text List of indirect required objects

Testing

To run the tests locally:

  1. Copy the example PHPUnit configuration:
cp phpunit.xml.example phpunit.xml
  1. Update phpunit.xml with your local PostgreSQL database credentials:
<env name="DB_HOST" value="your_host"/>
<env name="DB_PORT" value="5432"/>
<env name="DB_DATABASE" value="your_database"/>
<env name="DB_USERNAME" value="your_username"/>
<env name="DB_PASSWORD" value="your_password"/>
  1. Run the tests:
./vendor/bin/phpunit

Note: phpunit.xml is git-ignored to prevent committing local database credentials.

Complete Uninstallation

To completely remove the package from your Laravel application:

  1. Drop the dependency map view from your database:
DROP VIEW IF EXISTS public.tr1884_dbdepends_vw_dependency_map;
  1. Remove the migration record from your migrations table:
DELETE FROM migrations 
WHERE migration = '2024_01_01_000001_create_tr1884_dbdepends_vw_dependency_map_view';
  1. Remove the package from your composer.json:
composer remove trogers1884/laravel-dbdepends
  1. Remove any cached configuration:
php artisan config:clear
composer dump-autoload

Contributing

Contributions are welcome! Please see CONTRIBUTING.md for details.

Development Setup

  1. Fork the repository
  2. Clone your fork
  3. Install dependencies:
composer install
  1. Copy the test configuration files:
cp phpunit.xml.example phpunit.xml
cp .env.example .env.testing
  1. Update both files with your PostgreSQL test database credentials
  2. Run the tests to ensure everything is set up correctly:
./vendor/bin/phpunit

Security

If you discover any security-related issues, please email [security contact] instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.