Skip to content

Instantly share code, notes, and snippets.

@asmecher
Created June 14, 2018 16:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save asmecher/d1013624ff5325eae97384ae5adc88c4 to your computer and use it in GitHub Desktop.
Save asmecher/d1013624ff5325eae97384ae5adc88c4 to your computer and use it in GitHub Desktop.
Patch for OJS/OMP "ERROR: type "serial" does not exist" with PostgreSQL
diff --git a/lib/pkp/lib/adodb/adodb-datadict.inc.php b/lib/pkp/lib/adodb/adodb-datadict.inc.php
index 4a44dc0..d2f317d 100644
--- a/lib/pkp/lib/adodb/adodb-datadict.inc.php
+++ b/lib/pkp/lib/adodb/adodb-datadict.inc.php
@@ -516,7 +516,9 @@ class ADODB_DataDict {
{
$tabname = $this->TableName ($tabname);
if ($flds) {
- list($lines,$pkey,$idxs) = $this->_GenFields($flds);
+ // Avoid use of SERIAL for existing columns, 2014-04-14
+ // by AS
+ list($lines,$pkey,$idxs) = $this->_GenFields($flds, false, false);
// genfields can return FALSE at times
if ($lines == null) $lines = array();
list(,$first) = each($lines);
@@ -595,7 +597,7 @@ class ADODB_DataDict {
- function _GenFields($flds,$widespacing=false)
+ function _GenFields($flds,$widespacing=false,$allowSerial=true)
{
if (is_string($flds)) {
$padding = ' ';
@@ -684,7 +686,9 @@ class ADODB_DataDict {
break;
case 'UNSIGNED': $funsigned = true; break;
case 'AUTOINCREMENT':
- case 'AUTO': $fautoinc = true; $fnotnull = true; break;
+ case 'AUTO': // Serial type (psql) not allowed in ALTER TABLE statements (2014-04-14 AS)
+ if ($allowSerial) $fautoinc = true;
+ $fnotnull = true; break;
case 'KEY':
// a primary key col can be non unique in itself (if key spans many cols...)
case 'PRIMARY': $fprimary = $v; $fnotnull = true; /*$funiqueindex = true;*/ break;
@@ -1000,7 +1004,9 @@ class ADODB_DataDict {
} */
// already exists, alter table instead
- list($lines,$pkey,$idxs) = $this->_GenFields($flds);
+ // (Avoid use of SERIAL when altering existing fields for psql,
+ // 2014-04-14 by AS)
+ list($lines,$pkey,$idxs) = $this->_GenFields($flds, false, false);
// genfields can return FALSE at times
if ($lines == null) $lines = array();
$alter = 'ALTER TABLE ' . $this->TableName($tablename);
@@ -1068,4 +1074,4 @@ class ADODB_DataDict {
$this->charSet = $charset_name;
}
} // class
-?>
\ No newline at end of file
+?>
diff --git a/lib/pkp/lib/adodb/datadict/datadict-postgres.inc.php b/lib/pkp/lib/adodb/datadict/datadict-postgres.inc.php
index af6cf3b..6edebb2 100644
--- a/lib/pkp/lib/adodb/datadict/datadict-postgres.inc.php
+++ b/lib/pkp/lib/adodb/datadict/datadict-postgres.inc.php
@@ -193,7 +193,9 @@ class ADODB2_postgres extends ADODB_DataDict {
if ($has_alter_column) {
$tabname = $this->TableName($tabname);
$sql = array();
- list($lines,$pkey) = $this->_GenFields($flds);
+ // Avoid use of SERIAL when altering an existing column
+ // 2014-04-14 by AS
+ list($lines,$pkey) = $this->_GenFields($flds, false, false);
$set_null = false;
$alter = 'ALTER TABLE ' . $tabname . $this->alterCol . ' ';
foreach($lines as $v) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment