Skip to content

Commit

Permalink
Drop index before updating the col
Browse files Browse the repository at this point in the history
It will get re-created after
  • Loading branch information
nitriques committed Feb 26, 2019
1 parent af6a4e1 commit 989f5ea
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions extension.driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,18 @@ public function update($previousVersion=false) {
$textbox_fields = FieldManager::fetch(null, null, 'ASC', 'sortorder', 'textbox');
foreach($textbox_fields as $field) {
$table = "tbl_entries_data_" . $field->get('id');

// Handle length
if ($this->updateHasIndex('handle', $table)) {
$this->updateDropIndex('handle', $table);
}
$this->updateModifyColumn('handle', 'VARCHAR(1024)', $table);

// Make sure we have an index on the handle
if ($this->updateHasColumn('text_handle') && !$this->updateHasIndex('handle', $table)) {
$this->updateAddIndex('handle', $table, 333);
}
// Handle length
$this->updateModifyColumn('handle', 'VARCHAR(1024)', $table);

// Make sure we have a unique key on `entry_id`
if ($this->updateHasColumn('entry_id', $table) && !$this->updateHasUniqueKey('entry_id', $table)) {
$this->updateAddUniqueKey('entry_id', $table);
Expand Down Expand Up @@ -202,6 +208,23 @@ public function updateHasIndex($index, $table) {
);
}

/**
* Drop the given `$index` from `$table`.
*
* @param string $index
* @param string $table
* @return boolean
*/
public function updateDropIndex($index, $table)
{
return Symphony::Database()->query("
ALTER TABLE
`$table`
DROP INDEX
`{$index}`
");
}

/**
* Add a new Unique Key. Note that this does not check to see if an
* unique key already exists and will remove any existing key on the column.
Expand Down

0 comments on commit 989f5ea

Please sign in to comment.