Skip to content

Commit a111ada

Browse files
authored
Adds update_date_on_publish to configuration file (#49330)
1 parent 21a8373 commit a111ada

File tree

6 files changed

+62
-8
lines changed

6 files changed

+62
-8
lines changed

config/database.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,10 @@
121121
|
122122
*/
123123

124-
'migrations' => 'migrations',
124+
'migrations' => [
125+
'table' => 'migrations',
126+
'update_date_on_publish' => true,
127+
],
125128

126129
/*
127130
|--------------------------------------------------------------------------

src/Illuminate/Database/Console/DumpCommand.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,12 @@ public function handle(ConnectionResolverInterface $connections, Dispatcher $dis
6969
*/
7070
protected function schemaState(Connection $connection)
7171
{
72+
$migrations = Config::get('database.migrations', 'migrations');
73+
74+
$migrationTable = is_array($migrations) ? ($migrations['table'] ?? 'migrations') : $migrations;
75+
7276
return $connection->getSchemaState()
73-
->withMigrationTable($connection->getTablePrefix().Config::get('database.migrations', 'migrations'))
77+
->withMigrationTable($connection->getTablePrefix().$migrationTable)
7478
->handleOutputUsing(function ($type, $buffer) {
7579
$this->output->write($buffer);
7680
});

src/Illuminate/Database/MigrationServiceProvider.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ public function register()
5959
protected function registerRepository()
6060
{
6161
$this->app->singleton('migration.repository', function ($app) {
62-
$table = $app['config']['database.migrations'];
62+
$migrations = $app['config']['database.migrations'];
63+
64+
$table = is_array($migrations) ? ($migrations['table'] ?? null) : $migrations;
6365

6466
return new DatabaseMigrationRepository($app['db'], $table);
6567
});

src/Illuminate/Foundation/Testing/DatabaseTruncation.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,11 @@ protected function connectionsToTruncate(): array
130130
*/
131131
protected function exceptTables(?string $connectionName): array
132132
{
133-
if (property_exists($this, 'exceptTables')) {
134-
$migrationsTable = $this->app['config']->get('database.migrations');
133+
$migrations = $this->app['config']->get('database.migrations');
134+
135+
$migrationsTable = is_array($migrations) ? ($migrations['table'] ?? null) : $migrations;
135136

137+
if (property_exists($this, 'exceptTables')) {
136138
if (array_is_list($this->exceptTables ?? [])) {
137139
return array_merge(
138140
$this->exceptTables ?? [],
@@ -146,7 +148,7 @@ protected function exceptTables(?string $connectionName): array
146148
);
147149
}
148150

149-
return [$this->app['config']->get('database.migrations')];
151+
return [$migrationsTable];
150152
}
151153

152154
/**

src/Illuminate/Support/ServiceProvider.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,9 @@ protected function publishesMigrations(array $paths, $groups = null)
285285
{
286286
$this->publishes($paths, $groups);
287287

288-
static::$publishableMigrationPaths = array_unique(array_merge(static::$publishableMigrationPaths, array_keys($paths)));
288+
if ($this->app->config->get('database.migrations.update_date_on_publish', false)) {
289+
static::$publishableMigrationPaths = array_unique(array_merge(static::$publishableMigrationPaths, array_keys($paths)));
290+
}
289291
}
290292

291293
/**

tests/Support/SupportServiceProviderTest.php

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,29 @@
22

33
namespace Illuminate\Tests\Support;
44

5+
use Illuminate\Config\Repository as Config;
56
use Illuminate\Foundation\Application;
67
use Illuminate\Support\ServiceProvider;
78
use Mockery as m;
89
use PHPUnit\Framework\TestCase;
910

1011
class SupportServiceProviderTest extends TestCase
1112
{
13+
protected $app;
14+
1215
protected function setUp(): void
1316
{
1417
ServiceProvider::$publishes = [];
1518
ServiceProvider::$publishGroups = [];
1619

17-
$app = m::mock(Application::class)->makePartial();
20+
$this->app = $app = m::mock(Application::class)->makePartial();
21+
$config = m::mock(Config::class)->makePartial();
22+
23+
$config = new Config();
24+
25+
$app->instance('config', $config);
26+
$config->set('database.migrations.update_date_on_publish', true);
27+
1828
$one = new ServiceProviderForTestingOne($app);
1929
$one->boot();
2030
$two = new ServiceProviderForTestingTwo($app);
@@ -119,6 +129,37 @@ public function testMultipleTaggedAssetsAreMergedCorrectly()
119129
];
120130
$this->assertEquals($expected, $toPublish, 'Service provider does not return expected set of published tagged paths.');
121131
}
132+
133+
public function testPublishesMigrations()
134+
{
135+
$serviceProvider = new ServiceProviderForTestingOne($this->app);
136+
137+
(fn () => $this->publishesMigrations(['source/tagged/four' => 'destination/tagged/four'], 'tag_four'))
138+
->call($serviceProvider);
139+
140+
$this->assertContains('source/tagged/four', ServiceProvider::publishableMigrationPaths());
141+
142+
$this->app->config->set('database.migrations.update_date_on_publish', false);
143+
144+
(fn () => $this->publishesMigrations(['source/tagged/five' => 'destination/tagged/five'], 'tag_four'))
145+
->call($serviceProvider);
146+
147+
$this->assertNotContains('source/tagged/five', ServiceProvider::publishableMigrationPaths());
148+
149+
$this->app->config->set('database.migrations', 'migrations');
150+
151+
(fn () => $this->publishesMigrations(['source/tagged/five' => 'destination/tagged/five'], 'tag_four'))
152+
->call($serviceProvider);
153+
154+
$this->assertNotContains('source/tagged/five', ServiceProvider::publishableMigrationPaths());
155+
156+
$this->app->config->set('database.migrations', null);
157+
158+
(fn () => $this->publishesMigrations(['source/tagged/five' => 'destination/tagged/five'], 'tag_four'))
159+
->call($serviceProvider);
160+
161+
$this->assertNotContains('source/tagged/five', ServiceProvider::publishableMigrationPaths());
162+
}
122163
}
123164

124165
class ServiceProviderForTestingOne extends ServiceProvider

0 commit comments

Comments
 (0)