@@ -15,21 +15,22 @@ public function up()
1515 {
1616 Schema::table ('service_options ' , function (Blueprint $ table ) {
1717 $ table ->char ('uuid ' , 36 )->after ('id ' );
18- $ table ->string ('author ' )->after ('service_id ' );
1918
2019 $ table ->index (['service_id ' , 'tag ' ]);
2120 });
2221
23- DB ::table ('service_options ' )->select ([
24- 'service_options.id ' ,
25- 'service_options.author ' ,
26- 'service_options.uuid ' ,
27- 'services.author AS service_author ' ,
28- ])->join ('services ' , 'services.id ' , '= ' , 'service_options.service_id ' )->get ()->each (function ($ option ) {
29- DB ::table ('service_options ' )->where ('id ' , $ option ->id )->update ([
30- 'author ' => $ option ->service_author ,
31- 'uuid ' => Uuid::uuid4 ()->toString (),
32- ]);
22+ DB ::transaction (function () {
23+ DB ::table ('service_options ' )->select ([
24+ 'service_options.id ' ,
25+ 'service_options.uuid ' ,
26+ 'service_options.tag ' ,
27+ 'services.author AS service_author ' ,
28+ ])->join ('services ' , 'services.id ' , '= ' , 'service_options.service_id ' )->get ()->each (function ($ option ) {
29+ DB ::table ('service_options ' )->where ('id ' , $ option ->id )->update ([
30+ 'tag ' => $ option ->service_author . ': ' . $ option ->tag ,
31+ 'uuid ' => Uuid::uuid4 ()->toString (),
32+ ]);
33+ });
3334 });
3435
3536 Schema::table ('service_options ' , function (Blueprint $ table ) {
@@ -44,8 +45,15 @@ public function down()
4445 {
4546 Schema::table ('service_options ' , function (Blueprint $ table ) {
4647 $ table ->dropColumn ('uuid ' );
47- $ table ->dropColumn ('author ' );
4848 $ table ->dropIndex (['service_id ' , 'tag ' ]);
4949 });
50+
51+ DB ::transaction (function () {
52+ DB ::table ('service_options ' )->select (['id ' , 'author ' ])->get ()->each (function ($ option ) {
53+ DB ::table ('service_options ' )->where ('id ' , $ option ->id )->update ([
54+ 'tag ' => array_get (explode (': ' , $ option ->tag ), 1 ),
55+ ]);
56+ });
57+ });
5058 }
5159}
0 commit comments