MDL-18577 drop enums support - step3: Drop enums from generator classes. Only code used to drop enums remains until Moodle 2.1
This commit is contained in:
@@ -133,17 +133,6 @@ class postgres_sql_generator extends sql_generator {
|
||||
return $dbtype;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the code needed to create one enum for the xmldb_table and xmldb_field passes
|
||||
*/
|
||||
public function getEnumExtraSQL($xmldb_table, $xmldb_field) {
|
||||
|
||||
$sql = 'CONSTRAINT ' . $this->getNameForObject($xmldb_table->getName(), $xmldb_field->getName(), 'ck');
|
||||
$sql.= ' CHECK (' . $this->getEncQuoted($xmldb_field->getName()) . ' IN (' . implode(', ', $xmldb_field->getEnumValues()) . '))';
|
||||
|
||||
return $sql;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the code (in array) needed to add one comment to the table
|
||||
*/
|
||||
@@ -183,12 +172,7 @@ class postgres_sql_generator extends sql_generator {
|
||||
foreach ($constraints as $constraint) {
|
||||
/// Drop the old constraint
|
||||
$results[] = 'ALTER TABLE ' . $newtablename . ' DROP CONSTRAINT ' . $constraint->name;
|
||||
/// Calculate the new constraint name
|
||||
$newconstraintname = str_replace($oldconstraintprefix, $newconstraintprefix, $constraint->name);
|
||||
/// Add the new constraint
|
||||
$results[] = 'ALTER TABLE ' . $newtablename . ' ADD CONSTRAINT ' . $newconstraintname .
|
||||
' CHECK ' . $constraint->description;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $results;
|
||||
@@ -381,40 +365,11 @@ class postgres_sql_generator extends sql_generator {
|
||||
return $results;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the code (array of statements) needed to execute extra statements on field rename
|
||||
*/
|
||||
public function getRenameFieldExtraSQL($xmldb_table, $xmldb_field, $newname) {
|
||||
|
||||
$results = array();
|
||||
|
||||
/// If the field is enum, drop and re-create the check constraint
|
||||
if ($xmldb_field->getEnum()) {
|
||||
/// Drop the current enum
|
||||
$results = array_merge($results, $this->getDropEnumSQL($xmldb_table, $xmldb_field));
|
||||
/// Change field name (over a clone to avoid some potential problems later)
|
||||
$new_xmldb_field = clone($xmldb_field);
|
||||
$new_xmldb_field->setName($newname);
|
||||
/// Recreate the enum
|
||||
$results = array_merge($results, $this->getCreateEnumSQL($xmldb_table, $new_xmldb_field));
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
/**
|
||||
* Given one xmldb_table and one xmldb_field, return the SQL statements needded to create its enum
|
||||
* (usually invoked from getModifyEnumSQL()
|
||||
*/
|
||||
public function getCreateEnumSQL($xmldb_table, $xmldb_field) {
|
||||
/// All we have to do is to create the check constraint
|
||||
return array('ALTER TABLE ' . $this->getTableName($xmldb_table) .
|
||||
' ADD ' . $this->getEnumExtraSQL($xmldb_table, $xmldb_field));
|
||||
}
|
||||
|
||||
/**
|
||||
* Given one xmldb_table and one xmldb_field, return the SQL statements needded to drop its enum
|
||||
* (usually invoked from getModifyEnumSQL()
|
||||
*
|
||||
* TODO: Moodle 2.1 - drop in Moodle 2.1
|
||||
*/
|
||||
public function getDropEnumSQL($xmldb_table, $xmldb_field) {
|
||||
/// Let's introspect to know the real name of the check constraint
|
||||
@@ -456,6 +411,8 @@ class postgres_sql_generator extends sql_generator {
|
||||
* order to return only the check constraints belonging to one field.
|
||||
* Each element contains the name of the constraint and its description
|
||||
* If no check constraints are found, returns an empty array
|
||||
*
|
||||
* TODO: Moodle 2.1 - drop in Moodle 2.1
|
||||
*/
|
||||
public function getCheckConstraintsFromDB($xmldb_table, $xmldb_field = null) {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user