Skip to content

Commit 220789a

Browse files
committed
Push migrations to change existing service structure
1 parent 92ca84a commit 220789a

File tree

2 files changed

+101
-0
lines changed

2 files changed

+101
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
3+
use Ramsey\Uuid\Uuid;
4+
use Illuminate\Support\Facades\DB;
5+
use Illuminate\Support\Facades\Schema;
6+
use Illuminate\Database\Schema\Blueprint;
7+
use Illuminate\Database\Migrations\Migration;
8+
9+
class ChangeServicesToUseAMoreUniqueIdentifier extends Migration
10+
{
11+
/**
12+
* Run the migrations.
13+
*/
14+
public function up()
15+
{
16+
Schema::table('services', function (Blueprint $table) {
17+
$table->dropUnique(['name']);
18+
$table->dropUnique(['file']);
19+
20+
$table->string('author')->change();
21+
$table->char('uuid', 36)->after('id');
22+
$table->dropColumn('folder');
23+
});
24+
25+
DB::table('services')->get(['id', 'author', 'uuid'])->each(function ($service) {
26+
DB::table('services')->where('id', $service->id)->update([
27+
'author' => ($service->author === 'ptrdctyl-v040-11e6-8b77-86f30ca893d3') ? 'support@pterodactyl.io' : 'unknown@unknown-author.com',
28+
'uuid' => Uuid::uuid4()->toString(),
29+
]);
30+
});
31+
32+
Schema::table('services', function (Blueprint $table) {
33+
$table->unique('uuid');
34+
});
35+
}
36+
37+
/**
38+
* Reverse the migrations.
39+
*/
40+
public function down()
41+
{
42+
Schema::table('services', function (Blueprint $table) {
43+
$table->dropColumn('uuid');
44+
$table->string('folder')->unique('file');
45+
$table->char('author', 36)->change();
46+
47+
$table->unique('name');
48+
});
49+
}
50+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
use Ramsey\Uuid\Uuid;
4+
use Illuminate\Support\Facades\DB;
5+
use Illuminate\Support\Facades\Schema;
6+
use Illuminate\Database\Schema\Blueprint;
7+
use Illuminate\Database\Migrations\Migration;
8+
9+
class ChangeToABetterUniqueServiceConfiguration extends Migration
10+
{
11+
/**
12+
* Run the migrations.
13+
*/
14+
public function up()
15+
{
16+
Schema::table('service_options', function (Blueprint $table) {
17+
$table->char('uuid', 36)->after('id');
18+
$table->string('author')->after('service_id');
19+
20+
$table->index(['service_id', 'tag']);
21+
});
22+
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+
]);
33+
});
34+
35+
Schema::table('service_options', function (Blueprint $table) {
36+
$table->unique('uuid');
37+
});
38+
}
39+
40+
/**
41+
* Reverse the migrations.
42+
*/
43+
public function down()
44+
{
45+
Schema::table('service_options', function (Blueprint $table) {
46+
$table->dropColumn('uuid');
47+
$table->dropColumn('author');
48+
$table->dropIndex(['service_id', 'tag']);
49+
});
50+
}
51+
}

0 commit comments

Comments
 (0)