PHPackages                             dipesh79/laravel-pg-reset-sequences - 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. dipesh79/laravel-pg-reset-sequences

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

dipesh79/laravel-pg-reset-sequences
===================================

Artisan command to reset PostgreSQL sequences after importing a SQL dump

1.0.0(2mo ago)017MITPHPPHP ^8.1

Since May 1Pushed 2mo agoCompare

[ Source](https://github.com/dipesh79/laravel-laravel-pg-reset-sequences)[ Packagist](https://packagist.org/packages/dipesh79/laravel-pg-reset-sequences)[ RSS](/packages/dipesh79-laravel-pg-reset-sequences/feed)WikiDiscussions 1.x Synced 1w ago

READMEChangelog (1)Dependencies (5)Versions (2)Used By (0)

Laravel PG Reset Sequences
==========================

[](#laravel-pg-reset-sequences)

A simple Artisan command that resets PostgreSQL auto-increment sequences after importing a SQL dump.

The Problem
-----------

[](#the-problem)

When you import a PostgreSQL SQL dump into an existing database, the sequences (used for auto-incrementing IDs) are not updated to reflect the data that was just imported. This causes a `SQLSTATE[23505]: Unique violation` error when trying to insert new rows, because the sequence tries to use IDs that already exist.

```
SQLSTATE[23505]: Unique violation: 7 ERROR: duplicate key value violates unique constraint "types_pkey"
DETAIL: Key (id)=(1) already exists.

```

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

[](#installation)

```
composer require dipesh79/laravel-pg-reset-sequences
```

The package auto-discovers itself via Laravel's package auto-discovery. No manual registration needed.

Usage
-----

[](#usage)

### Dry run (preview only — no changes made)

[](#dry-run-preview-only--no-changes-made)

```
php artisan db:reset-sequences --dry-run
```

### Reset all sequences

[](#reset-all-sequences)

```
php artisan db:reset-sequences
```

### Example output

[](#example-output)

```
+------------------+--------+--------------------+-------------+--------+----------+-------------+
| Table            | Column | Sequence           | Current Val | Max ID | Next Val | Status      |
+------------------+--------+--------------------+-------------+--------+----------+-------------+
| types            | id     | types_id_seq1      | 1           | 5      | 6        | NEEDS RESET |
| users            | id     | users_id_seq1      | 1           | 12     | 13       | NEEDS RESET |
| products         | id     | products_id_seq1   | 1           | 0      | 1        | OK          |
+------------------+--------+--------------------+-------------+--------+----------+-------------+
2 sequence(s) reset successfully.

```

How It Works
------------

[](#how-it-works)

The command queries `information_schema.columns` for all columns with a `nextval(...)` default and parses the sequence name directly from the `column_default` value. This approach works even when PostgreSQL has renamed sequences after a dump import (e.g. `types_id_seq` → `types_id_seq1`).

For each sequence it:

1. Reads the current `last_value` of the sequence
2. Reads the `MAX(id)` from the actual table
3. Calls `setval(sequence, max_id + 1, false)` so the next insert uses the correct next value
4. Skips sequences that are already in sync

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

[](#requirements)

- PHP 8.1+
- Laravel 10, 11, or 12
- PostgreSQL connection

License
-------

[](#license)

MIT

###  Health Score

37

—

LowBetter than 81% of packages

Maintenance83

Actively maintained with recent releases

Popularity8

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity42

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~0 days

Total

2

Last Release

84d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/63183800?v=4)[Dipesh Khanal](/maintainers/Dipesh79)[@dipesh79](https://github.com/dipesh79)

---

Top Contributors

[![dipesh79](https://avatars.githubusercontent.com/u/63183800?v=4)](https://github.com/dipesh79 "dipesh79 (2 commits)")

---

Tags

laravelpostgresqlpostgresartisansequencereset

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/dipesh79-laravel-pg-reset-sequences/health.svg)

```
[![Health](https://phpackages.com/badges/dipesh79-laravel-pg-reset-sequences/health.svg)](https://phpackages.com/packages/dipesh79-laravel-pg-reset-sequences)
```

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3345.3M347](/packages/psalm-plugin-laravel)[laravel/ai

The official AI SDK for Laravel.

1.0k3.2M246](/packages/laravel-ai)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

255.2k](/packages/aedart-athenaeum)

PHPackages © 2026

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