Skip to content

Commit 3c04b8e

Browse files
committed
Improved migration by running up for the entire file, but drop if exists table individually
1 parent 6c045b0 commit 3c04b8e

1 file changed

Lines changed: 8 additions & 13 deletions

File tree

src/Replicator.php

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -73,30 +73,25 @@ public function clean( Collection | null $deletables = null, bool $verbose = fal
7373

7474
foreach( $deletables as $deletable )
7575
{
76-
$schemas = $this->schemas->values()->filter( fn( $schema ) => $schema->file === $deletable->file );
76+
$connection = $this->resolveConnection( $deletable->connection );
7777

78-
$migration = $this->parser->resolveMigration( $deletable->file, $schemas );
78+
$connection->getSchemaBuilder()->dropIfExists( $deletable->code );
7979

80-
$this->runReplication( $migration, $schemas, 'down' );
80+
$this->schemas->pull( $deletable->getName() );
8181
}
8282
}
8383

84-
protected function runReplication( Migration $migration, Collection $schemas, string $method ) : void
84+
protected function runReplication( Migration $migration, Collection $schemas ) : void
8585
{
8686
$connection = $this->resolveConnection( $migration->getConnection() );
8787

88-
$callback = function() use ( $connection, $migration, $schemas, $method )
88+
$callback = function() use ( $connection, $migration, $schemas )
8989
{
90-
if( method_exists( $migration, $method ) )
90+
if( method_exists( $migration, "up" ) )
9191
{
92-
$schemas->each( function( $schema ) use ( $method )
93-
{
94-
if( $method === 'up' ) $this->schemas = $this->schemas->put( $schema->getName(), $schema );
95-
96-
if( $method === 'down' ) $this->schemas->pull( $schema->getName() );
97-
} );
92+
$schemas->each( fn( $schema ) => $this->schemas = $this->schemas->put( $schema->getName(), $schema ) );
9893

99-
$this->runMethod( $connection, $migration, $method );
94+
$this->runMethod( $connection, $migration, "up" );
10095
}
10196
};
10297

0 commit comments

Comments
 (0)