From 889a47d24fc15e44be15cf7c699f9afd971ef63f Mon Sep 17 00:00:00 2001 From: OhmygoodR <109280933+OhmygoodR@users.noreply.github.com> Date: Tue, 13 Feb 2024 21:04:29 +0800 Subject: [PATCH 01/13] 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..61a79e8e 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()->cascadeOnDelete(); $table->string('name'); $table->timestamps(); }); From 098b4aad0c1a0d71d77264f04ac922340d78ea83 Mon Sep 17 00:00:00 2001 From: OhmygoodR <109280933+OhmygoodR@users.noreply.github.com> Date: Tue, 13 Feb 2024 21:06:07 +0800 Subject: [PATCH 02/13] 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..390b1011 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()->cascadeOnDelete(); + $table->foreignId('comment_id')->constrained()->cascadeOnDelete(); $table->string('comment_text'); $table->timestamps(); }); From 5623975983ae764ebf015ca5207ec219d4c4251b Mon Sep 17 00:00:00 2001 From: OhmygoodR <109280933+OhmygoodR@users.noreply.github.com> Date: Tue, 13 Feb 2024 21:13:07 +0800 Subject: [PATCH 03/13] 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 c05fcad8f36fe991fa74b49bde710ac376d0fa02 Mon Sep 17 00:00:00 2001 From: OhmygoodR <109280933+OhmygoodR@users.noreply.github.com> Date: Tue, 13 Feb 2024 21:14:53 +0800 Subject: [PATCH 04/13] Update 2021_11_09_080955_create_projects_table.php --- .../task3/2021_11_09_080955_create_projects_table.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 }); } From 284cb2c5e51ef3e7db679e11631d60642b177d3f Mon Sep 17 00:00:00 2001 From: OhmygoodR <109280933+OhmygoodR@users.noreply.github.com> Date: Tue, 13 Feb 2024 21:18:06 +0800 Subject: [PATCH 05/13] 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 0033c2341bd79a5935395bccbcde4427ca7597ec Mon Sep 17 00:00:00 2001 From: OhmygoodR <109280933+OhmygoodR@users.noreply.github.com> Date: Tue, 13 Feb 2024 21:25:57 +0800 Subject: [PATCH 06/13] Update 2021_11_09_083121_update_users_table.php --- .../task5/2021_11_09_083121_update_users_table.php | 8 ++++++++ 1 file changed, 8 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..568520e7 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,10 @@ 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'); }); @@ -27,5 +31,9 @@ public function up() public function down() { // + Schema::table('users',function(Blueprint $table){ + $table->dropColumn('name'); + }); + } } From 551c996f166fee919f03a94b768049c758dee202 Mon Sep 17 00:00:00 2001 From: OhmygoodR <109280933+OhmygoodR@users.noreply.github.com> Date: Tue, 13 Feb 2024 21:26:36 +0800 Subject: [PATCH 07/13] Update 2021_11_09_083121_update_users_table.php --- .../task5/2021_11_09_083121_update_users_table.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 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 568520e7..f9894aad 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,12 +15,12 @@ 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; + if(Schema::hasColumn('users','name')===false){ + Schema::table('users', function (Blueprint $table) { + $table->string('name'); + }); } - Schema::table('users', function (Blueprint $table) { - $table->string('name'); - }); + } /** From 2df213d2dc85c5da6a6de18690330f571d250654 Mon Sep 17 00:00:00 2001 From: OhmygoodR <109280933+OhmygoodR@users.noreply.github.com> Date: Tue, 13 Feb 2024 21:27:49 +0800 Subject: [PATCH 08/13] Update 2021_11_09_083225_recreate_users_table.php --- .../task5/2021_11_09_083225_recreate_users_table.php | 4 ++++ 1 file changed, 4 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..4f5e4f21 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,8 @@ 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')===false){ Schema::create('users', function (Blueprint $table) { $table->id(); $table->string('name'); @@ -23,6 +25,7 @@ public function up() $table->rememberToken(); $table->timestamps(); }); + } } /** @@ -33,5 +36,6 @@ public function up() public function down() { // + Schema::dropIfExists('users'); } } From 3fe7edd6b8c03ce2997ac37d892f2307cc2e83bd Mon Sep 17 00:00:00 2001 From: OhmygoodR <109280933+OhmygoodR@users.noreply.github.com> Date: Tue, 13 Feb 2024 21:28:47 +0800 Subject: [PATCH 09/13] 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 a9789513c21d12c35a48076d4abe02bd56673e82 Mon Sep 17 00:00:00 2001 From: OhmygoodR <109280933+OhmygoodR@users.noreply.github.com> Date: Tue, 13 Feb 2024 21:29:59 +0800 Subject: [PATCH 10/13] 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 c26f0991e863fbc2fab28311b0bbab85393cf6af Mon Sep 17 00:00:00 2001 From: OhmygoodR <109280933+OhmygoodR@users.noreply.github.com> Date: Tue, 13 Feb 2024 21:31:39 +0800 Subject: [PATCH 11/13] 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 ab93e04f99222a38bb4889727acd4e713174e60e Mon Sep 17 00:00:00 2001 From: OhmygoodR <109280933+OhmygoodR@users.noreply.github.com> Date: Tue, 13 Feb 2024 21:33:30 +0800 Subject: [PATCH 12/13] 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 947473692e57bb432879ebbbedc491aaeda5ac78 Mon Sep 17 00:00:00 2001 From: OhmygoodR <109280933+OhmygoodR@users.noreply.github.com> Date: Tue, 13 Feb 2024 21:34:13 +0800 Subject: [PATCH 13/13] 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(); });