Skip to content

Commit

Permalink
Optimization for non-Oracle databases
Browse files Browse the repository at this point in the history
  • Loading branch information
aimeos committed Nov 2, 2024
1 parent e5f5e2e commit 8b4c7e8
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 11 deletions.
27 changes: 18 additions & 9 deletions src/Schema/DB.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,22 +215,31 @@ public function dropSequence( $name ) : self
*/
public function dropTable( $name ) : self
{
$this->up();
$setup = false;
if( $this->type() === 'oracle' )
{
$this->up();

// Workaround for Oracle to drop sequence and trigger too
$manager = $this->getSchemaManager();
// Workaround for Oracle to drop sequence and trigger too
$manager = $this->getSchemaManager();

foreach( (array) $name as $entry )
{
if( $this->hasTable( $entry ) ) {
$manager->dropTable( $this->qi( $entry ) );
}
}

return $this->setup();
}

foreach( (array) $name as $entry )
{
if( $this->hasTable( $entry ) )
{
$manager->dropTable( $this->qi( $entry ) );
$setup = true;
if( $this->hasTable( $entry ) ) {
$this->to->dropTable( $entry );
}
}

return $setup ? $this->setup() : $this;
return $this->up();
}


Expand Down
14 changes: 12 additions & 2 deletions tests/Upscheme/Schema/DBTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,12 @@ public function testDropSequenceMultiple()
public function testDropTable()
{
$this->schemamock->expects( $this->once() )->method( 'hasTable' )->willReturn( true );
$this->smmock->expects( $this->once() )->method( 'dropTable' );

if( $this->object->type() !== 'oracle' ) {
$this->schemamock->expects( $this->once() )->method( 'dropTable' );
} else {
$this->smmock->expects( $this->once() )->method( 'dropTable' );
}

$this->assertInstanceOf( \Aimeos\Upscheme\Schema\DB::class, $this->object->dropTable( 'unit', 'test' ) );
}
Expand All @@ -204,7 +209,12 @@ public function testDropTable()
public function testDropTableMultiple()
{
$this->schemamock->expects( $this->exactly( 2 ) )->method( 'hasTable' )->willReturn( true );
$this->smmock->expects( $this->exactly( 2 ) )->method( 'dropTable' );

if( $this->object->type() !== 'oracle' ) {
$this->schemamock->expects( $this->exactly( 2 ) )->method( 'dropTable' );
} else {
$this->smmock->expects( $this->exactly( 2 ) )->method( 'dropTable' );
}

$this->assertInstanceOf( \Aimeos\Upscheme\Schema\DB::class, $this->object->dropTable( ['test', 'test2'] ) );
}
Expand Down

0 comments on commit 8b4c7e8

Please sign in to comment.