Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{

/**
* Get the migration connection name.
*/
public function getConnection(): string|null
{
return config('barstool.connection') ?? config('barstool.database_connection');
}

/**
* Run the migrations.
*/
public function up()
{
$schema = Schema::connection($this->getConnection());

if ($schema->hasIndex('barstools', 'barstools_created_at_index')) {
return;
}

$schema->table('barstools', function (Blueprint $table) {
$table->index('created_at');
});
}
};
2 changes: 1 addition & 1 deletion database/migrations/create_barstools_table.php.stub
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ return new class extends Migration
$schema->create('barstools', function (Blueprint $table) {
$table->id();
$table->uuid('uuid')->index();
$table->timestamp('created_at')->useCurrent();
$table->timestamp('created_at')->useCurrent()->index();
$table->string('connector_class')->index();
$table->string('request_class')->index();
$table->string('method');
Expand Down
6 changes: 5 additions & 1 deletion src/BarstoolServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ public function configurePackage(Package $package): void
->name('barstool')
->hasConfigFile()
->hasViews()
->hasMigrations(['create_barstools_table', 'add_context_to_barstools_table']);
->hasMigrations([
'create_barstools_table',
'add_context_to_barstools_table',
'add_created_at_index_to_barstools_table',
]);
}

public function packageRegistered(): void
Expand Down
10 changes: 10 additions & 0 deletions tests/BarstoolTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Saloon\Barstool\Models\Barstool;
use Saloon\Http\Faking\MockResponse;
use Illuminate\Support\Facades\Queue;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\Artisan;
use Saloon\Barstool\Enums\RecordingType;
use Saloon\Http\Connectors\NullConnector;
Expand Down Expand Up @@ -1161,3 +1162,12 @@
NullConnector::class,
SoloUserRequest::class,
]);

it('adds the created_at index via the upgrade migration', function () {
$migration = include __DIR__.'/../database/migrations/add_created_at_index_to_barstools_table.php.stub';
$migration->up();

$schema = Schema::connection(config('barstool.connection'));

expect($schema->hasIndex('barstools', 'barstools_created_at_index'))->toBeTrue();
});