Skip to content

Commit

Permalink
Complete tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
juancorax committed Nov 20, 2024
1 parent bfe388a commit 43bed0f
Show file tree
Hide file tree
Showing 12 changed files with 26 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@ 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->string('comment_text');
$table->timestamps();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public function up()
$table->timestamps();

// TASK: Add soft deletes column here
$table->softDeletes('deleted_at', precision: 0);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +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
Schema::table('users', function (Blueprint $table) {
$table->string('name');
});
if (! Schema::hasColumn('users', 'name')) {
Schema::table('users', function (Blueprint $table) {
$table->string('name');
});
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,17 @@ 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();
});
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class RenameCompaniesTable extends Migration
Expand All @@ -14,6 +13,7 @@ class RenameCompaniesTable extends Migration
public function up()
{
// TASK: add a migration to rename table "company" into "companies"
Schema::rename('company', 'companies');
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
}

Expand Down

0 comments on commit 43bed0f

Please sign in to comment.