Rename column

This commit is contained in:
PovilasKorop
2021-11-09 11:05:49 +02:00
parent 57f6333ea3
commit 0140f00c32
4 changed files with 81 additions and 0 deletions
+8
View File
@@ -103,3 +103,11 @@ Test method `test_renamed_table()`.
---
## Task 9. Rename column
Folder `database/migrations/task9` contains a migration for companies table. Later it was decided to rename the column from "companies.title" to "companies.name". Write the code for that, in the second migration file.
Test method `test_renamed_column()`.
---
@@ -0,0 +1,32 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateCompaniesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('companies', function (Blueprint $table) {
$table->id();
$table->string('title');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('companies');
}
}
@@ -0,0 +1,33 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class RenameNameInCompaniesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
// TASK: write the migration to rename the column "title" into "name"
Schema::table('companies', function (Blueprint $table) {
// Write code here
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('companies', function (Blueprint $table) {
//
});
}
}
+8
View File
@@ -104,4 +104,12 @@ class MigrationsTest extends TestCase
DB::table('companies')->insert(['name' => 'First']);
$this->assertDatabaseHas(Company::class, ['name' => 'First']);
}
public function test_renamed_column()
{
Artisan::call('migrate:fresh', ['--path' => '/database/migrations/task9']);
Company::create(['name' => 'First']);
$this->assertDatabaseHas(Company::class, ['name' => 'First']);
}
}