From 813adbaa87cb4ed9a9f74da6ca4a58acf3187cbd Mon Sep 17 00:00:00 2001 From: Paul Adrian Alcos Date: Thu, 30 May 2024 14:51:24 +0800 Subject: [PATCH 1/5] task1-task2 done --- .../migrations/task1/2021_11_08_091231_create_tasks_table.php | 2 +- .../task1/2021_11_08_092943_create_comments_table.php | 4 ++-- .../task2/2021_11_09_075928_add_surname_to_users_table.php | 3 +++ 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/database/migrations/task1/2021_11_08_091231_create_tasks_table.php b/database/migrations/task1/2021_11_08_091231_create_tasks_table.php index 08bf628f..7e02e7c3 100644 --- a/database/migrations/task1/2021_11_08_091231_create_tasks_table.php +++ b/database/migrations/task1/2021_11_08_091231_create_tasks_table.php @@ -15,7 +15,7 @@ public function up() { Schema::create('tasks', function (Blueprint $table) { $table->id(); - $table->bigInteger('user_id'); + $table->unsignedBigInteger('user_id'); $table->foreign('user_id')->references('id')->on('users'); $table->string('name'); $table->timestamps(); diff --git a/database/migrations/task1/2021_11_08_092943_create_comments_table.php b/database/migrations/task1/2021_11_08_092943_create_comments_table.php index 0378294b..974899a9 100644 --- a/database/migrations/task1/2021_11_08_092943_create_comments_table.php +++ b/database/migrations/task1/2021_11_08_092943_create_comments_table.php @@ -15,9 +15,9 @@ public function up() { Schema::create('comments', function (Blueprint $table) { $table->id(); - $table->unsignedInteger('user_id'); + $table->unsignedBigInteger('user_id'); $table->foreign('user_id')->references('id')->on('users'); - $table->unsignedInteger('comment_id'); + $table->unsignedBigInteger('comment_id'); $table->foreign('comment_id')->references('id')->on('comments'); $table->string('comment_text'); $table->timestamps(); diff --git a/database/migrations/task2/2021_11_09_075928_add_surname_to_users_table.php b/database/migrations/task2/2021_11_09_075928_add_surname_to_users_table.php index 5a3422a4..c0a44f4f 100644 --- a/database/migrations/task2/2021_11_09_075928_add_surname_to_users_table.php +++ b/database/migrations/task2/2021_11_09_075928_add_surname_to_users_table.php @@ -16,6 +16,9 @@ public function up() Schema::table('users', function (Blueprint $table) { // TASK: Add a string field "surname" which would go after the field "name" // Write code here + $table->after('name', function ($table) { + $table->string('surname'); + }); }); } From 3d3e884af1b206f75a18320ac81fc9478fac2f6b Mon Sep 17 00:00:00 2001 From: Paul Adrian Alcos Date: Thu, 30 May 2024 15:00:42 +0800 Subject: [PATCH 2/5] task 3 task 4 done --- .../task3/2021_11_09_080955_create_projects_table.php | 2 +- .../task4/2021_11_09_082205_create_products_table.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/database/migrations/task3/2021_11_09_080955_create_projects_table.php b/database/migrations/task3/2021_11_09_080955_create_projects_table.php index 9dc9d7b5..a9679538 100644 --- a/database/migrations/task3/2021_11_09_080955_create_projects_table.php +++ b/database/migrations/task3/2021_11_09_080955_create_projects_table.php @@ -17,7 +17,7 @@ public function up() $table->id(); $table->string('name'); $table->timestamps(); - + $table->softDeletes(); // TASK: Add soft deletes column here }); } diff --git a/database/migrations/task4/2021_11_09_082205_create_products_table.php b/database/migrations/task4/2021_11_09_082205_create_products_table.php index 78636019..6d48703a 100644 --- a/database/migrations/task4/2021_11_09_082205_create_products_table.php +++ b/database/migrations/task4/2021_11_09_082205_create_products_table.php @@ -16,7 +16,7 @@ public function up() // TASK: Edit this file, so that deleting category would auto-delete its products Schema::create('products', function (Blueprint $table) { $table->id(); - $table->foreignId('category_id')->constrained(); + $table->foreignId('category_id')->constrained()->onDelete('cascade'); $table->string('name'); $table->timestamps(); }); From 93bcd9ab3bbdf8df55003abddac7fedf7b7d9970 Mon Sep 17 00:00:00 2001 From: Paul Adrian Alcos Date: Thu, 30 May 2024 15:14:45 +0800 Subject: [PATCH 3/5] task5-6 --- .../2021_11_09_083121_update_users_table.php | 4 +++- ...2021_11_09_083225_recreate_users_table.php | 21 +++++++++++-------- ...21_11_09_083843_create_companies_table.php | 2 +- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/database/migrations/task5/2021_11_09_083121_update_users_table.php b/database/migrations/task5/2021_11_09_083121_update_users_table.php index c10976a5..acf8ae43 100644 --- a/database/migrations/task5/2021_11_09_083121_update_users_table.php +++ b/database/migrations/task5/2021_11_09_083121_update_users_table.php @@ -15,7 +15,9 @@ public function up() { // TASK: add an if-statement in this file to NOT add column if it already exists Schema::table('users', function (Blueprint $table) { - $table->string('name'); + if (!Schema::hasColumn('users', 'name')) { + $table->string('name'); + } }); } diff --git a/database/migrations/task5/2021_11_09_083225_recreate_users_table.php b/database/migrations/task5/2021_11_09_083225_recreate_users_table.php index 6b15a7c6..7d2d0dd2 100644 --- a/database/migrations/task5/2021_11_09_083225_recreate_users_table.php +++ b/database/migrations/task5/2021_11_09_083225_recreate_users_table.php @@ -14,15 +14,18 @@ class RecreateUsersTable extends Migration public function up() { // TASK: add an if-statement in this file to NOT create table if it already exists - Schema::create('users', function (Blueprint $table) { - $table->id(); - $table->string('name'); - $table->string('email')->unique(); - $table->timestamp('email_verified_at')->nullable(); - $table->string('password'); - $table->rememberToken(); - $table->timestamps(); - }); + if (!Schema::hasTable('users')) { + Schema::create('users', function (Blueprint $table) { + $table->id(); + $table->string('name'); + $table->string('email')->unique(); + $table->timestamp('email_verified_at')->nullable(); + $table->string('password'); + $table->rememberToken(); + $table->timestamps(); + }); + } + } /** diff --git a/database/migrations/task6/2021_11_09_083843_create_companies_table.php b/database/migrations/task6/2021_11_09_083843_create_companies_table.php index 9554406a..360998bb 100644 --- a/database/migrations/task6/2021_11_09_083843_create_companies_table.php +++ b/database/migrations/task6/2021_11_09_083843_create_companies_table.php @@ -16,7 +16,7 @@ public function up() // TASK: edit this migration so there couldn't be two companies with the same name Schema::create('companies', function (Blueprint $table) { $table->id(); - $table->string('name'); + $table->string('name')->unique(); $table->timestamps(); }); } From a86d87cb18a7403884c2959735374de20c703d25 Mon Sep 17 00:00:00 2001 From: Paul Adrian Alcos Date: Thu, 30 May 2024 15:18:31 +0800 Subject: [PATCH 4/5] task7-8 --- .../task7/2021_11_09_084922_create_new_companies_table.php | 2 +- .../task8/2021_11_09_085453_rename_companies_table.php | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/database/migrations/task7/2021_11_09_084922_create_new_companies_table.php b/database/migrations/task7/2021_11_09_084922_create_new_companies_table.php index 868a2422..9457fd8c 100644 --- a/database/migrations/task7/2021_11_09_084922_create_new_companies_table.php +++ b/database/migrations/task7/2021_11_09_084922_create_new_companies_table.php @@ -17,7 +17,7 @@ public function up() // its automatic value of name would be "My company" Schema::create('companies', function (Blueprint $table) { $table->id(); - $table->string('name'); + $table->string('name')->default("My company"); $table->timestamps(); }); } diff --git a/database/migrations/task8/2021_11_09_085453_rename_companies_table.php b/database/migrations/task8/2021_11_09_085453_rename_companies_table.php index dc4ae6f2..a546d47e 100644 --- a/database/migrations/task8/2021_11_09_085453_rename_companies_table.php +++ b/database/migrations/task8/2021_11_09_085453_rename_companies_table.php @@ -14,6 +14,7 @@ class RenameCompaniesTable extends Migration public function up() { // TASK: add a migration to rename table "company" into "companies" + Schema::rename("company", "companies"); } /** From fd3a84d27a6963b7fae2274ad67c545ff7f47724 Mon Sep 17 00:00:00 2001 From: Paul Adrian Alcos Date: Thu, 30 May 2024 15:40:05 +0800 Subject: [PATCH 5/5] task-9-10 --- .../task10/2021_11_09_090858_create_visitors_table.php | 2 +- .../task9/2021_11_09_090018_rename_name_in_companies_table.php | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/database/migrations/task10/2021_11_09_090858_create_visitors_table.php b/database/migrations/task10/2021_11_09_090858_create_visitors_table.php index 7a53968c..08e7516e 100644 --- a/database/migrations/task10/2021_11_09_090858_create_visitors_table.php +++ b/database/migrations/task10/2021_11_09_090858_create_visitors_table.php @@ -16,7 +16,7 @@ public function up() // TASK: edit this migration so country_id would allow NULL values Schema::create('visitors', function (Blueprint $table) { $table->id(); - $table->foreignId('country_id')->constrained(); + $table->foreignId('country_id')->nullable()->constrained(); $table->string('ip_address'); $table->timestamps(); }); diff --git a/database/migrations/task9/2021_11_09_090018_rename_name_in_companies_table.php b/database/migrations/task9/2021_11_09_090018_rename_name_in_companies_table.php index f270c9e7..568690ab 100644 --- a/database/migrations/task9/2021_11_09_090018_rename_name_in_companies_table.php +++ b/database/migrations/task9/2021_11_09_090018_rename_name_in_companies_table.php @@ -16,6 +16,8 @@ public function up() // TASK: write the migration to rename the column "title" into "name" Schema::table('companies', function (Blueprint $table) { // Write code here + + $table->renameColumn('title', 'name'); }); }