From 08f35869758cf89f975abccb42280306def3068a Mon Sep 17 00:00:00 2001
From: paca70 <paca70>
Date: Fri, 30 Jul 2004 10:42:59 +0000
Subject: [PATCH] Fixed uncorrect primary key for postgresql.

---
 mod/wiki/db/postgres7.php | 6 ++++++
 mod/wiki/db/postgres7.sql | 4 +++-
 mod/wiki/version.php      | 2 +-
 3 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/mod/wiki/db/postgres7.php b/mod/wiki/db/postgres7.php
index cea8de2297..b6e7a1b7e5 100644
--- a/mod/wiki/db/postgres7.php
+++ b/mod/wiki/db/postgres7.php
@@ -6,6 +6,12 @@ function wiki_upgrade($oldversion) {
 
     global $CFG;
 
+    if ($oldversion < 2004073000) {
+
+       modify_database("", "ALTER TABLE prefix_wiki_pages DROP COLUMN id;"); 
+       modify_database("", "ALTER TABLE ONLY prefix_wiki_pages 
+                            ADD CONSTRAINT id PRIMARY KEY (pagename, \"version\");"); 
+    }    
 
     return true;
 }
diff --git a/mod/wiki/db/postgres7.sql b/mod/wiki/db/postgres7.sql
index 4a80df806f..7ed97cdc64 100644
--- a/mod/wiki/db/postgres7.sql
+++ b/mod/wiki/db/postgres7.sql
@@ -41,7 +41,6 @@ CREATE TABLE prefix_wiki_entries (
 
 
 CREATE TABLE prefix_wiki_pages (
-  id SERIAL PRIMARY KEY,
   pagename VARCHAR(160) NOT NULL,
   version INTEGER  NOT NULL DEFAULT 0,
   flags INTEGER  DEFAULT 0,
@@ -55,4 +54,7 @@ CREATE TABLE prefix_wiki_pages (
   wiki INT8  NOT NULL
 ) ;
 
+ALTER TABLE ONLY prefix_wiki_pages
+    ADD CONSTRAINT id PRIMARY KEY (pagename, "version");
+
 CREATE INDEX prefix_wiki_pages_pagename_version_wiki_idx ON prefix_wiki_pages (pagename, version, wiki) ;
diff --git a/mod/wiki/version.php b/mod/wiki/version.php
index b46f4f9007..930081f288 100644
--- a/mod/wiki/version.php
+++ b/mod/wiki/version.php
@@ -5,7 +5,7 @@
 ///  This fragment is called by moodle_needs_upgrading() and /admin/index.php
 /////////////////////////////////////////////////////////////////////////////////
 
-$module->version  = 2004062400;  // The current module version (Date: YYYYMMDDXX)
+$module->version  = 2004073000;  // The current module version (Date: YYYYMMDDXX)
 $module->cron     = 0;           // Period for cron to check this module (secs)
 
 ?>
-- 
2.39.5