Skip to content

Commit

Permalink
10 Tasks Completed
Browse files Browse the repository at this point in the history
  • Loading branch information
azampanda committed Nov 7, 2023
1 parent bfe388a commit 8518156
Show file tree
Hide file tree
Showing 12 changed files with 25 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function up()
{
Schema::create('tasks', function (Blueprint $table) {
$table->id();
$table->bigInteger('user_id');
$table->unsignedBigInteger('user_id'); // should use unsignedBigInteger to match the parent table
$table->foreign('user_id')->references('id')->on('users');
$table->string('name');
$table->timestamps();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ public function up()
{
Schema::create('comments', function (Blueprint $table) {
$table->id();
$table->unsignedInteger('user_id');
$table->unsignedBigInteger('user_id'); // should use unsignedBigInteger to match the parent table
$table->foreign('user_id')->references('id')->on('users');
$table->unsignedInteger('comment_id');
$table->unsignedBigInteger('comment_id'); // should use unsignedBigInteger to match the parent table
$table->foreign('comment_id')->references('id')->on('comments');
$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();
});
}

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 @@ -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');
}
});
}

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
Expand Up @@ -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');
}

/**
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 8518156

Please sign in to comment.