PHPackages                             haakco/laravel-postgres-helper - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. haakco/laravel-postgres-helper

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

haakco/laravel-postgres-helper
==============================

Helper functions for postgres in Laravel

v4.0.10(1mo ago)02842MITPHPPHP &gt;=8.3CI failing

Since Jan 23Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/haakco/laravel-postgres-helper)[ Packagist](https://packagist.org/packages/haakco/laravel-postgres-helper)[ Docs](https://github.com/haakco/laravel-postgres-helper)[ RSS](/packages/haakco-laravel-postgres-helper/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (16)Versions (36)Used By (2)

Laravel PostgreSQL Helper
=========================

[](#laravel-postgresql-helper)

A comprehensive PostgreSQL utility package for Laravel applications that provides automatic sequence management, trigger automation, and database health monitoring.

Installation
------------

[](#installation)

```
composer require haakco/laravel-postgres-helper
```

Requirements
------------

[](#requirements)

- PHP 8.3+
- Laravel 10, 11, or 12
- PostgreSQL 13+

Testing
-------

[](#testing)

### Prerequisites

[](#prerequisites)

The integration tests require a PostgreSQL database. You have three options:

#### Option 1: Docker Compose (Recommended)

[](#option-1-docker-compose-recommended)

```
# Start the test database
just up
# or
docker-compose up -d

# Stop the containers
just down
# or
docker-compose down
```

**Docker Services:**

- **Main Database**: `localhost:5432` (database: `laravel_postgres_helper`)
- **Test Database**: `localhost:5433` (database: `laravel_postgres_helper_test`)
- **Username**: `postgres` / **Password**: `postgres`
- **PostgreSQL Version**: 16 with extensions (TimescaleDB, PostGIS, pg\_stat\_statements)

**Note**: The Docker setup uses development-optimized settings (fsync=off) for better performance. Never use these settings in production!

#### Option 2: Justfile Commands

[](#option-2-justfile-commands)

```
# Complete setup with database
just setup

# Or just reset the database
just db-reset
```

#### Option 3: Manual Setup

[](#option-3-manual-setup)

1. Copy the test environment file:

```
cp .env.testing.example .env.testing
```

2. The default configuration uses Docker Compose settings:

```
DB_TEST_HOST=127.0.0.1
DB_TEST_PORT=5433
DB_TEST_DATABASE=laravel_postgres_helper_test
DB_TEST_USERNAME=postgres
DB_TEST_PASSWORD=postgres

```

### Running Tests

[](#running-tests)

```
# Run all tests
composer test
# or
just test

# Run only unit tests (no database required)
composer test-unit
# or
just test-unit

# Run only integration tests
composer test-integration
# or
just test-integration

# Run with coverage
composer test-coverage
# or
just test-coverage

# Run tests with automatic database setup
just test-with-db
```

Development Commands
--------------------

[](#development-commands)

### Justfile Commands

[](#justfile-commands)

```
# Install dependencies
just install

# Linting and formatting
just lint          # Auto-fix all issues
just lint-check    # Check without fixing
just format        # PHP-CS-Fixer only
just phpstan       # PHPStan analysis only

# Testing
just test          # Run all tests
just test-unit     # Unit tests only
just test-integration # Integration tests only
just test-coverage # Generate coverage report

# Database management
just up            # Start Docker containers
just down          # Stop Docker containers
just db-reset      # Reset test database
just db            # Access main PostgreSQL
just db-test       # Access test PostgreSQL

# Quality assurance
just fix-all       # Lint and test
just check-all     # Check everything
just pre-commit    # Pre-commit checks

# Development workflow
just setup         # Complete setup
just dev           # Quick fix-all cycle
```

Upgrading from v3.x to v4.x
---------------------------

[](#upgrading-from-v3x-to-v4x)

When upgrading from version 3.x to 4.x, the package includes a migration that will automatically update your PostgreSQL functions to the latest versions:

```
# After upgrading the package
composer update haakco/laravel-postgres-helper

# Run migrations to update PostgreSQL functions
php artisan migrate
```

The migration `2025_01_25_000001_update_postgres_helper_functions_v4.php` will:

- Update all PostgreSQL helper functions to their latest definitions
- Add a comment to track the update
- Use `CREATE OR REPLACE` so it's safe to run multiple times

If you prefer to update manually without migrations:

```
// Update all functions manually
PgHelperLibrary::updateDateColumnsDefault();
PgHelperLibrary::addUpdateUpdatedAtColumn();
PgHelperLibrary::addUpdateUpdatedAtColumnForTables();
PgHelperLibrary::addFixAllSeq();
PgHelperLibrary::addFixDb();
```

Usage
-----

[](#usage)

### Basic Usage

[](#basic-usage)

```
use HaakCo\PostgresHelper\Libraries\PgHelperLibrary;

// Fix all sequences after inserting records with explicit IDs
PgHelperLibrary::fixAll();

// Fix only specific tables (much faster)
PgHelperLibrary::fixSequences(['users', 'permissions']);

// Fix triggers for tables with updated_at columns
PgHelperLibrary::fixTriggers(['users', 'posts']);
```

### Health Checks

[](#health-checks)

```
// Run comprehensive health check
$health = PgHelperLibrary::runHealthCheck();
echo "Database health: {$health['overall_score']}%";

// Validate table structure
$validation = PgHelperLibrary::validateStructure();
if (!$validation['valid']) {
    // Handle validation errors
}
```

Troubleshooting
---------------

[](#troubleshooting)

### Docker Issues

[](#docker-issues)

**Port Conflicts:**If you have PostgreSQL already running locally, change the ports in your `.env` file:

```
DB_PGSQL_PORT=5434
DB_PGSQL_TEST_PORT=5435
```

**Connection Issues:**

```
# Check container status
docker-compose ps

# View logs
docker-compose logs postgres
docker-compose logs postgres-test
```

**Reset Databases:**

```
# Remove all data and recreate fresh databases
docker-compose down -v
docker-compose up -d
```

### Test Database Issues

[](#test-database-issues)

**"uuid\_generate\_v4() does not exist" error:**

```
# The test database needs the uuid-ossp extension
just db-reset
# or manually:
createdb laravel_postgres_helper_test
psql laravel_postgres_helper_test -c "CREATE EXTENSION IF NOT EXISTS \"uuid-ossp\";"
```

License
-------

[](#license)

MIT

###  Health Score

49

—

FairBetter than 95% of packages

Maintenance90

Actively maintained with recent releases

Popularity11

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity72

Established project with proven stability

 Bus Factor1

Top contributor holds 90.7% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~35 days

Recently: every ~56 days

Total

34

Last Release

51d ago

Major Versions

v1.1.1 → v3.0.02024-01-28

v3.0.14 → v4.0.12025-06-14

PHP version history (3 changes)v1.0.3PHP &gt;=8.0

v1.1.0PHP ^8.0

v4.0.1PHP &gt;=8.3

### Community

Maintainers

![](https://www.gravatar.com/avatar/e15a429a90f3adbe239550525faa6cf2d2d32b9bd8add3a97255f9dacabee805?d=identicon)[haakco](/maintainers/haakco)

---

Top Contributors

[![timhaak](https://avatars.githubusercontent.com/u/271607?v=4)](https://github.com/timhaak "timhaak (68 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (7 commits)")

---

Tags

laravelPostgresHelper

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan, Rector

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/haakco-laravel-postgres-helper/health.svg)

```
[![Health](https://phpackages.com/badges/haakco-laravel-postgres-helper/health.svg)](https://phpackages.com/packages/haakco-laravel-postgres-helper)
```

###  Alternatives

[barryvdh/laravel-ide-helper

Laravel IDE Helper, generates correct PHPDocs for all Facade classes, to improve auto-completion.

14.9k123.0M687](/packages/barryvdh-laravel-ide-helper)[kyslik/column-sortable

Package for handling column sorting in Laravel 6.x

6485.6M21](/packages/kyslik-column-sortable)[laracraft-tech/laravel-useful-additions

A collection of useful Laravel additions!

58109.4k](/packages/laracraft-tech-laravel-useful-additions)[glhd/special

1929.4k](/packages/glhd-special)[bjuppa/laravel-blog

Add blog functionality to your Laravel project

483.3k2](/packages/bjuppa-laravel-blog)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
