Skip to content

Commit de27417

Browse files
committed
Add warning during update/build for new migrations introduced in 3.5.0
1 parent b0c52f6 commit de27417

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

src/Commands/Build.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33
namespace A17\Twill\Commands;
44

55
use A17\Twill\Commands\Traits\ExecutesInTwillDir;
6+
use A17\Twill\Commands\Traits\HandlesPotentialBreakingChangesWarnings;
67
use Illuminate\Filesystem\Filesystem;
78
use Symfony\Component\Process\Process;
89

910
class Build extends Command
1011
{
1112
use ExecutesInTwillDir;
13+
use HandlesPotentialBreakingChangesWarnings;
1214

1315
/**
1416
* The name and signature of the console command.
@@ -37,6 +39,8 @@ public function __construct(public Filesystem $filesystem)
3739
*/
3840
public function handle(): void
3941
{
42+
$this->warnAboutNewPositionColumns();
43+
4044
if ($this->option('copyOnly')) {
4145
$this->copyCustoms();
4246

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
namespace A17\Twill\Commands\Traits;
4+
5+
use Illuminate\Support\Facades\Schema;
6+
7+
/* @mixin \Illuminate\Console\Command */
8+
trait HandlesPotentialBreakingChangesWarnings
9+
{
10+
public function warnAboutNewPositionColumns(): void
11+
{
12+
if (config('twill.load_default_migrations', true)) {
13+
return;
14+
}
15+
16+
$mediablesHasPosition = Schema::hasColumn(config('twill.mediables_table', 'twill_mediables'), 'position');
17+
$fileablesHasPosition = Schema::hasColumn(config('twill.fileables_table', 'twill_fileables'), 'position');
18+
19+
if ($mediablesHasPosition && $fileablesHasPosition) {
20+
return;
21+
}
22+
23+
$this->warn('⚠️ Twill 3.5.0 introduced 2 new database migrations to fix a bug with the medias and files fields position management, make sure to add them to your project.');
24+
$this->warn("\nAdd position field to the twill_mediables table:");
25+
$this->info("🔗 https://github.com/area17/twill/blob/3.5.0/migrations/default/2020_02_09_000015_add_position_to_twill_default_mediables_table.php");
26+
$this->warn("\nAdd position field to the twill_fileables table:");
27+
$this->info("🔗 https://github.com/area17/twill/blob/3.5.0/migrations/default/2020_02_09_000016_add_position_to_twill_default_fileables_table.php");
28+
}
29+
}

src/Commands/Update.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@
22

33
namespace A17\Twill\Commands;
44

5+
use A17\Twill\Commands\Traits\HandlesPotentialBreakingChangesWarnings;
56
use Illuminate\Filesystem\Filesystem;
67

78
class Update extends Command
89
{
10+
use HandlesPotentialBreakingChangesWarnings;
11+
912
protected $signature = 'twill:update {--fromBuild} {--migrate}';
1013
protected $description = 'Publish new updated Twill assets and optionally run database migrations';
1114

@@ -19,6 +22,9 @@ public function handle(): void
1922
$this->publishAssets();
2023
$this->call('twill:flush-manifest');
2124
$this->call('view:clear');
25+
26+
$this->warnAboutNewPositionColumns();
27+
2228
if ($this->option('migrate') || $this->confirm('Do you want to run any pending database migrations now?')) {
2329
$this->call('migrate');
2430
}

0 commit comments

Comments
 (0)