Skip to content
Snippets Groups Projects
Commit 11b3170a authored by Elmar Ludwig's avatar Elmar Ludwig
Browse files

add index for booking_id to resource_booking_intervals, fixes #198

Closes #198
parent 37b00233
No related branches found
No related tags found
No related merge requests found
<?php
class AddIndexResourceBookingIntervals extends Migration
{
public function description()
{
return 'add index for booking_id to resource_booking_intervals';
}
public function up()
{
$db = DBManager::get();
// avoid running this migration twice
$sql = "SHOW INDEX FROM resource_booking_intervals WHERE Key_name = 'booking_id'";
$result = $db->query($sql);
if ($result && $result->rowCount() > 0) {
return;
}
// index "assign_object_id" may not exist (depending on upgrade path)
$sql = "SHOW INDEX FROM resource_booking_intervals WHERE Key_name = 'assign_object_id'";
$result = $db->query($sql);
if ($result && $result->rowCount() > 0) {
$sql = 'ALTER TABLE resource_booking_intervals DROP INDEX assign_object_id';
$db->exec($sql);
}
$sql = 'ALTER TABLE resource_booking_intervals ADD INDEX booking_id (booking_id)';
$db->exec($sql);
}
public function down()
{
$db = DBManager::get();
$query = 'ALTER TABLE resource_booking_intervals DROP INDEX booking_id';
$db->exec($query);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment