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
This commit is contained in:
parent
ecb2322ac6
commit
b85187c92b
1 changed files with 20 additions and 0 deletions
|
|
@ -39,12 +39,32 @@ class V1DataMigrationSeeder extends Seeder
|
||||||
// Import subscriptions
|
// Import subscriptions
|
||||||
$this->importSubscriptions();
|
$this->importSubscriptions();
|
||||||
|
|
||||||
|
// Fix PostgreSQL sequences after importing data with specific IDs
|
||||||
|
$this->fixSequences();
|
||||||
|
|
||||||
$this->command->info('✅ v1.0 data migration complete!');
|
$this->command->info('✅ v1.0 data migration complete!');
|
||||||
$this->command->info(' - Docket Entries: ' . DocketEntry::count());
|
$this->command->info(' - Docket Entries: ' . DocketEntry::count());
|
||||||
$this->command->info(' - Documents: ' . Document::count());
|
$this->command->info(' - Documents: ' . Document::count());
|
||||||
$this->command->info(' - Subscriptions: ' . Subscription::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
|
private function importDocketEntries(): void
|
||||||
{
|
{
|
||||||
$entries = [
|
$entries = [
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue