fix(migrations): guard uuid column addition and filter teamless servers
- Skip uuid column creation if it already exists to prevent duplicate
column errors on re-run
- Use chunkById instead of orderBy+chunk for efficient pagination
- Filter servers by whereHas('team') to avoid processing orphaned servers
without a team relationship
This commit is contained in:
parent
68e8d6904d
commit
a5b3d3a536
2 changed files with 7 additions and 6 deletions
|
|
@ -11,7 +11,7 @@
|
||||||
*/
|
*/
|
||||||
public function up(): void
|
public function up(): void
|
||||||
{
|
{
|
||||||
Server::query()->chunk(100, function ($servers) {
|
Server::query()->whereHas('team')->chunk(100, function ($servers) {
|
||||||
foreach ($servers as $server) {
|
foreach ($servers as $server) {
|
||||||
$existingKeys = SharedEnvironmentVariable::where('type', 'server')
|
$existingKeys = SharedEnvironmentVariable::where('type', 'server')
|
||||||
->where('server_id', $server->id)
|
->where('server_id', $server->id)
|
||||||
|
|
|
||||||
|
|
@ -10,14 +10,15 @@
|
||||||
{
|
{
|
||||||
public function up(): void
|
public function up(): void
|
||||||
{
|
{
|
||||||
Schema::table('local_persistent_volumes', function (Blueprint $table) {
|
if (! Schema::hasColumn('local_persistent_volumes', 'uuid')) {
|
||||||
$table->string('uuid')->nullable()->after('id');
|
Schema::table('local_persistent_volumes', function (Blueprint $table) {
|
||||||
});
|
$table->string('uuid')->nullable()->after('id');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
DB::table('local_persistent_volumes')
|
DB::table('local_persistent_volumes')
|
||||||
->whereNull('uuid')
|
->whereNull('uuid')
|
||||||
->orderBy('id')
|
->chunkById(1000, function ($volumes) {
|
||||||
->chunk(1000, function ($volumes) {
|
|
||||||
foreach ($volumes as $volume) {
|
foreach ($volumes as $volume) {
|
||||||
DB::table('local_persistent_volumes')
|
DB::table('local_persistent_volumes')
|
||||||
->where('id', $volume->id)
|
->where('id', $volume->id)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue