Skip to content

Commit

Permalink
Creates a fresh instance of schema for each migration (#1305)
Browse files Browse the repository at this point in the history
  • Loading branch information
nunomaduro authored Feb 16, 2023
1 parent 9d3c56b commit 34a259c
Showing 1 changed file with 10 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,6 @@

return new class extends Migration
{
/**
* The database schema.
*
* @var \Illuminate\Database\Schema\Builder
*/
protected $schema;

/**
* Create a new migration instance.
*/
public function __construct()
{
$this->schema = Schema::connection($this->getConnection());
}

/**
* Get the migration connection name.
*/
Expand All @@ -34,7 +19,9 @@ public function getConnection(): string|null
*/
public function up(): void
{
$this->schema->create('telescope_entries', function (Blueprint $table) {
$schema = Schema::connection($this->getConnection());

$schema->create('telescope_entries', function (Blueprint $table) {
$table->bigIncrements('sequence');
$table->uuid('uuid');
$table->uuid('batch_id');
Expand All @@ -51,7 +38,7 @@ public function up(): void
$table->index(['type', 'should_display_on_index']);
});

$this->schema->create('telescope_entries_tags', function (Blueprint $table) {
$schema->create('telescope_entries_tags', function (Blueprint $table) {
$table->uuid('entry_uuid');
$table->string('tag');

Expand All @@ -64,7 +51,7 @@ public function up(): void
->onDelete('cascade');
});

$this->schema->create('telescope_monitoring', function (Blueprint $table) {
$schema->create('telescope_monitoring', function (Blueprint $table) {
$table->string('tag');
});
}
Expand All @@ -74,8 +61,10 @@ public function up(): void
*/
public function down(): void
{
$this->schema->dropIfExists('telescope_entries_tags');
$this->schema->dropIfExists('telescope_entries');
$this->schema->dropIfExists('telescope_monitoring');
$schema = Schema::connection($this->getConnection());

$schema->dropIfExists('telescope_entries_tags');
$schema->dropIfExists('telescope_entries');
$schema->dropIfExists('telescope_monitoring');
}
};

0 comments on commit 34a259c

Please sign in to comment.