From f460491bbc14d67ce5112bab7cc0405e0cb518ca Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Tue, 19 May 2009 21:47:48 +0000 Subject: [PATCH] MINOR Updated PostgreSQLDatabase to support additional CREATE TABLE options in alterTable() and createTable() --- code/PostgreSQLDatabase.php | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/code/PostgreSQLDatabase.php b/code/PostgreSQLDatabase.php index f58ba6b..a31411c 100644 --- a/code/PostgreSQLDatabase.php +++ b/code/PostgreSQLDatabase.php @@ -186,9 +186,10 @@ class PostgreSQLDatabase extends Database { return true; } - public function createTable($tableName, $fields = null, $indexes = null) { + public function createTable($tableName, $fields = null, $indexes = null, $options = null) { $fieldSchemas = $indexSchemas = ""; 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 //for GiST searches @@ -207,7 +208,7 @@ class PostgreSQLDatabase extends Database { $fieldSchemas $fulltexts 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 $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 = ""; $alterList = array(); @@ -256,6 +257,14 @@ class PostgreSQLDatabase extends Database { $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) $this->query($alteration); }