Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?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);
}
}