Skip to content

Commit

Permalink
Change order of params in CommandInterface (#607)
Browse files Browse the repository at this point in the history
* Change order of params in CommandInterface

* styleci fix
  • Loading branch information
darkdef committed Mar 25, 2023
1 parent 0bfe486 commit 565e2ec
Show file tree
Hide file tree
Showing 12 changed files with 184 additions and 184 deletions.
34 changes: 17 additions & 17 deletions docs/en/command/ddl.md
Expand Up @@ -19,7 +19,7 @@ declare(strict_types=1);
use Yiisoft\Db\Connection\ConnectionInterface;

/** @var ConnectionInterface $db */
$db->createCommand()->addCheck('ck-customer-status', '{{%customer}}', 'status > 0')->execute();
$db->createCommand()->addCheck('{{%customer}}', 'ck-customer-status', 'status > 0')->execute();
```

## Adding a new column
Expand Down Expand Up @@ -94,7 +94,7 @@ declare(strict_types=1);
use Yiisoft\Db\Connection\ConnectionInterface;

/** @var ConnectionInterface $db */
$db->createCommand()->addDefaultValue('df-customer-name', '{{%customer}}', 'name', 'John Doe')->execute();
$db->createCommand()->addDefaultValue('{{%customer}}', 'df-customer-name', 'name', 'John Doe')->execute();
```

## Adding a foreign key
Expand All @@ -112,8 +112,8 @@ use Yiisoft\Db\Connection\ConnectionInterface;

/** @var ConnectionInterface $db */
$db->createCommand()->addForeignKey(
'fk-customer-profile_id',
'{{%customer}}',
'fk-customer-profile_id',
'profile_id',
'{{%profile}}',
'id',
Expand All @@ -136,7 +136,7 @@ declare(strict_types=1);
use Yiisoft\Db\Connection\ConnectionInterface;

/** @var ConnectionInterface $db */
$db->createCommand()->addPrimaryKey('pk-customer-id', '{{%customer}}', 'id')->execute();
$db->createCommand()->addPrimaryKey('{{%customer}}', 'pk-customer-id', 'id')->execute();
```

## Add `UNIQUE` constraint
Expand All @@ -154,7 +154,7 @@ declare(strict_types=1);
use Yiisoft\Db\Connection\ConnectionInterface;

/** @var ConnectionInterface $db */
$db->createCommand()->addUnique('uq-customer-name', '{{%customer}}', 'name')->execute();
$db->createCommand()->addUnique('{{%customer}}', 'uq-customer-name', 'name')->execute();
```

## Alter column
Expand Down Expand Up @@ -193,7 +193,7 @@ declare(strict_types=1);
use Yiisoft\Db\Connection\ConnectionInterface;

/** @var ConnectionInterface $db */
$db->createCommand()->createIndex('idx-customer-name', '{{%customer}}', 'name')->execute();
$db->createCommand()->createIndex('{{%customer}}', 'idx-customer-name', 'name')->execute();
```

### Unique index
Expand All @@ -209,7 +209,7 @@ declare(strict_types=1);
use Yiisoft\Db\Connection\ConnectionInterface;

/** @var ConnectionInterface $db */
$db->createCommand()->createIndex('idx_test_name', 'test', 'id', 'UNIQUE')->execute();
$db->createCommand()->createIndex('test', 'idx_test_name', 'id', 'UNIQUE')->execute();
```

### Clustered index
Expand All @@ -224,7 +224,7 @@ declare(strict_types=1);
use Yiisoft\Db\Connection\ConnectionInterface;

/** @var ConnectionInterface $db */
$db->createCommand()->createIndex('idx_test_name', 'test', 'id', 'CLUSTERED')->execute();
$db->createCommand()->createIndex('test', 'idx_test_name', 'id', 'CLUSTERED')->execute();
```

### Non-clustered index
Expand All @@ -239,7 +239,7 @@ declare(strict_types=1);
use Yiisoft\Db\Connection\ConnectionInterface;

/** @var ConnectionInterface $db */
$db->createCommand()->createIndex('idx_test_name', 'test', 'id', 'NONCLUSTERED')->execute();
$db->createCommand()->createIndex('test', 'idx_test_name', 'id', 'NONCLUSTERED')->execute();
```

### Fulltext index
Expand All @@ -255,7 +255,7 @@ declare(strict_types=1);
use Yiisoft\Db\Connection\ConnectionInterface;

/** @var ConnectionInterface $db */
$db->createCommand()->createIndex('idx_test_name', 'test', 'name', 'FULLTEXT')->execute();
$db->createCommand()->createIndex('test', 'idx_test_name', 'name', 'FULLTEXT')->execute();
```

### Bitmap index
Expand All @@ -271,7 +271,7 @@ use Yiisoft\Db\Connection\ConnectionInterface;

/** @var ConnectionInterface $db */

$db->createCommand()->createIndex('idx_test_name', 'test', 'id', 'BITMAP')->execute();
$db->createCommand()->createIndex('test', 'idx_test_name', 'id', 'BITMAP')->execute();
```

## Creating a table
Expand Down Expand Up @@ -374,7 +374,7 @@ declare(strict_types=1);
use Yiisoft\Db\Connection\ConnectionInterface;

/** @var ConnectionInterface $db */
$db->createCommand()->dropCheck('ck-customer-status', '{{%customer}}')->execute();
$db->createCommand()->dropCheck('{{%customer}}', 'ck-customer-status')->execute();
```

## Drop column
Expand Down Expand Up @@ -445,7 +445,7 @@ declare(strict_types=1);
use Yiisoft\Db\Connection\ConnectionInterface;

/** @var ConnectionInterface $db */
$db->createCommand()->dropDefaultValue('df-customer-name', '{{%customer}}')->execute();
$db->createCommand()->dropDefaultValue('{{%customer}}', 'df-customer-name')->execute();
```

## Dropping a foreign key
Expand All @@ -462,7 +462,7 @@ declare(strict_types=1);
use Yiisoft\Db\Connection\ConnectionInterface;

/** @var ConnectionInterface $db */
$db->createCommand()->dropForeignKey('fk-customer-profile_id', '{{%customer}}')->execute();
$db->createCommand()->dropForeignKey('{{%customer}}', 'fk-customer-profile_id')->execute();
```

## Dropping an index
Expand All @@ -479,7 +479,7 @@ declare(strict_types=1);
use Yiisoft\Db\Connection\ConnectionInterface;

/** @var ConnectionInterface $db */
$db->createCommand()->dropIndex('idx-customer-name', '{{%customer}}')->execute();
$db->createCommand()->dropIndex('{{%customer}}', 'idx-customer-name')->execute();
```

## Drop a primary key
Expand All @@ -496,7 +496,7 @@ declare(strict_types=1);
use Yiisoft\Db\Connection\ConnectionInterface;

/** @var ConnectionInterface $db */
$db->createCommand()->dropPrimaryKey('pk-customer-id', '{{%customer}}')->execute();
$db->createCommand()->dropPrimaryKey('{{%customer}}', 'pk-customer-id')->execute();
```

## Drop a table
Expand Down Expand Up @@ -531,7 +531,7 @@ declare(strict_types=1);
use Yiisoft\Db\Connection\ConnectionInterface;

/** @var ConnectionInterface $db */
$db->createCommand()->dropUnique('uq-customer-name', '{{%customer}}')->execute();
$db->createCommand()->dropUnique('{{%customer}}', 'uq-customer-name')->execute();
```

## Rename a column
Expand Down
48 changes: 24 additions & 24 deletions src/Command/AbstractCommand.php
Expand Up @@ -93,9 +93,9 @@ abstract class AbstractCommand implements CommandInterface
/** @var string The SQL statement to be executed */
private string $sql = '';

public function addCheck(string $name, string $table, string $expression): static
public function addCheck(string $table, string $name, string $expression): static
{
$sql = $this->queryBuilder()->addCheck($name, $table, $expression);
$sql = $this->queryBuilder()->addCheck($table, $name, $expression);
return $this->setSql($sql)->requireTableSchemaRefresh($table);
}

Expand All @@ -117,24 +117,24 @@ public function addCommentOnTable(string $table, string $comment): static
return $this->setSql($sql)->requireTableSchemaRefresh($table);
}

public function addDefaultValue(string $name, string $table, string $column, mixed $value): static
public function addDefaultValue(string $table, string $name, string $column, mixed $value): static
{
$sql = $this->queryBuilder()->addDefaultValue($name, $table, $column, $value);
$sql = $this->queryBuilder()->addDefaultValue($table, $name, $column, $value);
return $this->setSql($sql)->requireTableSchemaRefresh($table);
}

public function addForeignKey(
string $name,
string $table,
string $name,
array|string $columns,
string $refTable,
array|string $refColumns,
string $delete = null,
string $update = null
): static {
$sql = $this->queryBuilder()->addForeignKey(
$name,
$table,
$name,
$columns,
$refTable,
$refColumns,
Expand All @@ -144,15 +144,15 @@ public function addForeignKey(
return $this->setSql($sql)->requireTableSchemaRefresh($table);
}

public function addPrimaryKey(string $name, string $table, array|string $columns): static
public function addPrimaryKey(string $table, string $name, array|string $columns): static
{
$sql = $this->queryBuilder()->addPrimaryKey($name, $table, $columns);
$sql = $this->queryBuilder()->addPrimaryKey($table, $name, $columns);
return $this->setSql($sql)->requireTableSchemaRefresh($table);
}

public function addUnique(string $name, string $table, array|string $columns): static
public function addUnique(string $table, string $name, array|string $columns): static
{
$sql = $this->queryBuilder()->addUnique($name, $table, $columns);
$sql = $this->queryBuilder()->addUnique($table, $name, $columns);
return $this->setSql($sql)->requireTableSchemaRefresh($table);
}

Expand Down Expand Up @@ -193,13 +193,13 @@ public function checkIntegrity(string $schema, string $table, bool $check = true
}

public function createIndex(
string $name,
string $table,
string $name,
array|string $columns,
string $indexType = null,
string $indexMethod = null
): static {
$sql = $this->queryBuilder()->createIndex($name, $table, $columns, $indexType, $indexMethod);
$sql = $this->queryBuilder()->createIndex($table, $name, $columns, $indexType, $indexMethod);
return $this->setSql($sql)->requireTableSchemaRefresh($table);
}

Expand All @@ -221,9 +221,9 @@ public function delete(string $table, array|string $condition = '', array $param
return $this->setSql($sql)->bindValues($params);
}

public function dropCheck(string $name, string $table): static
public function dropCheck(string $table, string $name): static
{
$sql = $this->queryBuilder()->dropCheck($name, $table);
$sql = $this->queryBuilder()->dropCheck($table, $name);
return $this->setSql($sql)->requireTableSchemaRefresh($table);
}

Expand All @@ -245,27 +245,27 @@ public function dropCommentFromTable(string $table): static
return $this->setSql($sql)->requireTableSchemaRefresh($table);
}

public function dropDefaultValue(string $name, string $table): static
public function dropDefaultValue(string $table, string $name): static
{
$sql = $this->queryBuilder()->dropDefaultValue($name, $table);
$sql = $this->queryBuilder()->dropDefaultValue($table, $name);
return $this->setSql($sql)->requireTableSchemaRefresh($table);
}

public function dropForeignKey(string $name, string $table): static
public function dropForeignKey(string $table, string $name): static
{
$sql = $this->queryBuilder()->dropForeignKey($name, $table);
$sql = $this->queryBuilder()->dropForeignKey($table, $name);
return $this->setSql($sql)->requireTableSchemaRefresh($table);
}

public function dropIndex(string $name, string $table): static
public function dropIndex(string $table, string $name): static
{
$sql = $this->queryBuilder()->dropIndex($name, $table);
$sql = $this->queryBuilder()->dropIndex($table, $name);
return $this->setSql($sql)->requireTableSchemaRefresh($table);
}

public function dropPrimaryKey(string $name, string $table): static
public function dropPrimaryKey(string $table, string $name): static
{
$sql = $this->queryBuilder()->dropPrimaryKey($name, $table);
$sql = $this->queryBuilder()->dropPrimaryKey($table, $name);
return $this->setSql($sql)->requireTableSchemaRefresh($table);
}

Expand All @@ -275,9 +275,9 @@ public function dropTable(string $table): static
return $this->setSql($sql)->requireTableSchemaRefresh($table);
}

public function dropUnique(string $name, string $table): static
public function dropUnique(string $table, string $name): static
{
$sql = $this->queryBuilder()->dropUnique($name, $table);
$sql = $this->queryBuilder()->dropUnique($table, $name);
return $this->setSql($sql)->requireTableSchemaRefresh($table);
}

Expand Down

0 comments on commit 565e2ec

Please sign in to comment.