Skip to content

Commit 9eb8fe8

Browse files
[6.x] Publish migration for webauthn table during upgrade process (#12938)
1 parent 0d4f935 commit 9eb8fe8

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

src/Providers/ExtensionServiceProvider.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ class ExtensionServiceProvider extends ServiceProvider
253253
Updates\RemoveParentField::class,
254254
Updates\UpdateGlobalVariables::class,
255255
Updates\PublishMigrationForTwoFactorColumns::class,
256+
Updates\PublishMigrationForWebauthnTable::class,
256257
Updates\AddAddonSettingsToGitConfig::class,
257258
];
258259

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
namespace Statamic\UpdateScripts;
4+
5+
use Illuminate\Support\Facades\File;
6+
use Illuminate\Support\Str;
7+
8+
class PublishMigrationForWebauthnTable extends UpdateScript
9+
{
10+
public function shouldUpdate($newVersion, $oldVersion)
11+
{
12+
return $this->isUpdatingTo('6.0.0')
13+
&& config('statamic.users.repository', 'file') === 'eloquent';
14+
}
15+
16+
public function update()
17+
{
18+
if (! $this->migrationExists('statamic_webauthn_table')) {
19+
$stub = __DIR__.'/../Console/Commands/stubs/auth/statamic_webauthn_table.php.stub';
20+
$filename = date('Y_m_d_His').'_statamic_webauthn_table.php';
21+
22+
File::put(database_path("migrations/$filename"), File::get($stub));
23+
24+
$this->console->line(sprintf(
25+
'Migration <info>database/migrations/%s</info> created successfully.',
26+
$filename
27+
));
28+
29+
$this->console->line('Run <comment>php artisan migrate</comment> to apply the migration.');
30+
}
31+
}
32+
33+
protected function migrationExists(string $name): bool
34+
{
35+
return collect(File::allFiles(database_path('migrations')))
36+
->map->getFilename()
37+
->filter(fn (string $filename) => Str::contains($filename, $name))
38+
->isNotEmpty();
39+
}
40+
}

0 commit comments

Comments
 (0)