Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

t4 #496

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open

t4 #496

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,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();
});
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 All @@ -28,6 +29,7 @@ public function down()
{
Schema::table('users', function (Blueprint $table) {
//
$table->dropColumn('surname');
});
}
}
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()->cascadeOnDelete();
$table->string('name');
$table->timestamps();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');
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 All @@ -24,5 +25,6 @@ public function up()
public function down()
{
//
Schema::rename('companies','company');
}
}
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 All @@ -28,6 +29,7 @@ public function down()
{
Schema::table('companies', function (Blueprint $table) {
//
$table->renameColumn('name','title');
});
}
}
Loading