Skip to content

Commit 7a06e07

Browse files
committed
Added migration to create indexes and foriegn keys for the totem tables
1 parent 11b1125 commit 7a06e07

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
class AlterTasksTableAddAutoCleanupNumAndTypeFields extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*
12+
* @return void
13+
*/
14+
public function up()
15+
{
16+
Schema::table(config('totem.table_prefix') . 'task_results', function (Blueprint $table) {
17+
$table->index('task_id', 'task_id_idx');
18+
$table->index('ran_at', 'ran_at_idx');
19+
$table->foreign('task_id', 'task_id_fk')
20+
->references('task_id')->on('tasks');
21+
});
22+
23+
Schema::table(config('totem.table_prefix') . 'task_frequencies', function (Blueprint $table) {
24+
$table->index('task_id', 'task_id_idx');
25+
$table->foreign('task_id', 'task_id_fk')
26+
->references('task_id')->on('tasks');
27+
});
28+
29+
Schema::table(config('totem.table_prefix') . 'tasks', function (Blueprint $table) {
30+
$table->index('is_active', 'is_active_idx');
31+
$table->index('dont_overlap', 'dont_overlap_idx');
32+
$table->index('run_in_maintenance', 'run_in_maintenance_idx');
33+
$table->index('run_on_one_server', 'run_on_one_server_idx');
34+
$table->index('auto_cleanup_num', 'auto_cleanup_num_idx');
35+
$table->index('auto_cleanup_type', 'auto_cleanup_type_idx');
36+
});
37+
}
38+
39+
/**
40+
* Reverse the migrations.
41+
*
42+
* @return void
43+
*/
44+
public function down()
45+
{
46+
Schema::table(config('totem.table_prefix') . 'task_results', function (Blueprint $table) {
47+
$table->dropIndex('task_id_idx');
48+
$table->dropIndex('ran_at_idx');
49+
$table->dropForeign('task_id_fk');
50+
});
51+
52+
Schema::table(config('totem.table_prefix') . 'task_frequencies', function (Blueprint $table) {
53+
$table->dropIndex('task_id_idx');
54+
$table->dropForeign('task_id_fk');
55+
});
56+
57+
Schema::table(config('totem.table_prefix') . 'tasks', function (Blueprint $table) {
58+
$table->dropIndex('is_active_idx');
59+
$table->dropIndex('dont_overlap_idx');
60+
$table->dropIndex('run_in_maintenance_idx');
61+
$table->dropIndex('run_on_one_server_idx');
62+
$table->dropIndex('auto_cleanup_num_idx');
63+
$table->dropIndex('auto_cleanup_type_idx');
64+
});
65+
}
66+
}

0 commit comments

Comments
 (0)