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
14 changes: 11 additions & 3 deletions src/Database/Adapter/MariaDB.php
Original file line number Diff line number Diff line change
Expand Up @@ -832,9 +832,17 @@ public function deleteIndex(string $collection, string $id): bool

$sql = $this->trigger(Database::EVENT_INDEX_DELETE, $sql);

return $this->getPDO()
->prepare($sql)
->execute();
try {
return $this->getPDO()
->prepare($sql)
->execute();
} catch (PDOException $e) {
if ($e->getCode() === "42000" && $e->errorInfo[1] === 1091) {
return true;
}

throw $e;
}
}

/**
Expand Down
14 changes: 11 additions & 3 deletions src/Database/Adapter/SQLite.php
Original file line number Diff line number Diff line change
Expand Up @@ -499,9 +499,17 @@ public function deleteIndex(string $collection, string $id): bool
$sql = "DROP INDEX `{$this->getNamespace()}_{$this->tenant}_{$name}_{$id}`";
$sql = $this->trigger(Database::EVENT_INDEX_DELETE, $sql);

return $this->getPDO()
->prepare($sql)
->execute();
try {
return $this->getPDO()
->prepare($sql)
->execute();
} catch (PDOException $e) {
if (str_contains($e->getMessage(), 'no such index')) {
return true;
}

throw $e;
}
}

/**
Expand Down
18 changes: 18 additions & 0 deletions tests/e2e/Adapter/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ abstract protected static function getDatabase(): Database;
*/
abstract protected static function deleteColumn(string $collection, string $column): bool;

/**
* @param string $collection
* @param string $index
*
* @return bool
*/
abstract protected static function deleteIndex(string $collection, string $index): bool;

/**
* @return string
*/
Expand Down Expand Up @@ -1616,6 +1624,16 @@ public function testCreateDeleteIndex(): void
$this->assertInstanceOf(DuplicateException::class, $e);
}

// Test delete index when index does not exist
$this->assertEquals(true, static::getDatabase()->createIndex('indexes', 'index1', Database::INDEX_KEY, ['string', 'integer'], [128], [Database::ORDER_ASC]));
$this->assertEquals(true, static::deleteIndex('indexes', 'index1'));
$this->assertEquals(true, static::getDatabase()->deleteIndex('indexes', 'index1'));

// Test delete index when attribute does not exist
$this->assertEquals(true, static::getDatabase()->createIndex('indexes', 'index1', Database::INDEX_KEY, ['string', 'integer'], [128], [Database::ORDER_ASC]));
$this->assertEquals(true, static::getDatabase()->deleteAttribute('indexes', 'string'));
$this->assertEquals(true, static::getDatabase()->deleteIndex('indexes', 'index1'));

static::getDatabase()->deleteCollection('indexes');
}

Expand Down
10 changes: 10 additions & 0 deletions tests/e2e/Adapter/MariaDBTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,14 @@ protected static function deleteColumn(string $collection, string $column): bool

return true;
}

protected static function deleteIndex(string $collection, string $index): bool
{
$sqlTable = "`" . self::getDatabase()->getDatabase() . "`.`" . self::getDatabase()->getNamespace() . "_" . $collection . "`";
$sql = "DROP INDEX `{$index}` ON {$sqlTable}";

self::$pdo->exec($sql);

return true;
}
}
15 changes: 15 additions & 0 deletions tests/e2e/Adapter/MirrorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -331,4 +331,19 @@ protected static function deleteColumn(string $collection, string $column): bool

return true;
}

protected static function deleteIndex(string $collection, string $index): bool
{
$sqlTable = "`" . self::$source->getDatabase() . "`.`" . self::$source->getNamespace() . "_" . $collection . "`";
$sql = "DROP INDEX `{$index}` ON {$sqlTable}";

self::$sourcePdo->exec($sql);

$sqlTable = "`" . self::$destination->getDatabase() . "`.`" . self::$destination->getNamespace() . "_" . $collection . "`";
$sql = "DROP INDEX `{$index}` ON {$sqlTable}";

self::$destinationPdo->exec($sql);

return true;
}
}
5 changes: 5 additions & 0 deletions tests/e2e/Adapter/MongoDBTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,9 @@ protected static function deleteColumn(string $collection, string $column): bool
{
return true;
}

protected static function deleteIndex(string $collection, string $index): bool
{
return true;
}
}
10 changes: 10 additions & 0 deletions tests/e2e/Adapter/MySQLTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,14 @@ protected static function deleteColumn(string $collection, string $column): bool

return true;
}

protected static function deleteIndex(string $collection, string $index): bool
{
$sqlTable = "`" . self::getDatabase()->getDatabase() . "`.`" . self::getDatabase()->getNamespace() . "_" . $collection . "`";
$sql = "DROP INDEX `{$index}` ON {$sqlTable}";

self::$pdo->exec($sql);

return true;
}
}
11 changes: 11 additions & 0 deletions tests/e2e/Adapter/PostgresTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,15 @@ protected static function deleteColumn(string $collection, string $column): bool

return true;
}

protected static function deleteIndex(string $collection, string $index): bool
{
$key = "\"".self::getDatabase()->getNamespace()."_".self::getDatabase()->getTenant()."_{$collection}_{$index}\"";

$sql = "DROP INDEX \"".self::getDatabase()->getDatabase()."\".{$key}";

self::$pdo->exec($sql);

return true;
}
}
10 changes: 10 additions & 0 deletions tests/e2e/Adapter/SQLiteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,14 @@ protected static function deleteColumn(string $collection, string $column): bool

return true;
}

protected static function deleteIndex(string $collection, string $index): bool
{
$index = "`".self::getDatabase()->getNamespace()."_".self::getDatabase()->getTenant()."_{$collection}_{$index}`";
$sql = "DROP INDEX {$index}";

self::$pdo->exec($sql);

return true;
}
}
10 changes: 10 additions & 0 deletions tests/e2e/Adapter/SharedTables/MariaDBTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,14 @@ protected static function deleteColumn(string $collection, string $column): bool

return true;
}

protected static function deleteIndex(string $collection, string $index): bool
{
$sqlTable = "`" . self::getDatabase()->getDatabase() . "`.`" . self::getDatabase()->getNamespace() . "_" . $collection . "`";
$sql = "DROP INDEX `{$index}` ON {$sqlTable}";

self::$pdo->exec($sql);

return true;
}
}
5 changes: 5 additions & 0 deletions tests/e2e/Adapter/SharedTables/MongoDBTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,9 @@ protected static function deleteColumn(string $collection, string $column): bool
{
return true;
}

protected static function deleteIndex(string $collection, string $index): bool
{
return true;
}
}
10 changes: 10 additions & 0 deletions tests/e2e/Adapter/SharedTables/MySQLTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,14 @@ protected static function deleteColumn(string $collection, string $column): bool

return true;
}

protected static function deleteIndex(string $collection, string $index): bool
{
$sqlTable = "`" . self::getDatabase()->getDatabase() . "`.`" . self::getDatabase()->getNamespace() . "_" . $collection . "`";
$sql = "DROP INDEX `{$index}` ON {$sqlTable}";

self::$pdo->exec($sql);

return true;
}
}
11 changes: 11 additions & 0 deletions tests/e2e/Adapter/SharedTables/PostgresTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,15 @@ protected static function deleteColumn(string $collection, string $column): bool

return true;
}

protected static function deleteIndex(string $collection, string $index): bool
{
$key = "\"".self::getDatabase()->getNamespace()."_".self::getDatabase()->getTenant()."_{$collection}_{$index}\"";

$sql = "DROP INDEX \"".self::getDatabase()->getDatabase()."\".{$key}";

self::$pdo->exec($sql);

return true;
}
}
10 changes: 10 additions & 0 deletions tests/e2e/Adapter/SharedTables/SQLiteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,14 @@ protected static function deleteColumn(string $collection, string $column): bool

return true;
}

protected static function deleteIndex(string $collection, string $index): bool
{
$index = "`".self::getDatabase()->getNamespace()."_".self::getDatabase()->getTenant()."_{$collection}_{$index}`";
$sql = "DROP INDEX {$index}";

self::$pdo->exec($sql);

return true;
}
}