]> git.mjollnir.org Git - moodle.git/commitdiff
Now table renaming is working properly on PostgreSQL
authorstronk7 <stronk7>
Sun, 1 Oct 2006 08:44:55 +0000 (08:44 +0000)
committerstronk7 <stronk7>
Sun, 1 Oct 2006 08:44:55 +0000 (08:44 +0000)
(only renaming of check constraints are pending)

lib/xmldb/classes/generators/postgres7/postgres7.class.php

index 0ec062cbe291c275aa49d4338878a6ceabada3a1..7a1e3e68fb4b5824bbef198ba05c1696d828d9de 100644 (file)
@@ -41,6 +41,8 @@ class XMLDBpostgres7 extends XMLDBgenerator {
     var $sequence_name = 'BIGSERIAL'; //Particular name for inline sequences in this generator
     var $sequence_only = true; //To avoid to output the rest of the field specs, leaving only the name and the sequence_name variable
 
+    var $rename_table_extra_code = true; //Does the generator need to add code after table rename
+
     var $enum_inline_code = false; //Does the generator need to add inline code in the column definition
 
     var $rename_key_sql = null; //SQL sentence to rename one key (PostgreSQL doesn't support this!)
@@ -133,6 +135,26 @@ class XMLDBpostgres7 extends XMLDBgenerator {
         return array($comment);
     }
 
+    /**
+     * Returns the code (array of statements) needed to execute extra statements on table rename
+     */
+    function getRenameTableExtraSQL ($xmldb_table, $newname) {
+
+        $results = array();
+
+        $newt = new XMLDBTable($newname);
+
+        $xmldb_field = new XMLDBField('id'); // Fields having sequences should be exclusively, id.
+
+        $oldseqname = $this->getTableName($xmldb_table) . '_' . $xmldb_field->getName() . '_seq';
+        $newseqname = $this->getTableName($newt) . '_' . $xmldb_field->getName() . '_seq';
+
+    /// Rename de sequence
+        $results[] = 'ALTER TABLE ' . $oldseqname . ' RENAME TO ' . $newseqname;
+
+        return $results;
+    }
+
     /**
      * Given one XMLDBTable and one XMLDBField, return the SQL statements needded to alter the field in the table
      * PostgreSQL has some severe limits: