diff --git a/README.md b/README.md index e0758ae..72a597f 100644 --- a/README.md +++ b/README.md @@ -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()`. + +--- + diff --git a/database/migrations/task9/2021_11_09_090003_create_companies_table.php b/database/migrations/task9/2021_11_09_090003_create_companies_table.php new file mode 100644 index 0000000..38f1330 --- /dev/null +++ b/database/migrations/task9/2021_11_09_090003_create_companies_table.php @@ -0,0 +1,32 @@ +id(); + $table->string('title'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('companies'); + } +} diff --git a/database/migrations/task9/2021_11_09_090018_rename_name_in_companies_table.php b/database/migrations/task9/2021_11_09_090018_rename_name_in_companies_table.php new file mode 100644 index 0000000..f270c9e --- /dev/null +++ b/database/migrations/task9/2021_11_09_090018_rename_name_in_companies_table.php @@ -0,0 +1,33 @@ +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']); + } }