From 537b116c5bd09e893f28123394c580f093a81733 Mon Sep 17 00:00:00 2001 From: Donald <154738239+DonaldFon@users.noreply.github.com> Date: Fri, 27 Dec 2024 02:29:10 +0800 Subject: [PATCH 01/12] Update 2021_11_08_091231_create_tasks_table.php --- .../migrations/task1/2021_11_08_091231_create_tasks_table.php | 3 +-- 1 file changed, 1 insertion(+), 2 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..d249f4b7 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,8 +15,7 @@ public function up() { Schema::create('tasks', function (Blueprint $table) { $table->id(); - $table->bigInteger('user_id'); - $table->foreign('user_id')->references('id')->on('users'); + $table->foreignId('user_id')->constrained(); $table->string('name'); $table->timestamps(); }); From 179d3c0d392d1bab90122693d80f933d686fb2be Mon Sep 17 00:00:00 2001 From: Donald <154738239+DonaldFon@users.noreply.github.com> Date: Fri, 27 Dec 2024 02:30:07 +0800 Subject: [PATCH 02/12] Update 2021_11_08_092943_create_comments_table.php --- .../task1/2021_11_08_092943_create_comments_table.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) 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..3c5ff32a 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,10 +15,8 @@ public function up() { Schema::create('comments', function (Blueprint $table) { $table->id(); - $table->unsignedInteger('user_id'); - $table->foreign('user_id')->references('id')->on('users'); - $table->unsignedInteger('comment_id'); - $table->foreign('comment_id')->references('id')->on('comments'); + $table->foreignId('user_id')->constrained(); + $table->foreignId('comment_id')->constrained(); $table->string('comment_text'); $table->timestamps(); }); From d2d23672cfd1cdf2fc7a69efbde60316083359af Mon Sep 17 00:00:00 2001 From: Donald <154738239+DonaldFon@users.noreply.github.com> Date: Fri, 27 Dec 2024 02:31:52 +0800 Subject: [PATCH 03/12] Update 2021_11_09_075928_add_surname_to_users_table.php --- .../task2/2021_11_09_075928_add_surname_to_users_table.php | 2 ++ 1 file changed, 2 insertions(+) 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..7cfe14e5 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,7 @@ 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->string('surname')->after('name'); }); } @@ -28,6 +29,7 @@ public function down() { Schema::table('users', function (Blueprint $table) { // + $table->dropColumn('surname'); }); } } From 909f7d030dc8601c59b4d61a26c88a097e48d561 Mon Sep 17 00:00:00 2001 From: Donald <154738239+DonaldFon@users.noreply.github.com> Date: Fri, 27 Dec 2024 02:32:36 +0800 Subject: [PATCH 04/12] Update 2021_11_09_080955_create_projects_table.php --- .../migrations/task3/2021_11_09_080955_create_projects_table.php | 1 + 1 file changed, 1 insertion(+) 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..3cbcc04d 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 @@ -19,6 +19,7 @@ public function up() $table->timestamps(); // TASK: Add soft deletes column here + $table->softDeletes(); }); } From 9f780843c8b7432a70121095f9e895e1fca26da8 Mon Sep 17 00:00:00 2001 From: Donald <154738239+DonaldFon@users.noreply.github.com> Date: Fri, 27 Dec 2024 02:33:36 +0800 Subject: [PATCH 05/12] Update 2021_11_09_082205_create_products_table.php --- .../task4/2021_11_09_082205_create_products_table.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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..9a22e739 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()->cascadeOnDelete(); $table->string('name'); $table->timestamps(); }); From 447de2dcb398936996e092586c0e89fdb9b6aac5 Mon Sep 17 00:00:00 2001 From: Donald <154738239+DonaldFon@users.noreply.github.com> Date: Fri, 27 Dec 2024 02:35:36 +0800 Subject: [PATCH 06/12] Update 2021_11_09_083121_update_users_table.php --- .../task5/2021_11_09_083121_update_users_table.php | 5 +++++ 1 file changed, 5 insertions(+) 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..0bec1358 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 @@ -14,6 +14,11 @@ class UpdateUsersTable extends Migration public function up() { // TASK: add an if-statement in this file to NOT add column if it already exists + + if(Schema::hasColumn('users','name')){ + return; + } + Schema::table('users', function (Blueprint $table) { $table->string('name'); }); From 5eef4d80f55d08d5f3aa51f57c8abbfb7155c544 Mon Sep 17 00:00:00 2001 From: Donald <154738239+DonaldFon@users.noreply.github.com> Date: Fri, 27 Dec 2024 02:36:04 +0800 Subject: [PATCH 07/12] Update 2021_11_09_083225_recreate_users_table.php --- .../task5/2021_11_09_083225_recreate_users_table.php | 5 +++++ 1 file changed, 5 insertions(+) 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..0f2eb743 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,6 +14,11 @@ class RecreateUsersTable extends Migration public function up() { // TASK: add an if-statement in this file to NOT create table if it already exists + + if(Schema::hasTable('users')){ + return; + } + Schema::create('users', function (Blueprint $table) { $table->id(); $table->string('name'); From 0d9e9c65d6bbbeb67ccce650783aeb8e3c35ea1e Mon Sep 17 00:00:00 2001 From: Donald <154738239+DonaldFon@users.noreply.github.com> Date: Fri, 27 Dec 2024 02:36:41 +0800 Subject: [PATCH 08/12] Update 2021_11_09_083843_create_companies_table.php --- .../task6/2021_11_09_083843_create_companies_table.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 b63e2ab591186366910f7253c01eb7e5ec033df5 Mon Sep 17 00:00:00 2001 From: Donald <154738239+DonaldFon@users.noreply.github.com> Date: Fri, 27 Dec 2024 02:37:08 +0800 Subject: [PATCH 09/12] Update 2021_11_09_084922_create_new_companies_table.php --- .../task7/2021_11_09_084922_create_new_companies_table.php | 2 +- 1 file changed, 1 insertion(+), 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..36bf0166 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(); }); } From 7001e2724afbd79b0f9e62147ef0c0a9e59cdbad Mon Sep 17 00:00:00 2001 From: Donald <154738239+DonaldFon@users.noreply.github.com> Date: Fri, 27 Dec 2024 02:38:03 +0800 Subject: [PATCH 10/12] Update 2021_11_09_085453_rename_companies_table.php --- .../task8/2021_11_09_085453_rename_companies_table.php | 2 ++ 1 file changed, 2 insertions(+) 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..1f09456b 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'); } /** @@ -24,5 +25,6 @@ public function up() public function down() { // + Schema::rename('companies','company'); } } From 24cb934241cff65d24651396cc465ebf4873bef0 Mon Sep 17 00:00:00 2001 From: Donald <154738239+DonaldFon@users.noreply.github.com> Date: Fri, 27 Dec 2024 02:39:01 +0800 Subject: [PATCH 11/12] Update 2021_11_09_090018_rename_name_in_companies_table.php --- .../task9/2021_11_09_090018_rename_name_in_companies_table.php | 2 ++ 1 file changed, 2 insertions(+) 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..f782c2d8 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,7 @@ 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'); }); } @@ -28,6 +29,7 @@ public function down() { Schema::table('companies', function (Blueprint $table) { // + $table->renameColumn('name','title'); }); } } From cfe713eedd18a97b4acf15fd5160138d0debbfa6 Mon Sep 17 00:00:00 2001 From: Donald <154738239+DonaldFon@users.noreply.github.com> Date: Fri, 27 Dec 2024 02:39:33 +0800 Subject: [PATCH 12/12] Update 2021_11_09_090858_create_visitors_table.php --- .../task10/2021_11_09_090858_create_visitors_table.php | 2 +- 1 file changed, 1 insertion(+), 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(); });