From 5b0684d677ae2806192d632b61331330e8fef924 Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Fri, 9 Nov 2012 12:44:06 +0100 Subject: [PATCH 01/12] Added 2.4-compatible composer.json --- composer.json | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 composer.json diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..469257b --- /dev/null +++ b/composer.json @@ -0,0 +1,17 @@ +{ + "name": "silverstripe/postgresql", + "description": "SilverStripe now has tentative support for PostgreSQL ('Postgres')", + "type": "silverstripe-module", + "keywords": ["silverstripe", "postgresql", "database"], + "authors": [ + { + "name": "Sam Minnée", + "email": "sam@silverstripe.com" + } + ], + + "require": + { + "silverstripe/framework": "2.3.*,2.4.*" + } +} \ No newline at end of file From 618d7f11372a5920267974958e40e84b8c928b11 Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Wed, 28 Nov 2012 22:07:12 +0100 Subject: [PATCH 02/12] Less restrictive compatibility notation in composer Support 2.5.x ("post-2.4") as well --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 469257b..fbad3d9 100644 --- a/composer.json +++ b/composer.json @@ -12,6 +12,6 @@ "require": { - "silverstripe/framework": "2.3.*,2.4.*" + "silverstripe/framework": "~2.3" } } \ No newline at end of file From 8673583f13e749451e9f82421bd3d45988f1ee71 Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Wed, 28 Nov 2012 22:48:27 +0100 Subject: [PATCH 03/12] Fixed syntax error in searchengine() --- code/PostgreSQLDatabase.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/PostgreSQLDatabase.php b/code/PostgreSQLDatabase.php index 1db0b2d..5ee6210 100755 --- a/code/PostgreSQLDatabase.php +++ b/code/PostgreSQLDatabase.php @@ -1742,7 +1742,7 @@ class PostgreSQLDatabase extends SS_Database { } else { if(isset($objects)) $results = new DataObjectSet($objects); else $results = new DataObjectSet(); - $results->setPageLimits($start, $pageLength, $current+1); + $results->setPageLimits($start, $pageLength, $totalCount); return $results; } } From 6c966276ab36dfa38733a3cee6c7321058624eae Mon Sep 17 00:00:00 2001 From: Simon Welsh Date: Wed, 9 Jul 2014 19:26:27 +1000 Subject: [PATCH 04/12] Create 1.1 branch for pre-3.2 support --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index f707d48..fc2027e 100644 --- a/composer.json +++ b/composer.json @@ -12,6 +12,6 @@ "require": { - "silverstripe/framework": "3.*" + "silverstripe/framework": ">=3.0,<3.2" } -} \ No newline at end of file +} From 4f6a9523f62554977f01da0a182eed6ac0091118 Mon Sep 17 00:00:00 2001 From: Simon Welsh Date: Fri, 11 Jul 2014 09:26:11 +1000 Subject: [PATCH 05/12] Don't test against unsupported core versions --- .travis.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 4aabda2..6508c08 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,7 +7,6 @@ env: matrix: - DB=POSTGRESQL CORE_RELEASE=3.0 - DB=POSTGRESQL CORE_RELEASE=3.1 - - DB=POSTGRESQL CORE_RELEASE=master before_script: - composer self-update @@ -17,4 +16,4 @@ before_script: - cd ~/builds/ss script: - - phpunit framework/tests \ No newline at end of file + - phpunit framework/tests From eac309696d65aff39c78d1d1196dceea6d12bc25 Mon Sep 17 00:00:00 2001 From: torleif Date: Fri, 25 Jul 2014 21:25:54 +1200 Subject: [PATCH 06/12] FIX postgres filter on non text fields - on branch 1.1 See https://github.com/torleif/silverstripe-postgresql/commit/7626d74beebe28bc48440f75195a1a14330c8cc3 --- code/PostgreSQLDatabase.php | 1 + 1 file changed, 1 insertion(+) diff --git a/code/PostgreSQLDatabase.php b/code/PostgreSQLDatabase.php index 2a9dc08..329a032 100644 --- a/code/PostgreSQLDatabase.php +++ b/code/PostgreSQLDatabase.php @@ -2108,6 +2108,7 @@ class PostgreSQLDatabase extends SS_Database { } else { $comp = ($caseSensitive === true) ? 'LIKE' : 'ILIKE'; if($negate) $comp = 'NOT ' . $comp; + $field.='::text'; } return sprintf("%s %s '%s'", $field, $comp, $value); From b148e2457cc29a39e13944a258bb0a68892c12eb Mon Sep 17 00:00:00 2001 From: James Pluck Date: Thu, 12 Jun 2014 11:31:27 +1200 Subject: [PATCH 07/12] FIX Total Items count on Search This issue causes pagination to fail for search results on sites using the postgres db. Patch corrects the TotalItems in the returned List to show all items matching the search criteria rather than just the items returned in the current 'page' requested. --- code/PostgreSQLDatabase.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/code/PostgreSQLDatabase.php b/code/PostgreSQLDatabase.php index 2a9dc08..a27708e 100644 --- a/code/PostgreSQLDatabase.php +++ b/code/PostgreSQLDatabase.php @@ -1885,12 +1885,14 @@ class PostgreSQLDatabase extends SS_Database { $fullQuery = "SELECT * FROM (" . implode(" UNION ", $tables) . ") AS q1 $orderBy LIMIT $limit OFFSET $offset"; + // Get the total items in this search + $totalItemsQuery = "SELECT COUNT(*) AS totalitems FROM (" . implode(" UNION ", $tables) . ") AS q1"; + $totalCount = DB::query($totalItemsQuery); + // Get records $records = DB::query($fullQuery); - $totalCount=0; foreach($records as $record){ $objects[] = new $record['ClassName']($record); - $totalCount++; } if(isset($objects)) $results = new ArrayList($objects); @@ -1899,7 +1901,7 @@ class PostgreSQLDatabase extends SS_Database { $list->setLimitItems(false); $list->setPageStart($start); $list->setPageLength($pageLength); - $list->setTotalItems($totalCount); + $list->setTotalItems($totalCount->value()); return $list; } From d112ca5d125b6267c5ac51d7b50e62ee73ad15c3 Mon Sep 17 00:00:00 2001 From: micmania1 Date: Sat, 16 Aug 2014 10:07:26 +0000 Subject: [PATCH 08/12] FIX handling of fulltext indexes declared as strings --- code/PostgreSQLDatabase.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/code/PostgreSQLDatabase.php b/code/PostgreSQLDatabase.php index 2a9dc08..73812fe 100644 --- a/code/PostgreSQLDatabase.php +++ b/code/PostgreSQLDatabase.php @@ -482,6 +482,18 @@ class PostgreSQLDatabase extends SS_Database { $ts_details=$this->fulltext($this_index, $tableName, $name); $fulltexts.=$ts_details['fulltexts'] . ', '; $triggers.=$ts_details['triggers']; + } else if(is_string($this_index)) { + preg_match('/^fulltext\ \((.+)\)$/i', $this_index, $matches); + if(count($matches) == 2) { + $index = array( + 'type' => 'fulltext', + 'name' => $name, + 'value' => $matches[1] + ); + $ts_details=$this->fulltext($index, $tableName, $name); + $fulltexts.=$ts_details['fulltexts'] . ', '; + $triggers.=$ts_details['triggers']; + } } } } From 48c07ad1abab1bd0681a15309c396cdfc4b9f244 Mon Sep 17 00:00:00 2001 From: Damian Mooyman Date: Wed, 15 Oct 2014 10:32:44 +1300 Subject: [PATCH 09/12] Use parseIndexSpec to cleanup fulltext specification --- code/PostgreSQLDatabase.php | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/code/PostgreSQLDatabase.php b/code/PostgreSQLDatabase.php index 441bb66..5bfecfd 100644 --- a/code/PostgreSQLDatabase.php +++ b/code/PostgreSQLDatabase.php @@ -477,23 +477,12 @@ class PostgreSQLDatabase extends SS_Database { $fulltexts=''; $triggers=''; if($indexes){ - foreach($indexes as $name=>$this_index){ - if(is_array($this_index) && $this_index['type']=='fulltext'){ - $ts_details=$this->fulltext($this_index, $tableName, $name); - $fulltexts.=$ts_details['fulltexts'] . ', '; - $triggers.=$ts_details['triggers']; - } else if(is_string($this_index)) { - preg_match('/^fulltext\ \((.+)\)$/i', $this_index, $matches); - if(count($matches) == 2) { - $index = array( - 'type' => 'fulltext', - 'name' => $name, - 'value' => $matches[1] - ); - $ts_details=$this->fulltext($index, $tableName, $name); - $fulltexts.=$ts_details['fulltexts'] . ', '; - $triggers.=$ts_details['triggers']; - } + foreach($indexes as $name => $indexSpec) { + $indexSpec = $this->parseIndexSpec($name, $indexSpec); + if($indexSpec['type'] === 'fulltext') { + $ts_details = $this->fulltext($indexSpec, $tableName, $name); + $fulltexts .= $ts_details['fulltexts'] . ', '; + $triggers .= $ts_details['triggers']; } } } From 9a2dc1adc8f030a294343d9cf966ee6753638094 Mon Sep 17 00:00:00 2001 From: devimust Date: Sat, 2 May 2015 11:09:54 +0000 Subject: [PATCH 10/12] FIX allow for spaces in enum field-type default values --- code/PostgreSQLDatabase.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/PostgreSQLDatabase.php b/code/PostgreSQLDatabase.php index 5bfecfd..0a60ed0 100644 --- a/code/PostgreSQLDatabase.php +++ b/code/PostgreSQLDatabase.php @@ -721,7 +721,7 @@ class PostgreSQLDatabase extends SS_Database { // TODO: this returns an empty array for the following string: int(11) not null auto_increment // on second thoughts, why is an auto_increment field being passed through? - $pattern = '/^([\w()]+)\s?((?:not\s)?null)?\s?(default\s[\w\']+)?\s?(check\s[\w()\'",\s]+)?$/i'; + $pattern = '/^([\w()]+)\s?((?:not\s)?null)?\s?(default\s[\w\s\']+)?\s?(check\s[\w()\'",\s]+)?$/i'; preg_match($pattern, $colSpec, $matches); if(sizeof($matches)==0) return ''; From 4b3fd28b3b0b93c3a56bba729a9ed30f3391f0ce Mon Sep 17 00:00:00 2001 From: Daniel Hensby Date: Wed, 26 Jul 2017 11:48:27 +0100 Subject: [PATCH 11/12] Backport of #48 --- code/PostgreSQLDatabase.php | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/code/PostgreSQLDatabase.php b/code/PostgreSQLDatabase.php index 5ee6210..90e4fe4 100755 --- a/code/PostgreSQLDatabase.php +++ b/code/PostgreSQLDatabase.php @@ -682,7 +682,8 @@ class PostgreSQLDatabase extends SS_Database { } // SET check constraint (The constraint HAS to be dropped) - $existing_constraint=$this->query("SELECT conname FROM pg_constraint WHERE conname='{$tableName}_{$colName}_check';")->value(); + $constraint_name = "{$tableName}_{$colName}_check"; + $existing_constraint = $this->constraintExists($constraint_name); if(isset($matches[4])) { //Take this new constraint and see what's outstanding from the target table: $constraint_bits=explode('(', $matches[4]); @@ -704,11 +705,11 @@ class PostgreSQLDatabase extends SS_Database { //First, delete any existing constraint on this column, even if it's no longer an enum if($existing_constraint) - $alterCol .= ",\nDROP CONSTRAINT \"{$tableName}_{$colName}_check\""; + $alterCol .= ",\nDROP CONSTRAINT \"{$constraint_name}\""; //Now create the constraint (if we've asked for one) if(!empty($matches[4])) - $alterCol .= ",\nADD CONSTRAINT \"{$tableName}_{$colName}_check\" $matches[4]"; + $alterCol .= ",\nADD CONSTRAINT \"{$constraint_name}\" $matches[4]"; } return isset($alterCol) ? $alterCol : ''; @@ -1031,16 +1032,16 @@ class PostgreSQLDatabase extends SS_Database { * @param string $indexSpec The specification of the index, see Database::requireIndex() for more details. */ public function alterIndex($tableName, $indexName, $indexSpec) { - $indexSpec = trim($indexSpec); - if($indexSpec[0] != '(') { - list($indexType, $indexFields) = explode(' ',$indexSpec,2); - } else { - $indexFields = $indexSpec; - } + $indexSpec = trim($indexSpec); + if($indexSpec[0] != '(') { + list($indexType, $indexFields) = explode(' ',$indexSpec,2); + } else { + $indexFields = $indexSpec; + } - if(!$indexType) { - $indexType = "index"; - } + if(!$indexType) { + $indexType = "index"; + } $this->query("DROP INDEX $indexName"); $this->query("ALTER TABLE \"$tableName\" ADD $indexType \"$indexName\" $indexFields"); @@ -1865,9 +1866,10 @@ class PostgreSQLDatabase extends SS_Database { DB::query("CREATE TABLE \"$partition_name\" (CHECK (" . str_replace('NEW.', '', $partition_value) . ")) INHERITS (\"$tableName\")$tableSpace;"); } else { //Drop the constraint, we will recreate in in the next line - $existing_constraint=$this->query("SELECT conname FROM pg_constraint WHERE conname='{$partition_name}_pkey';"); + $constraint_name = "{$partition_name}_pkey"; + $existing_constraint = $this->constraintExists($constraint_name); if($existing_constraint){ - DB::query("ALTER TABLE \"$partition_name\" DROP CONSTRAINT \"{$partition_name}_pkey\";"); + DB::query("ALTER TABLE \"$partition_name\" DROP CONSTRAINT \"{$constraint_name}\";"); } $this->dropTrigger(strtolower('trigger_' . $tableName . '_insert'), $tableName); } From 6a168488acc30ec4942b2aa12c7b1cc56be3dc78 Mon Sep 17 00:00:00 2001 From: Daniel Hensby Date: Wed, 26 Jul 2017 11:55:24 +0100 Subject: [PATCH 12/12] Stay on travis precise --- .travis.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 6508c08..e0a1a30 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,8 @@ -language: php +language: php + +dist: precise + +sudo: false php: - 5.3