Task 8 - rename table

This commit is contained in:
PovilasKorop
2021-11-09 10:58:48 +02:00
parent 76504ffe87
commit 57f6333ea3
4 changed files with 77 additions and 0 deletions
+8
View File
@@ -95,3 +95,11 @@ Test method `test_automatic_value()`.
---
## Task 8. Rename table
Folder `database/migrations/task8` contains a migration for company table. Later it was decided to rename the table from "company" to "companies". Write the code for that, in the second migration file.
Test method `test_renamed_table()`.
---
@@ -0,0 +1,32 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateCompanyTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('company', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('companies');
}
}
@@ -0,0 +1,28 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class RenameCompaniesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
// TASK: add a migration to rename table "company" into "companies"
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
//
}
}
+9
View File
@@ -9,6 +9,7 @@ use App\Models\Project;
use App\Models\User;
use Illuminate\Database\QueryException;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\DB;
use Tests\TestCase;
class MigrationsTest extends TestCase
@@ -95,4 +96,12 @@ class MigrationsTest extends TestCase
$company = Company::first();
$this->assertEquals('My company', $company->name);
}
public function test_renamed_table()
{
Artisan::call('migrate:fresh', ['--path' => '/database/migrations/task8']);
DB::table('companies')->insert(['name' => 'First']);
$this->assertDatabaseHas(Company::class, ['name' => 'First']);
}
}