From 04ebda1c6a680eb7daacb68c78b514f8944086ef Mon Sep 17 00:00:00 2001 From: weichien00 Date: Wed, 7 Jul 2021 00:25:10 +0800 Subject: [PATCH] update migration companies,address,contact,segments,segment_constants,segment_companies. --- ...21_06_21_232943_create_companies_table.php | 6 ++--- ...21_06_21_232944_create_addresses_table.php | 23 +++++++++---------- ...021_06_23_151826_create_contacts_table.php | 13 ++++++----- ...021_06_25_014731_create_segments_table.php | 7 ++---- ..._014830_create_segment_constants_table.php | 11 +++------ ..._014905_create_segment_companies_table.php | 14 ++--------- 6 files changed, 27 insertions(+), 47 deletions(-) diff --git a/database/migrations/2021_06_21_232943_create_companies_table.php b/database/migrations/2021_06_21_232943_create_companies_table.php index d23b63e0..7d99860c 100644 --- a/database/migrations/2021_06_21_232943_create_companies_table.php +++ b/database/migrations/2021_06_21_232943_create_companies_table.php @@ -1,6 +1,5 @@ id(); $table->string('name'); - $table->string('reference'); - $table->integer('type')->default(CompanyType::COMPANY_BUSINESS); - $table->integer('business_type')->default(BusinessType::IMPORTER); + $table->string('reference','45'); + $table->integer('type')->default(BusinessType::IMPORTER); $table->integer('status')->default(ApprovalStatus::PENDING_SUBMISSION); $table->softDeletes(); $table->timestamps(); diff --git a/database/migrations/2021_06_21_232944_create_addresses_table.php b/database/migrations/2021_06_21_232944_create_addresses_table.php index 3228b65e..2c84b678 100644 --- a/database/migrations/2021_06_21_232944_create_addresses_table.php +++ b/database/migrations/2021_06_21_232944_create_addresses_table.php @@ -15,21 +15,20 @@ class CreateAddressesTable extends Migration { Schema::create('addresses', function (Blueprint $table) { $table->id(); - $table->foreignId('company_id')->unsigned(); - $table->foreignId('country_id')->unsigned(); - $table->foreignId('state_id')->unsigned(); - $table->foreignId('district_id')->unsigned(); - $table->string('postcode'); - $table->string('street_one'); - $table->string('street_two')->nullable(); - $table->integer('billing')->default(true); + $table->morphs('owner'); + $table->string('street_one', '45'); + $table->string('street_two', '45')->nullable(); + $table->foreignId('district_id')->constrained(); + $table->foreignId('state_id')->constrained(); + $table->foreignId('country_id')->constrained(); + $table->string('postcode', '45'); + $table->integer('default'); $table->softDeletes(); $table->timestamps(); + }); - $table->foreign('country_id')->references('id')->on('countries'); - $table->foreign('company_id')->references('id')->on('companies'); - $table->foreign('state_id')->references('id')->on('states'); - $table->foreign('district_id')->references('id')->on('districts'); + Schema::table('addresses', function (Blueprint $table) { + $table->string('owner_type', 191)->change(); }); } diff --git a/database/migrations/2021_06_23_151826_create_contacts_table.php b/database/migrations/2021_06_23_151826_create_contacts_table.php index c8e70331..5251bb18 100644 --- a/database/migrations/2021_06_23_151826_create_contacts_table.php +++ b/database/migrations/2021_06_23_151826_create_contacts_table.php @@ -15,17 +15,18 @@ class CreateContactsTable extends Migration { Schema::create('contacts', function (Blueprint $table) { $table->id(); - $table->foreignId('company_id')->unsigned(); - $table->foreignId('country_id')->unsigned(); + $table->morphs('owner'); $table->string('reference'); - $table->string('phone')->nullable(); + $table->string('phone', '45')->nullable(); $table->string('email')->nullable(); - $table->string('wechat_id')->nullable(); + $table->string('wechat_id', '45')->nullable(); + $table->integer('default'); $table->softDeletes(); $table->timestamps(); + }); - $table->foreign('country_id')->references('id')->on('countries'); - $table->foreign('company_id')->references('id')->on('companies'); + Schema::table('contacts', function (Blueprint $table) { + $table->string('owner_type', 191)->change(); }); } diff --git a/database/migrations/2021_06_25_014731_create_segments_table.php b/database/migrations/2021_06_25_014731_create_segments_table.php index 2d524073..c6625629 100644 --- a/database/migrations/2021_06_25_014731_create_segments_table.php +++ b/database/migrations/2021_06_25_014731_create_segments_table.php @@ -17,11 +17,8 @@ class CreateSegmentsTable extends Migration { Schema::create('segments', function (Blueprint $table) { $table->id(); - $table->string('name'); - $table->integer('type')->default(SegmentConstants::STANDARD_SEGMENT); - $table->integer('status')->default(ApprovalStatus::APPROVED); - $table->softDeletes(); - $table->timestamps(); + $table->foreignId('company_module_id')->constrained(); + $table->string('name', '45'); }); } diff --git a/database/migrations/2021_06_25_014830_create_segment_constants_table.php b/database/migrations/2021_06_25_014830_create_segment_constants_table.php index 85b8dc5e..0e21e195 100644 --- a/database/migrations/2021_06_25_014830_create_segment_constants_table.php +++ b/database/migrations/2021_06_25_014830_create_segment_constants_table.php @@ -15,14 +15,9 @@ class CreateSegmentConstantsTable extends Migration { Schema::create('segment_constants', function (Blueprint $table) { $table->id(); - $table->foreignId('segment_id')->unsigned(); - $table->string('name'); - $table->string('reference'); - $table->json('detail'); - $table->softDeletes(); - $table->timestamps(); - - $table->foreign('segment_id')->references('id')->on('segments'); + $table->foreignId('segment_id')->constrained(); + $table->string('reference','45'); + $table->json('value'); }); } diff --git a/database/migrations/2021_06_25_014905_create_segment_companies_table.php b/database/migrations/2021_06_25_014905_create_segment_companies_table.php index aca7358f..4e27d72f 100644 --- a/database/migrations/2021_06_25_014905_create_segment_companies_table.php +++ b/database/migrations/2021_06_25_014905_create_segment_companies_table.php @@ -14,14 +14,10 @@ class CreateSegmentCompaniesTable extends Migration public function up() { Schema::create('segment_companies', function (Blueprint $table) { - $table->foreignId('segment_id')->unsigned(); - $table->foreignId('company_id')->unsigned(); - $table->softDeletes(); + $table->foreignId('segment_id')->constrained(); + $table->foreignId('company_id')->constrained(); $table->timestamps(); - $table->primary(['segment_id', 'company_id']); - $table->foreign('segment_id')->references('id')->on('segments'); - $table->foreign('company_id')->references('id')->on('companies'); }); } @@ -32,12 +28,6 @@ class CreateSegmentCompaniesTable extends Migration */ public function down() { - Schema::table('segment_companies', function (Blueprint $table) { - - $table->dropForeign('segment_companies_segment_id_foreign'); - $table->dropForeign('segment_companies_company_id_foreign'); - }); - Schema::dropIfExists('segment_companies'); } }