2017-03-12 06:00:06 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
use Illuminate\Support\Facades\Schema;
|
|
|
|
use Illuminate\Database\Schema\Blueprint;
|
|
|
|
use Illuminate\Database\Migrations\Migration;
|
|
|
|
|
|
|
|
class ChangeServiceVariablesValidationRules extends Migration
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Run the migrations.
|
|
|
|
*/
|
2022-11-25 21:29:04 +01:00
|
|
|
public function up(): void
|
2017-03-12 06:00:06 +01:00
|
|
|
{
|
|
|
|
Schema::table('service_variables', function (Blueprint $table) {
|
|
|
|
$table->renameColumn('regex', 'rules');
|
|
|
|
});
|
|
|
|
|
|
|
|
DB::transaction(function () {
|
2017-10-07 06:57:53 +02:00
|
|
|
foreach (DB::table('service_variables')->get() as $variable) {
|
2017-03-19 16:21:03 +01:00
|
|
|
$variable->rules = ($variable->required) ? 'required|regex:' . $variable->rules : 'regex:' . $variable->rules;
|
2017-03-12 06:00:06 +01:00
|
|
|
$variable->save();
|
|
|
|
}
|
|
|
|
});
|
2017-03-13 00:34:06 +01:00
|
|
|
|
|
|
|
Schema::table('service_variables', function (Blueprint $table) {
|
|
|
|
$table->dropColumn('required');
|
|
|
|
});
|
2017-03-12 06:00:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reverse the migrations.
|
|
|
|
*/
|
2022-11-25 21:29:04 +01:00
|
|
|
public function down(): void
|
2017-03-12 06:00:06 +01:00
|
|
|
{
|
|
|
|
Schema::table('service_variables', function (Blueprint $table) {
|
|
|
|
$table->renameColumn('rules', 'regex');
|
2017-03-13 00:34:06 +01:00
|
|
|
$table->boolean('required')->default(true)->before('regex');
|
2017-03-12 06:00:06 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
DB::transaction(function () {
|
2017-10-07 06:57:53 +02:00
|
|
|
foreach (DB::table('service_variables')->get() as $variable) {
|
2017-03-12 06:00:06 +01:00
|
|
|
$variable->regex = str_replace(['required|regex:', 'regex:'], '', $variable->regex);
|
|
|
|
$variable->save();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|