mirror of
https://github.com/snipe/snipe-it.git
synced 2024-12-26 14:09:43 -08:00
Updated migration to fix field names
This commit is contained in:
parent
19313e4b83
commit
b0f84fa82b
|
@ -3,8 +3,9 @@
|
||||||
use Illuminate\Support\Facades\Schema;
|
use Illuminate\Support\Facades\Schema;
|
||||||
use Illuminate\Database\Migrations\Migration;
|
use Illuminate\Database\Migrations\Migration;
|
||||||
use App\Models\CustomField;
|
use App\Models\CustomField;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fixes issue #2551 where columns got donked if the field name in non-ascii
|
* Fixes issue #2551 where columns got donked if the field name in non-ascii
|
||||||
* format.
|
* format.
|
||||||
*
|
*
|
||||||
|
@ -16,8 +17,10 @@ use App\Models\CustomField;
|
||||||
* @since [v4.0]
|
* @since [v4.0]
|
||||||
* @return Array
|
* @return Array
|
||||||
*/
|
*/
|
||||||
function updateLegacyColumnName($customfield) {
|
|
||||||
|
function updateLegacyColumnName($customfield) {
|
||||||
$name_to_db_name = CustomField::name_to_db_name($customfield->name);
|
$name_to_db_name = CustomField::name_to_db_name($customfield->name);
|
||||||
|
\Log::debug('Trying to rename '.$name_to_db_name." to ".$customfield->convertUnicodeDbSlug()."...\n");
|
||||||
|
|
||||||
if (Schema::hasColumn(CustomField::$table_name, $name_to_db_name)) {
|
if (Schema::hasColumn(CustomField::$table_name, $name_to_db_name)) {
|
||||||
|
|
||||||
|
@ -27,9 +30,13 @@ use App\Models\CustomField;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
\Log::debug('Legacy DB column '.$name_to_db_name.' was not found on the assets table.');
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class FixUtf8CustomFieldColumnNames extends Migration
|
class FixUtf8CustomFieldColumnNames extends Migration
|
||||||
|
@ -42,10 +49,26 @@ class FixUtf8CustomFieldColumnNames extends Migration
|
||||||
public function up()
|
public function up()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
Schema::table('custom_fields', function ($table) {
|
||||||
|
$table->string('db_column')->nullable();
|
||||||
|
$table->text('help_text')->nullable();
|
||||||
|
});
|
||||||
|
|
||||||
foreach(CustomField::all() as $field) {
|
foreach(CustomField::all() as $field) {
|
||||||
|
|
||||||
|
$db_column = $field->convertUnicodeDbSlug();
|
||||||
|
|
||||||
|
DB::table('custom_fields')
|
||||||
|
->where('id', $field->id)
|
||||||
|
->update(['db_column' => $db_column]);
|
||||||
|
|
||||||
|
// change the name of the column
|
||||||
updateLegacyColumnName($field);
|
updateLegacyColumnName($field);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -55,7 +78,10 @@ class FixUtf8CustomFieldColumnNames extends Migration
|
||||||
*/
|
*/
|
||||||
public function down()
|
public function down()
|
||||||
{
|
{
|
||||||
//
|
Schema::table('custom_fields', function ($table) {
|
||||||
|
$table->dropColumn('db_column');
|
||||||
|
$table->dropColumn('help_text');
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue