mirror of
https://github.com/slawkens/myaac.git
synced 2025-04-27 01:39:22 +02:00
Syntactic sugar for db structure changes
This commit is contained in:
parent
7f4737631d
commit
e0036a3e32
@ -218,6 +218,30 @@ abstract class OTS_Base_DB extends PDO implements IOTS_DB
|
|||||||
$this->exec($query);
|
$this->exec($query);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function addColumn($table, $column, $definition): void {
|
||||||
|
$this->exec('ALTER TABLE ' . $this->tableName($table) . ' ADD ' . $this->fieldName($column) . ' ' . $definition . ';');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function modifyColumn($table, $column, $definition): void {
|
||||||
|
$this->exec('ALTER TABLE ' . $this->tableName($table) . ' MODIFY ' . $this->fieldName($column) . ' ' . $definition . ';');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function changeColumn($table, $from, $to, $definition): void {
|
||||||
|
$this->exec('ALTER TABLE ' . $this->tableName($table) . ' CHANGE ' . $this->fieldName($from) . ' ' . $this->fieldName($to) . ' ' . $definition . ';');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function dropColumn($table, $column): void {
|
||||||
|
$this->exec('ALTER TABLE ' . $this->tableName($table) . ' DROP COLUMN ' . $this->fieldName($column) . ';');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function renameTable($from, $to): void {
|
||||||
|
$this->exec('RENAME TABLE ' . $this->tableName($from) . ' TO ' . $this->tableName($to) . ';');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function dropTable($table, $ifExists = true): void {
|
||||||
|
$this->exec('DROP TABLE ' . ($ifExists ? 'IF EXISTS' : '') . ' ' . $this->tableName($table) . ';');
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* LIMIT/OFFSET clause for queries.
|
* LIMIT/OFFSET clause for queries.
|
||||||
*
|
*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user