mirror of
https://github.com/InvoiceShelf/InvoiceShelf.git
synced 2026-04-18 18:54:07 +00:00
Replacing model_type in database (#100)
* Replacing model_type in database * Also update old Crater namespace
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
$this->replaceModelTypes('InvoiceShelf', 'App');
|
||||
$this->replaceModelTypes('Crater', 'App');
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
$this->replaceModelTypes('App', 'InvoiceShelf');
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace model types in the specified tables.
|
||||
*/
|
||||
private function replaceModelTypes(string $from, string $to): void
|
||||
{
|
||||
$mappings = [
|
||||
'media' => 'model_type',
|
||||
'email_logs' => 'mailable_type',
|
||||
'notifications' => 'notifiable_type',
|
||||
'personal_access_tokens' => 'tokenable_type',
|
||||
'custom_field_values' => 'custom_field_valuable_type',
|
||||
'abilities' => 'entity_type',
|
||||
'assigned_roles' => 'entity_type',
|
||||
];
|
||||
|
||||
foreach ($mappings as $table => $column) {
|
||||
DB::table($table)->update([$column => DB::raw("REPLACE($column, '$from', '$to')")]);
|
||||
}
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user