mirror of
https://github.com/silverstripe/silverstripe-postgresql
synced 2024-10-22 17:05:45 +02:00
MINOR Updated PostgreSQLDatabase to support additional CREATE TABLE options in alterTable() and createTable()
This commit is contained in:
parent
6672499e1a
commit
f460491bbc
@ -186,9 +186,10 @@ class PostgreSQLDatabase extends Database {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function createTable($tableName, $fields = null, $indexes = null) {
|
public function createTable($tableName, $fields = null, $indexes = null, $options = null) {
|
||||||
$fieldSchemas = $indexSchemas = "";
|
$fieldSchemas = $indexSchemas = "";
|
||||||
if($fields) foreach($fields as $k => $v) $fieldSchemas .= "\"$k\" $v,\n";
|
if($fields) foreach($fields as $k => $v) $fieldSchemas .= "\"$k\" $v,\n";
|
||||||
|
$addOptions = (isset($options[$this->class])) ? $options[$this->class] : null;
|
||||||
|
|
||||||
//If we have a fulltext search request, then we need to create a special column
|
//If we have a fulltext search request, then we need to create a special column
|
||||||
//for GiST searches
|
//for GiST searches
|
||||||
@ -207,7 +208,7 @@ class PostgreSQLDatabase extends Database {
|
|||||||
$fieldSchemas
|
$fieldSchemas
|
||||||
$fulltexts
|
$fulltexts
|
||||||
primary key (\"ID\")
|
primary key (\"ID\")
|
||||||
); $indexSchemas");
|
); $indexSchemas $addOptions");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -218,7 +219,7 @@ class PostgreSQLDatabase extends Database {
|
|||||||
* @param $alteredFields Updated fields, a map of field name => field schema
|
* @param $alteredFields Updated fields, a map of field name => field schema
|
||||||
* @param $alteredIndexes Updated indexes, a map of index name => index type
|
* @param $alteredIndexes Updated indexes, a map of index name => index type
|
||||||
*/
|
*/
|
||||||
public function alterTable($tableName, $newFields = null, $newIndexes = null, $alteredFields = null, $alteredIndexes = null) {
|
public function alterTable($tableName, $newFields = null, $newIndexes = null, $alteredFields = null, $alteredIndexes = null, $alteredOptions = null) {
|
||||||
$fieldSchemas = $indexSchemas = "";
|
$fieldSchemas = $indexSchemas = "";
|
||||||
|
|
||||||
$alterList = array();
|
$alterList = array();
|
||||||
@ -256,6 +257,14 @@ class PostgreSQLDatabase extends Database {
|
|||||||
$this->query("ALTER TABLE \"$tableName\" " . $alterations);
|
$this->query("ALTER TABLE \"$tableName\" " . $alterations);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if($alteredOptions && isset($alteredOptions[$this->class])) {
|
||||||
|
$this->query(sprintf("ALTER TABLE \"%s\" %s", $tableName, $alteredOptions[$this->class]));
|
||||||
|
Database::alteration_message(
|
||||||
|
sprintf("Table %s options changed: %s", $tableName, $alteredOptions[$this->class]),
|
||||||
|
"changed"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
foreach($alterIndexList as $alteration)
|
foreach($alterIndexList as $alteration)
|
||||||
$this->query($alteration);
|
$this->query($alteration);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user