From c0f14c11f10146704a58e770ec6e5d93d8ceaeea Mon Sep 17 00:00:00 2001 From: juliane Date: Mon, 30 Sep 2024 17:11:43 +0900 Subject: [PATCH 1/9] task 01 --- .../migrations/task1/2021_11_08_091231_create_tasks_table.php | 2 +- .../task1/2021_11_08_092943_create_comments_table.php | 4 ++-- 2 files changed, 3 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(); From 645a74e9bef71d2b9aa784488757919c211e3aa7 Mon Sep 17 00:00:00 2001 From: juliane Date: Mon, 30 Sep 2024 17:21:05 +0900 Subject: [PATCH 2/9] task 02 --- .../task2/2021_11_09_075928_add_surname_to_users_table.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) 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..fe868b01 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 @@ -15,7 +15,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'); }); } @@ -27,7 +27,8 @@ public function up() public function down() { Schema::table('users', function (Blueprint $table) { - // + //removing the field "surname" + $table->dropColumn('surname'); }); } } From 125d2f78d696949d54ac6044f0aba79be361d082 Mon Sep 17 00:00:00 2001 From: juliane Date: Thu, 3 Oct 2024 20:02:01 +0900 Subject: [PATCH 3/9] task 03 --- .../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 6e3f061de66fd89d5823350e8d0ab37838337bd2 Mon Sep 17 00:00:00 2001 From: juliane Date: Thu, 3 Oct 2024 20:07:51 +0900 Subject: [PATCH 4/9] task 04 --- .../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..2ada7fa4 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 baa19d1b6884dd633238f66abaa6ee4742472e10 Mon Sep 17 00:00:00 2001 From: juliane Date: Thu, 3 Oct 2024 20:14:37 +0900 Subject: [PATCH 5/9] task 05 --- .../task5/2021_11_09_083051_create_another_users_table.php | 2 ++ .../migrations/task5/2021_11_09_083121_update_users_table.php | 2 ++ .../migrations/task5/2021_11_09_083225_recreate_users_table.php | 2 ++ 3 files changed, 6 insertions(+) diff --git a/database/migrations/task5/2021_11_09_083051_create_another_users_table.php b/database/migrations/task5/2021_11_09_083051_create_another_users_table.php index 4705f0d5..c65c72a5 100644 --- a/database/migrations/task5/2021_11_09_083051_create_another_users_table.php +++ b/database/migrations/task5/2021_11_09_083051_create_another_users_table.php @@ -13,6 +13,7 @@ class CreateAnotherUsersTable extends Migration */ public function up() { + if (!Schema::hasTable('users')) { Schema::create('users', function (Blueprint $table) { $table->id(); $table->string('name'); @@ -23,6 +24,7 @@ public function up() $table->timestamps(); }); } + } /** * Reverse the migrations. 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..6889ad48 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) { + 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..0d2db49f 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,7 @@ 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')) { Schema::create('users', function (Blueprint $table) { $table->id(); $table->string('name'); @@ -24,6 +25,7 @@ public function up() $table->timestamps(); }); } + } /** * Reverse the migrations. From ce375f59b041994991b4b305e77649458f45854f Mon Sep 17 00:00:00 2001 From: juliane Date: Thu, 3 Oct 2024 20:24:00 +0900 Subject: [PATCH 6/9] task 06 --- .../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 4f75cdb2fc7c5f2b406fb8f5e44670df4f99615c Mon Sep 17 00:00:00 2001 From: juliane Date: Fri, 4 Oct 2024 21:48:13 +0900 Subject: [PATCH 7/9] task 07, task 08 --- .../task7/2021_11_09_084922_create_new_companies_table.php | 2 +- .../task8/2021_11_09_085453_rename_companies_table.php | 2 ++ 2 files changed, 3 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..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(); }); } 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..e91e5ca9 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 4a55f376bc25eb4adf120ac4ec2bdc80061067d0 Mon Sep 17 00:00:00 2001 From: juliane Date: Fri, 4 Oct 2024 23:34:22 +0900 Subject: [PATCH 8/9] task 09 --- .../task9/2021_11_09_090018_rename_name_in_companies_table.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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..fc1ab583 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 @@ -15,7 +15,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 +28,7 @@ public function down() { Schema::table('companies', function (Blueprint $table) { // + $table->renameColumn('name', 'title'); }); } } From 6d44aa459bef4f9f347cfa79ef8578c00cd5d4f1 Mon Sep 17 00:00:00 2001 From: juliane Date: Fri, 4 Oct 2024 23:37:11 +0900 Subject: [PATCH 9/9] task 10 --- .../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(); });