blob: ab6bf051aeb25464ff386a5339f5a1c8948b2191 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
<?php
trait DatabaseMigrationTrait
{
/**
* Returns whether a key/index with the given name exists on the given
* table.
*/
protected function keyExists(string $table, string $key): bool
{
$query = "SHOW INDEX FROM `$table` WHERE Key_name = ?";
return (bool) DBManager::get()->fetchOne($query, [$key]);
}
/**
* Returns whether a column with the given name exists on the given table.
*/
protected function columnExists(string $table, string $column): bool
{
$query = "SHOW COLUMNS FROM `{$table}` LIKE ?";
return (bool) DBManager::get()->fetchOne($query, [$column]);
}
/**
* Returns whether a table with the given name exists.
*/
protected function tableExists(string $table): bool
{
$query = "SHOW TABLES LIKE ?";
return (bool) DBManager::get()->fetchOne($query, [$table]);
}
}
|