mirror of
https://github.com/silverstripe/silverstripe-postgresql
synced 2024-10-22 17:05:45 +02:00
Outstanding Postgres fixes
This commit is contained in:
parent
dfb831cd38
commit
6672499e1a
@ -223,7 +223,6 @@ class PostgreSQLDatabase extends Database {
|
|||||||
|
|
||||||
$alterList = array();
|
$alterList = array();
|
||||||
if($newFields) foreach($newFields as $k => $v) $alterList[] .= "ADD \"$k\" $v";
|
if($newFields) foreach($newFields as $k => $v) $alterList[] .= "ADD \"$k\" $v";
|
||||||
//if($newIndexes) foreach($newIndexes as $k => $v) $alterList[] .= "ADD " . $this->getIndexSqlDefinition($tableName, $k, $v);
|
|
||||||
|
|
||||||
if($alteredFields) {
|
if($alteredFields) {
|
||||||
foreach($alteredFields as $k => $v) {
|
foreach($alteredFields as $k => $v) {
|
||||||
@ -247,6 +246,11 @@ class PostgreSQLDatabase extends Database {
|
|||||||
$alterIndexList[] .= $this->getIndexSqlDefinition($tableName, $k, $v);
|
$alterIndexList[] .= $this->getIndexSqlDefinition($tableName, $k, $v);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Add the new indexes:
|
||||||
|
if($newIndexes) foreach($newIndexes as $k=>$v){
|
||||||
|
$alterIndexList[] = $this->getIndexSqlDefinition($tableName, $k, $v);
|
||||||
|
}
|
||||||
|
|
||||||
if($alterList) {
|
if($alterList) {
|
||||||
$alterations = implode(",\n", $alterList);
|
$alterations = implode(",\n", $alterList);
|
||||||
$this->query("ALTER TABLE \"$tableName\" " . $alterations);
|
$this->query("ALTER TABLE \"$tableName\" " . $alterations);
|
||||||
@ -444,7 +448,8 @@ class PostgreSQLDatabase extends Database {
|
|||||||
//Here we create a db-specific version of whatever index we need to create.
|
//Here we create a db-specific version of whatever index we need to create.
|
||||||
switch($indexSpec['type']){
|
switch($indexSpec['type']){
|
||||||
case 'fulltext':
|
case 'fulltext':
|
||||||
$indexSpec='fulltext (' . str_replace(' ', '', $indexSpec['value']) . ')';
|
//$indexSpec='fulltext (' . str_replace(' ', '', $indexSpec['value']) . ')';
|
||||||
|
$indexSpec='(ts_' . $indexSpec['indexName'] . ')';
|
||||||
break;
|
break;
|
||||||
case 'unique':
|
case 'unique':
|
||||||
$indexSpec='unique (' . $indexSpec['value'] . ')';
|
$indexSpec='unique (' . $indexSpec['value'] . ')';
|
||||||
@ -504,7 +509,7 @@ class PostgreSQLDatabase extends Database {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$indexName=trim($indexName, '()');
|
$indexName=trim($indexName, '()');
|
||||||
//return 'ix_' . $tableName . '_' . $indexName;
|
|
||||||
return $indexName;
|
return $indexName;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -906,6 +911,19 @@ class PostgreSQLDatabase extends Database {
|
|||||||
function addslashes($value){
|
function addslashes($value){
|
||||||
return pg_escape_string($value);
|
return pg_escape_string($value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This changes the index name depending on database requirements.
|
||||||
|
* MySQL doesn't need any changes.
|
||||||
|
*/
|
||||||
|
function modifyIndex($index, $spec){
|
||||||
|
|
||||||
|
if(is_array($spec) && $spec['type']=='fulltext')
|
||||||
|
return 'ts_' . str_replace(',', '_', $index);
|
||||||
|
else
|
||||||
|
return str_replace('_', ',', $index);
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user