From b85187c92bea50d1af5e32d1ca1372c4c0176f7c Mon Sep 17 00:00:00 2001 From: TheMaddax Date: Sun, 11 Jan 2026 09:38:54 -0700 Subject: [PATCH] Fix PostgreSQL sequence issue after data import - Added fixSequences() method to V1DataMigrationSeeder - Automatically resets sequences for docket_entries, documents, and subscriptions - Prevents 'duplicate key value violates unique constraint' errors - Fixes issue where PDF uploads were failing due to out-of-sync sequences --- database/seeders/V1DataMigrationSeeder.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/database/seeders/V1DataMigrationSeeder.php b/database/seeders/V1DataMigrationSeeder.php index 716a5e12..dc43aadc 100644 --- a/database/seeders/V1DataMigrationSeeder.php +++ b/database/seeders/V1DataMigrationSeeder.php @@ -39,12 +39,32 @@ class V1DataMigrationSeeder extends Seeder // Import subscriptions $this->importSubscriptions(); + // Fix PostgreSQL sequences after importing data with specific IDs + $this->fixSequences(); + $this->command->info('✅ v1.0 data migration complete!'); $this->command->info(' - Docket Entries: ' . DocketEntry::count()); $this->command->info(' - Documents: ' . Document::count()); $this->command->info(' - Subscriptions: ' . Subscription::count()); } + /** + * Fix PostgreSQL sequences after importing data with specific IDs. + * This prevents "duplicate key value violates unique constraint" errors. + */ + private function fixSequences(): void + { + $tables = ['docket_entries', 'documents', 'subscriptions']; + + foreach ($tables as $table) { + $maxId = DB::table($table)->max('id'); + if ($maxId) { + DB::statement("SELECT setval('{$table}_id_seq', " . ($maxId + 1) . ", false)"); + $this->command->info(" - Fixed {$table} sequence (set to " . ($maxId + 1) . ")"); + } + } + } + private function importDocketEntries(): void { $entries = [