2021_06_07_08638_create_keywords_table.php
2.56 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php
use App\Models\Keyword;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateKeywordsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
if (Schema::hasTable('goal_ad_groups') && Schema::hasColumn('goal_ad_groups', 'campaign_external_id')) {
Schema::create('goal_ad_groups', function (Blueprint $table) {
$table->renameColumn('campaign_external_id', 'dictionary_campaign_external_id');
});
}
if (Schema::hasTable('ad_groups') && !Schema::hasColumn('ad_groups', 'keywords_loaded_at')) {
Schema::create('ad_groups', function (Blueprint $table) {
$table->timestamp('keywords_loaded_at')->nullable();
});
}
Schema::create('keywords', function (Blueprint $table) {
$table->id();
$table->bigInteger('external_id');
$table->bigInteger('ad_group_external_id');
$table->bigInteger('campaign_external_id');
$table->bigInteger('ad_group_id')->unsigned();
$table->bigInteger('campaign_id')->unsigned();
$table->text('keyword')->nullable();
$table->string('user_param_1', 255)->nullable();
$table->string('user_param_2', 255)->nullable();
$table->bigInteger('bid')->nullable();
$table->bigInteger('context_bid')->nullable();
$table->enum('state', [
Keyword::STATE_OFF,
Keyword::STATE_ON,
Keyword::STATE_SUSPENDED,
])->nullable();
$table->enum('status', [
Keyword::STATUS_ACCEPTED,
Keyword::STATUS_DRAFT,
Keyword::STATUS_REJECTED,
Keyword::STATUS_UNKNOWN,
])->nullable();
$table->enum('serving_status', [
Keyword::SERVING_STATUS_ELIGIBLE,
Keyword::SERVING_STATUS_RARELY_SERVED,
])->nullable();
$table->timestamp('updated_self')->nullable();
$table->timestamps();
$table->foreign('ad_group_id')->references('id')->on('ad_groups')
->cascadeOnDelete();
$table->foreign('campaign_id')->references('id')->on('campaigns')
->cascadeOnDelete();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('keywords');
}
}