This repository was archived by the owner on Jun 2, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy path2019_05_29_000100_version_510.php
163 lines (134 loc) · 5.78 KB
/
2019_05_29_000100_version_510.php
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
<?php
use BT\Modules\Settings\Models\Setting;
use BT\Modules\Clients\Models\Contact;
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
class Version510 extends Migration
{
/**
* Schema table name to migrate
* @var string
*/
public $set_schema_table = 'clients';
/**
* Run the migrations.
* @table payments_custom
*
* @return void
*/
public function up()
{
Schema::create('industries', function (Blueprint $table) {
$table->increments('id');
$table->string('name', 255);
});
Schema::create('sizes', function (Blueprint $table) {
$table->increments('id');
$table->string('name', 255);
});
Schema::create('titles', function (Blueprint $table) {
$table->increments('id');
$table->string('name', 255);
});
Schema::create('payment_terms', function (Blueprint $table) {
$table->increments('id');
$table->integer('num_days');
$table->string('name', 255);
});
//seed industries, sizes, titles and paymentterms
Artisan::call('db:seed', [
'--class' => IndustrySeeder::class
]);
Artisan::call('db:seed', [
'--class' => SizeSeeder::class
]);
Artisan::call('db:seed', [
'--class' => TitleSeeder::class
]);
Artisan::call('db:seed', [
'--class' => PaymentTermsSeeder::class
]);
//add more client fields
Schema::table($this->set_schema_table, function ($table) {
$table->text('address_2')->nullable()->default(null)->after('country');
$table->string('city_2')->nullable()->default(null)->after('address_2');
$table->string('state_2')->nullable()->default(null)->after('city_2');
$table->string('zip_2')->nullable()->default(null)->after('state_2');
$table->string('country_2')->nullable()->default(null)->after('zip_2');
$table->string('id_number')->nullable()->default(null)->after('language');
$table->string('vat_number')->nullable()->default(null)->after('id_number');
$table->tinyInteger('is_company')->default(0)->after('active');
$table->unsignedInteger('industry_id')->nullable()->default(1)->after('vat_number');
$table->unsignedInteger('size_id')->nullable()->default(1)->after('industry_id');
$table->unsignedInteger('paymentterm_id')->nullable()->default(1)->after('size_id');
$table->foreign('industry_id')->references('id')->on('industries')->onDelete('no action')->onUpdate('no action');
$table->foreign('size_id')->references('id')->on('sizes')->onDelete('no action')->onUpdate('no action');
$table->foreign('paymentterm_id')->references('id')->on('payment_terms')->onDelete('no action')->onUpdate('no action');
});
//add more contact fields
Schema::table('contacts', function ($table) {
$table->string('first_name')->after('client_id');
$table->string('last_name')->after('first_name');
$table->string('phone')->nullable()->default(null)->after('email');
$table->string('fax')->nullable()->default(null)->after('phone');
$table->string('mobile')->nullable()->default(null)->after('fax');
$table->tinyInteger('is_primary')->default(0)->after('default_bcc');
$table->tinyInteger('optin')->default(1)->after('is_primary');
$table->unsignedInteger('title_id')->nullable()->default(1)->after('mobile');
$table->foreign('title_id')->references('id')->on('titles')->onDelete('no action')->onUpdate('no action');
});
//split existing contact name into first and last
$contacts = Contact::all();
foreach ($contacts as $contact) {
$splitName = explode(' ', $contact->name);
$contact->first_name = array_shift($splitName);
$contact->last_name = implode(" ", $splitName);
$contact->save();
}
deleteTempFiles();
deleteViewCache();
Setting::saveByKey('version', '5.1.0');
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::disableForeignKeyConstraints();
Schema::drop('industries');
Schema::drop('sizes');
Schema::drop('titles');
Schema::drop('payment_terms');
Schema::table('clients', function($table) {
$table->dropColumn('address_2');
$table->dropColumn('city_2');
$table->dropColumn('state_2');
$table->dropColumn('zip_2');
$table->dropColumn('country_2');
$table->dropColumn('id_number');
$table->dropColumn('vat_number');
$table->dropColumn('is_company');
$table->dropForeign('clients_industry_id_foreign');
$table->dropForeign('clients_size_id_foreign');
$table->dropForeign('clients_paymentterm_id_foreign');
$table->dropColumn('industry_id');
$table->dropColumn('size_id');
$table->dropColumn('paymentterm_id');
});
Schema::table('contacts', function($table) {
$table->dropColumn('first_name');
$table->dropColumn('last_name');
$table->dropColumn('phone');
$table->dropColumn('fax');
$table->dropColumn('mobile');
$table->dropColumn('is_primary');
$table->dropColumn('optin');
$table->dropForeign('contacts_title_id_foreign');
$table->dropColumn('title_id');
});
Schema::enableForeignKeyConstraints();
}
}