Migration change
This commit is contained in:
parent
220789a4b9
commit
493c5888a3
1 changed files with 20 additions and 12 deletions
|
@ -15,21 +15,22 @@ class ChangeToABetterUniqueServiceConfiguration extends Migration
|
||||||
{
|
{
|
||||||
Schema::table('service_options', function (Blueprint $table) {
|
Schema::table('service_options', function (Blueprint $table) {
|
||||||
$table->char('uuid', 36)->after('id');
|
$table->char('uuid', 36)->after('id');
|
||||||
$table->string('author')->after('service_id');
|
|
||||||
|
|
||||||
$table->index(['service_id', 'tag']);
|
$table->index(['service_id', 'tag']);
|
||||||
});
|
});
|
||||||
|
|
||||||
DB::table('service_options')->select([
|
DB::transaction(function () {
|
||||||
'service_options.id',
|
DB::table('service_options')->select([
|
||||||
'service_options.author',
|
'service_options.id',
|
||||||
'service_options.uuid',
|
'service_options.uuid',
|
||||||
'services.author AS service_author',
|
'service_options.tag',
|
||||||
])->join('services', 'services.id', '=', 'service_options.service_id')->get()->each(function ($option) {
|
'services.author AS service_author',
|
||||||
DB::table('service_options')->where('id', $option->id)->update([
|
])->join('services', 'services.id', '=', 'service_options.service_id')->get()->each(function ($option) {
|
||||||
'author' => $option->service_author,
|
DB::table('service_options')->where('id', $option->id)->update([
|
||||||
'uuid' => Uuid::uuid4()->toString(),
|
'tag' => $option->service_author . ':' . $option->tag,
|
||||||
]);
|
'uuid' => Uuid::uuid4()->toString(),
|
||||||
|
]);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
Schema::table('service_options', function (Blueprint $table) {
|
Schema::table('service_options', function (Blueprint $table) {
|
||||||
|
@ -44,8 +45,15 @@ class ChangeToABetterUniqueServiceConfiguration extends Migration
|
||||||
{
|
{
|
||||||
Schema::table('service_options', function (Blueprint $table) {
|
Schema::table('service_options', function (Blueprint $table) {
|
||||||
$table->dropColumn('uuid');
|
$table->dropColumn('uuid');
|
||||||
$table->dropColumn('author');
|
|
||||||
$table->dropIndex(['service_id', 'tag']);
|
$table->dropIndex(['service_id', 'tag']);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
DB::transaction(function () {
|
||||||
|
DB::table('service_options')->select(['id', 'author'])->get()->each(function ($option) {
|
||||||
|
DB::table('service_options')->where('id', $option->id)->update([
|
||||||
|
'tag' => array_get(explode(':', $option->tag), 1),
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue