aboutsummaryrefslogtreecommitdiff
path: root/lib/migrations/DatabaseMigrationTrait.php
blob: f8fad728900696d93db769aaace0808c9799cacd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<?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]);
    }
}